Skip to content

Commit a83aaab

Browse files
authored
Merge pull request #1 from nsingla/gitaction
Adding github action and support for htmlunit driver
2 parents ba47e4d + a39ec3a commit a83aaab

3 files changed

Lines changed: 134 additions & 30 deletions

File tree

.github/workflows/main.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
3+
name: Maven Build & Deploy
4+
5+
on:
6+
push:
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up JDK 11
19+
uses: actions/setup-java@v3
20+
with:
21+
java-version: '11'
22+
distribution: 'temurin'
23+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
24+
settings-path: ${{ github.workspace }} # location for the settings.xml file
25+
26+
- name: SetUp Chrome Browser
27+
uses: browser-actions/setup-chrome@latest
28+
29+
- name: Build with Maven
30+
if: ${{ github.ref != 'refs/heads/master' }}
31+
run: mvn clean package --file pom.xml -Dheadless=true
32+
33+
- name: Set up Maven Central Repository
34+
uses: actions/setup-java@v3
35+
with:
36+
java-version: '11'
37+
distribution: 'adopt'
38+
server-id: ossrh
39+
server-username: MAVEN_USERNAME
40+
server-password: MAVEN_PASSWORD
41+
42+
- name: Import GPG key
43+
id: import_gpg
44+
uses: crazy-max/ghaction-import-gpg@v5
45+
with:
46+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
47+
passphrase: ${{ secrets.GPG_PASSPHRASE }}
48+
49+
- name: Publish package
50+
if: contains(github.ref, 'release')
51+
run: mvn clean -Dgpg.passphrase=${{ secrets.GPG_PASSPHRASE }} --batch-mode deploy -DskipTests=true -P release
52+
env:
53+
MAVEN_USERNAME: ${{ secrets.MVN_USERNAME }}
54+
MAVEN_PASSWORD: ${{ secrets.MVN_PASSWORD }}

pom.xml

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@
5252
<properties>
5353
<java.version>11</java.version>
5454
<junit5.framework.version>2.1.1</junit5.framework.version>
55-
<plugin.selenium.version>4.6.0</plugin.selenium.version>
55+
<selenium.version>4.6.0</selenium.version>
5656
<webdrivermanager.version>4.2.2</webdrivermanager.version>
5757
<allure.version>2.20.1</allure.version>
5858

5959
<!-- Plugin Versions -->
6060
<maven.compiler.plugin.version>3.10.1</maven.compiler.plugin.version>
6161
<maven.surefire.plugin.version>3.0.0-M7</maven.surefire.plugin.version>
62+
<maven.source.plugin.version>3.2.1</maven.source.plugin.version>
63+
<maven.javadoc.plugin.version>3.4.1</maven.javadoc.plugin.version>
64+
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>
65+
6266

6367
</properties>
6468

@@ -86,7 +90,7 @@
8690
<dependency>
8791
<groupId>org.seleniumhq.selenium</groupId>
8892
<artifactId>selenium-java</artifactId>
89-
<version>${plugin.selenium.version}</version>
93+
<version>${selenium.version}</version>
9094
<exclusions>
9195
<exclusion>
9296
<groupId>com.google.*</groupId>
@@ -111,27 +115,9 @@
111115
</exclusions>
112116
</dependency>
113117
<dependency>
114-
<groupId>io.github.bonigarcia</groupId>
115-
<artifactId>webdrivermanager</artifactId>
116-
<version>${webdrivermanager.version}</version>
117-
<exclusions>
118-
<exclusion>
119-
<groupId>com.google.*</groupId>
120-
<artifactId>*</artifactId>
121-
</exclusion>
122-
<exclusion>
123-
<groupId>*commons*</groupId>
124-
<artifactId>*</artifactId>
125-
</exclusion>
126-
<exclusion>
127-
<groupId>org.jsoup</groupId>
128-
<artifactId>*</artifactId>
129-
</exclusion>
130-
<exclusion>
131-
<groupId>org.slf4j</groupId>
132-
<artifactId>*</artifactId>
133-
</exclusion>
134-
</exclusions>
118+
<groupId>org.seleniumhq.selenium</groupId>
119+
<artifactId>htmlunit-driver</artifactId>
120+
<version>${selenium.version}</version>
135121
</dependency>
136122
</dependencies>
137123

@@ -183,5 +169,56 @@
183169
</plugin>
184170
</plugins>
185171
</build>
186-
172+
<profiles>
173+
<profile>
174+
<id>release</id>
175+
<build>
176+
<plugins>
177+
<plugin>
178+
<groupId>org.apache.maven.plugins</groupId>
179+
<artifactId>maven-gpg-plugin</artifactId>
180+
<version>${maven.gpg.plugin.version}</version>
181+
<executions>
182+
<execution>
183+
<id>sign-artifacts</id>
184+
<phase>verify</phase>
185+
<goals>
186+
<goal>sign</goal>
187+
</goals>
188+
</execution>
189+
</executions>
190+
</plugin>
191+
<plugin>
192+
<groupId>org.apache.maven.plugins</groupId>
193+
<artifactId>maven-source-plugin</artifactId>
194+
<version>${maven.source.plugin.version}</version>
195+
<executions>
196+
<execution>
197+
<id>attach-sources</id>
198+
<goals>
199+
<goal>jar-no-fork</goal>
200+
</goals>
201+
</execution>
202+
</executions>
203+
</plugin>
204+
<plugin>
205+
<groupId>org.apache.maven.plugins</groupId>
206+
<artifactId>maven-javadoc-plugin</artifactId>
207+
<version>${maven.javadoc.plugin.version}</version>
208+
<configuration>
209+
<source>${java.version}</source>
210+
</configuration>
211+
<executions>
212+
<execution>
213+
<id>attach-javadocs</id>
214+
<goals>
215+
<goal>jar</goal>
216+
</goals>
217+
</execution>
218+
</executions>
219+
</plugin>
220+
</plugins>
221+
</build>
222+
</profile>
223+
</profiles>
187224
</project>

src/main/java/io/nsingla/selenium/DriverFactory.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33
import io.nsingla.constants.SeleniumConstants;
44
import io.nsingla.selenium.enums.TestMode;
55

6-
import io.github.bonigarcia.wdm.WebDriverManager;
76
import org.apache.commons.lang3.StringUtils;
87
import org.openqa.selenium.MutableCapabilities;
98
import org.openqa.selenium.PageLoadStrategy;
10-
import org.openqa.selenium.Proxy;
119
import org.openqa.selenium.UnexpectedAlertBehaviour;
1210
import org.openqa.selenium.WebDriver;
1311
import org.openqa.selenium.chrome.ChromeDriver;
1412
import org.openqa.selenium.chrome.ChromeOptions;
13+
import org.openqa.selenium.edge.EdgeDriver;
1514
import org.openqa.selenium.edge.EdgeOptions;
15+
import org.openqa.selenium.firefox.FirefoxDriver;
1616
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
1717
import org.openqa.selenium.firefox.FirefoxOptions;
1818
import org.openqa.selenium.firefox.FirefoxProfile;
19+
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
1920
import org.openqa.selenium.logging.LogType;
2021
import org.openqa.selenium.logging.LoggingPreferences;
2122
import org.openqa.selenium.remote.AbstractDriverOptions;
2223
import org.openqa.selenium.remote.Browser;
2324
import org.openqa.selenium.remote.CapabilityType;
2425
import org.openqa.selenium.remote.LocalFileDetector;
2526
import org.openqa.selenium.remote.RemoteWebDriver;
27+
import org.openqa.selenium.safari.SafariDriver;
2628
import org.openqa.selenium.safari.SafariOptions;
2729
import org.slf4j.Logger;
2830
import org.slf4j.LoggerFactory;
@@ -140,9 +142,20 @@ private WebDriver getLocalDriver() {
140142
if (!downloaDir.exists()) {
141143
downloaDir.mkdir();
142144
}
143-
ChromeOptions options = createDefaultDriverOptions(ChromeOptions.class);
144-
setDefaultChromeOptions(options);
145-
return new ChromeDriver(options);
145+
AbstractDriverOptions options = getDriverOptions();
146+
if (Browser.FIREFOX.equals(browser)) {
147+
return new FirefoxDriver((FirefoxOptions) options);
148+
} else if (Browser.CHROME.equals(browser)) {
149+
return new ChromeDriver((ChromeOptions) options);
150+
} else if (Browser.SAFARI.equals(browser)) {
151+
return new SafariDriver((SafariOptions) options);
152+
} else if (Browser.EDGE.equals(browser)) {
153+
return new EdgeDriver((EdgeOptions) options);
154+
} else if (Browser.HTMLUNIT.equals(browser)) {
155+
return new HtmlUnitDriver();
156+
} else {
157+
throw new RuntimeException("Cannot start a webdriver session for browser: " + browser);
158+
}
146159
}
147160

148161
private RemoteWebDriver getRemoteDriver(String server) throws MalformedURLException {
@@ -244,4 +257,4 @@ private void setDefaultFirefoxOptions(FirefoxOptions options) {
244257
public WebDriver getDriver() {
245258
return driver;
246259
}
247-
}
260+
}

0 commit comments

Comments
 (0)