├── .gitignore
├── .travis.yml
├── README.md
├── google-style.xml
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── github
│ └── ansonliao
│ └── selenium
│ ├── annotations
│ ├── Author.java
│ ├── Description.java
│ ├── Headless.java
│ ├── Incognito.java
│ ├── PageName.java
│ ├── Retry.java
│ ├── URL.java
│ └── browser
│ │ ├── Chrome.java
│ │ ├── Edge.java
│ │ ├── Firefox.java
│ │ ├── IgnoreChrome.java
│ │ ├── IgnoreEdge.java
│ │ ├── IgnoreFirefox.java
│ │ ├── IgnoreInternetExplorer.java
│ │ ├── IgnoreOpera.java
│ │ ├── IgnorePhantomJs.java
│ │ ├── InternetExplorer.java
│ │ ├── Opera.java
│ │ └── PhantomJs.java
│ ├── factory
│ ├── ChromeFactory.java
│ ├── DriverManager.java
│ ├── DriverManagerFactory.java
│ ├── EdgeFactory.java
│ ├── FirefoxFactory.java
│ ├── InternetExplorerFactory.java
│ ├── OperaFactory.java
│ ├── PhantomJsFactory.java
│ └── WDManager.java
│ ├── internal
│ ├── OptionalConsumer.java
│ ├── OptionalEx.java
│ └── ScreenshotManager.java
│ ├── json
│ ├── JsonLoader.java
│ └── JsonParser.java
│ ├── parallel
│ ├── ClassFinder.java
│ ├── MethodFinder.java
│ ├── SeleniumParallel.java
│ └── SeleniumParallelTestListener.java
│ ├── report
│ └── factory
│ │ ├── ExtentManager.java
│ │ └── ExtentTestManager.java
│ ├── testng
│ ├── RetryListener.java
│ ├── TestNGFilter.java
│ ├── TestNGRetry.java
│ ├── TestNGRunner.java
│ ├── TestResultListener.java
│ ├── XmlClassBuilder.java
│ ├── XmlSuiteBuilder.java
│ └── XmlTestBuilder.java
│ └── utils
│ ├── AnnotationUtils.java
│ ├── AuthorUtils.java
│ ├── BrowserUtils.java
│ ├── CapsUtils.java
│ ├── MyFileUtils.java
│ ├── PlatformUtils.java
│ ├── SEConfig.java
│ ├── StringUtils.java
│ ├── TestGroupUtils.java
│ ├── WDMHelper.java
│ └── config
│ └── SEConfigs.java
└── test
└── java
└── testcases
└── Test_Demo.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.o
7 | *.so
8 |
9 | # Logs and databases #
10 | ######################
11 | *.log
12 | *.sqlite
13 | *.out
14 |
15 | # OS generated files #
16 | ######################
17 | .DS_Store
18 | .DS_Store?
19 | *.DS_Store
20 | ._*
21 | .Spotlight-V100
22 | .Trashes
23 | Icon?
24 | ehthumbs.db
25 | Thumbs.db
26 | *~
27 |
28 | # Maven #
29 | #########
30 | .classpath
31 | .project
32 | .settings/
33 | target/
34 | test-output/
35 |
36 | # NetBeans #
37 | ############
38 | nbproject/private/
39 | /nb-configuration.xml
40 |
41 | # IDEA
42 | ############
43 | .idea
44 | *.iml
45 |
46 | # Web Driver
47 | drivers/
48 |
49 | # Debug Files
50 | *.txt
51 | *.html
52 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | script: mvn clean site install -Dmaven.test.skip=true
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Selenium-Extensions
2 | [](https://github.com/saikrishna321/AppiumTestDistribution)
3 | [](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
4 | [](https://travis-ci.org/ansonliao/Selenium-Extensions/builds/)
5 |
6 | This is a extension for Selenium in Java to extend Selenium for make Selenium test case can be run in parallel, and make it easy to support multiple browsers.
7 | Integrated beautiful and powerful HTML test report: [ExtentReports](http://extentreports.com/).
8 |
9 | ## Maven Dependency
10 | Add the below dependencies in your `pom.xml` (Master)
11 |
12 | ```xml
13 |
14 |
15 | jitpack.io
16 | https://jitpack.io
17 |
18 |
19 | ```
20 |
21 | ```xml
22 |
23 | com.github.ansonliao
24 | Selenium-Extensions
25 | 2.3.7-SNAPSHOT
26 |
27 | ```
28 |
29 | ## Parallel
30 | Introduce [TestNG](http://testng.org/doc/index.html) framework to support Selenium test case parallel run.
31 | Parallel mode is by Test, the tag `` of TestNG test suite xml.
32 |
33 | ## Visual TestNG test suite XML generation
34 | No need to provide TestNG test suite XMl file to start the test, TestNG test suite XML file will be generated programmatically.
35 |
36 | ## Report
37 | ### Testing Report
38 |
39 | After test completed, Extents test report can be found `target/ExtentReports.html`.
40 |
41 | ### Screenshot for test fail
42 | Screenshot can be found at `target/screenshots` for the test failed.
43 |
44 | ## Download WebDriver binary automatically
45 | `Selenium-Extensions` will download `WebDriver` binaries for Test automatically,
46 | no need download the binary manually before the test start.
47 |
48 | ### WebDriverManager
49 |
50 | For download the webdriver binary, introduced the dependency `webdrivermanager` of `io.github.bonigarcia`, for more detail the setting for the `Web Driver Manager`, please refer to the official document: [Read Me](https://github.com/bonigarcia/webdrivermanager/), and the configuration file: [Configuration](https://github.com/bonigarcia/webdrivermanager#configuration) .
51 |
52 | ## Multiple browsers support
53 | Browser support:
54 |
55 | - **Chrome**: Mac, Linux, Windows
56 | - **FireFox**: Mac, Linux, Windows
57 | - **PhantomJs**: Mac, Linux, Windows
58 | - **Opera**: Mac, Linux, Windows
59 | - **Edge**: Windows
60 | - **InternetExplorer**: Windows
61 | - **Safari**: DEPRECATED
62 |
63 | ## Multiple browsers in Runtime
64 | ```java
65 | public class TestBrowser {
66 | @Test
67 | @Chrome
68 | public void f1() {
69 | // your testing code here
70 | }
71 |
72 | @Test
73 | @Firefox
74 | public void f2() {
75 | // your testing code here
76 | }
77 | }
78 | ```
79 |
80 | Even, you can annotated your test class:
81 | ```java
82 | @Chrome
83 | public class TestBrowser {
84 | @Test
85 | @Edge
86 | public void f1() {
87 | // your testing code here
88 | }
89 |
90 | @Test
91 | @Firefox
92 | public void f2() {
93 | // your testing code here
94 | }
95 | }
96 | ```
97 |
98 | From the above code, test class `BrowserTest` was annotated by `@Chrome`, so all test method of TestNG of test class `BrowserTest` will be run at browser `Chrome`.
99 | So finally, test method:
100 | * `f1()`: will be run at browsers `Edge` and `Chrome` (if Windows OS platform);
101 | * `f2()`: will be run at browsers `Firefox` and `Chrome`.
102 |
103 | ## Dynamic URL support for test method
104 | ```java
105 | public class TestBrowser {
106 |
107 | @Test
108 | @Chrome
109 | @URL("https://www.google.com/")
110 | public void f1() {
111 | // your testing code here
112 | }
113 |
114 | @Test
115 | @Firefox
116 | @URL("https://www.wordpress.com")
117 | public void f2() {
118 | // your testing code here
119 | }
120 | }
121 | ```
122 |
123 | When the test start (test cases `f1`, `f2`), the URL will be open automatically, URL `https://www.google.com/` will be
124 | launched for test case `f1`, URL `https://www.wordpress.com` will be launched for test case `f2`.
125 |
126 | also, you can annotate test class by `@URL`, such as:
127 | ```java
128 | @URL("http://www.google.com")
129 | public class TestBrowser {
130 | @Test
131 | @Chrome
132 | public void f1() {
133 | // your testing code here
134 | }
135 |
136 | @Test
137 | @Firefox
138 | public void f2() {
139 | // your testing code here
140 | }
141 | }
142 | ```
143 |
144 | Above two test cases `f1`, `f2` will be lauch URL `http://www.google.com` automatically.
145 |
146 | ## Run test case
147 |
148 | You need to create the `runner` to trigger the testing run.
149 |
150 | Below is a sample, it is the simplest sample run all test cases, only run method `TestNGRunner.Run()`.
151 |
152 | ```java
153 | public class MyTestRunner {
154 | @Test
155 | public void run() {
156 | TestNGRunner.Run();
157 | }
158 | }
159 | ```
160 |
161 | When test runner created, we can trigger the test by `Maven` command, as below.
162 |
163 | ```bash
164 | mvn clean test -Dtest=MyTestRunner
165 | ```
166 |
167 | ## Filter
168 | `Selenium-Extentsions` support run the test case by filters.
169 | The filter includes:
170 |
171 | - *All*: run test cases in test project
172 | - *Package*: run test cases by specify packages
173 | - *Test Group*: run test cases by specify test groups which in TestNG test annotation `@Test`
174 | - *Test class*: run test cases by specify test classes which are TestNG test class
175 | - *Browser*: run test cases by specify browser, such as `CHROME`, `FIREFOX`
176 |
177 | ### Full configuration list
178 | You can create your owned configuration and named to `seleniumextentsions.properties` or `se.properties`.
179 | Please note that make sure put your owned configuration file to the resources directory of under `src` that the main Java code (`src/main/resources`) or test Java code (`src/test/resources`).
180 |
181 | | **Key** | **Description** | **Value** | **Default Value**|
182 | | --- | --- | ---| --- |
183 | | add.browser.group.to.report | Whether add testing browser to ExtentReports as a group of ExtentReport | Boolean: `true` / `false` | `false` (Java keyword in boolean, case sensitive) |
184 | | run.by.browsers | Run all TestNG test by the specified browser(s). This setting will ignore the existing browser annotation of TestNG test class, and will resign all valid TestNG test class to this setting browser | `CHROME`, `FIREFOX`, `IE`, `OPERA`, `PHAMTOMJS`, `EDGE`, `INTEREXPLORER`| null |
185 | | default.browser | Setting the default browser for the valid TestNG test case which without any valid browser annotation| `CHROME`, `FIREFOX`, `IE`, `OPERA`, `PHAMTOMJS`, `EDGE`, `INTEREXPLORER` | `CHROME` (no case sensitive) |
186 | | browser.annotation.package | The package that places all browser annotations and all ignore browser annotations. | string | `com.github.ansonliao.selenium.annotations.browser` |
187 | | test.tag.class.size.of.testngxml | The setting for how many TestNG test class will be held for each `Test` tag of TestNG XML | positive integer | 10 |
188 | | testing.package.names | Specified what test script under the package(s) will be run | string or string of list | nulll |
189 | | testing.browser.names | Run the test cases which specified annotated by browser annotation match to this setting | string or string of list | null |
190 | | testing.test.groups | Run the test cases which are assigned to the testing group of TestNG of this setting | string or string of list | null |
191 | | testing.testng.classes | Specified what valid TestNG testing class will be executed | string or string of list | null |
192 | | testng.listeners | Provided your owned TestNG listener(s) | string or string of list | `com.github.ansonliao.selenium.testng.TestResultListener`, `com.github.ansonliao.selenium.parallel.SeleniumParallelTestListener` |
193 | | testng.class.prefix | Specified the specificed TestNG testing class that the leading, the TestNG testing class scanned will only filter the testing class which the class name starts with the setting | string | `test` (no case sensitive) |
194 |
195 | > Please note that, for the setting can be string of list, please use comma (`,`) as the separator
196 |
197 | ### Sample configuration: `src/test/resources/seleniumextensions.properties`
198 |
199 | ```
200 | add.browser.group.to.report=true
201 | run.by.browsers=CHROME, FIREFOX
202 | default.browser=CHROME // can be removed
203 | browser.annotation.package=com.github.ansonliao.selenium.annotations.browser // can be removed
204 | testing.package.names=example.phase1, example.phase2
205 | test.tag.class.size.of.testngxml=20
206 | testing.test.groups=REGRESSION, SMOKE
207 | testng.listeners=example.listeners.mylistener1, example.listeners.mylistener2
208 |
209 | ```
210 |
211 | ### Provide filters as Maven command line argument
212 |
213 | also you can provide the configuration by Maven's command line argument:
214 |
215 | Execute `Smoke` test case (TestNG test group includes `SMOKE`) only
216 |
217 | ```bash
218 | mvn clean test -Dtest=your_test_runner -Dtesting.test.groups=SMOKE
219 | ```
220 |
221 | Or have a package that place all `Smoke` test case together and the package name is `example.smoke`:
222 |
223 | ```bash
224 | mvn clean test -Dtest=your_test_runner -Dtesting.package.names=example.smoke
225 | ```
226 |
227 | ### Provide filters programmatically
228 |
229 | In your Test Runner, before calling `TestNGRunner.Run(...)`, you can set the configuration via set the values of `System.Properties` or `System.envs` of Java:
230 |
231 | ```java
232 | public class RegressionRunner {
233 | @Test
234 | public void runner() {
235 | System.setProperty("testing.test.groups", "REGRESSION");
236 | TestNGRunner.run();
237 | }
238 | }
239 |
240 | public class SmokeRunner {
241 | @Test
242 | public void runner() {
243 | System.setProperty("testing.test.groups", "SMOKE");
244 | }
245 | }
246 |
247 | public class ChromeTestRunner {
248 | @Test
249 | public void runner() {
250 | System.setProperty("testing.browser.names", "CHROME");
251 | TestNGRunner.run();
252 | }
253 | }
254 |
255 | ```
256 |
257 |
258 |
259 | #### Difference between `default.browser` and `testing.browser.names`
260 |
261 | - `testing.browser.names`: The program will look for the valid TestNG testing class and testing method's browser annotations and check the browser annotation of test case whether contained in the setting of `testing.browser.names`, and then execute the test case which annotated by the browser annotation contains in the setting.
262 | - `run.by.browsers`: The programm will look for the valid TestNG test case and then ignore the browser annotation(s), and then add browser(s) of `run.by.browsers` as the new browser annotation(s) for the valid TestNG test case.
263 |
264 | **Sample:**
265 |
266 | Let's say we have two test methods below:
267 |
268 | ```java
269 | public class TestCaseSample {
270 |
271 | @Test(groups={"Regresion", "SMOKE"})
272 | @Chrome
273 | public void regression1() {
274 | // testing code here
275 | }
276 |
277 | @Test(groups={"Regression", "BVT"})
278 | @Firefox
279 | public void regression2() {
280 | // testing code here
281 | }
282 | }
283 | ```
284 |
285 | 1. Setting `run.by.browsers=EDGE, PHANTOMJS` applied, those two test cases will be executed against to browser `Edge`, `PhantomJS`
286 | 2. Setting `testing.browser.names=FIREFOX` applied, only `regression2()` of those two test cases will be executed, because only test case `regression2()` have browser `Firefox` annotation
287 | 3. Setting `testing.browser.names=PHANTOMJS` applied, no test case will be executed, because no test case annotated to browser `PHANTOMJS`
288 |
289 | ## License
290 | 
291 |
292 | Selenium-Extensions is released under [Apache License version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
293 |
--------------------------------------------------------------------------------
/google-style.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
76 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
100 |
101 |
102 |
104 |
106 |
107 |
108 |
109 |
111 |
112 |
113 |
114 |
116 |
117 |
118 |
119 |
121 |
122 |
123 |
124 |
126 |
127 |
128 |
130 |
132 |
134 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
155 |
156 |
157 |
158 |
159 |
160 |
162 |
163 |
164 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
174 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.ansonliao
6 | Selenium-Extensions
7 | 2.3.7
8 | jar
9 |
10 | Selenium-Extensions
11 | A tool for run Web UI test in parallel across browsers
12 | https://github.com/ansonliao/Selenium-Extensions
13 |
14 |
15 |
16 | GNU Public License version 3.0
17 | http://www.gnu.org/licenses/gpl-3.0.txt
18 |
19 |
20 |
21 |
22 |
23 | Anson Liao
24 | ansonliao.xiao@gmail.com
25 |
26 | owner
27 |
28 |
29 |
30 |
31 |
32 | UTF-8
33 | 6.10
34 | 1.7.24
35 | 1.8
36 | 1.8
37 | 1.7.24
38 | 3.141.59
39 | 0.0.8
40 | 1.3.2
41 | 2.3
42 | 2.2.5
43 | 2.0-M7
44 | 8.18
45 | 3.6.0
46 | 2.19.1
47 | 2.7.5
48 | 2.17
49 | 3.1.3
50 | 1.0.10
51 | 2.8.5
52 | 2.4.0
53 | 1.5.2
54 | false
55 |
56 |
57 |
58 |
59 | org.seleniumhq.selenium
60 | selenium-java
61 | ${selenium.java.version}
62 |
63 |
64 | gson
65 | com.google.code.gson
66 |
67 |
68 | httpmime
69 | org.apache.httpcomponents
70 |
71 |
72 |
73 |
74 | org.testng
75 | testng
76 | ${testng.version}
77 |
78 |
79 | com.aventstack
80 | extentreports
81 | ${aventstack.extentreports.version}
82 |
83 |
84 | gson
85 | com.google.code.gson
86 |
87 |
88 | httpmime
89 | org.apache.httpcomponents
90 |
91 |
92 |
93 |
94 | ru.yandex.qatools.ashot
95 | ashot
96 | ${ashot.version}
97 |
98 |
99 | org.seleniumhq.selenium
100 | selenium-java
101 |
102 |
103 | org.hamcrest
104 | hamcrest-all
105 |
106 |
107 |
108 |
109 | org.slf4j
110 | slf4j-api
111 | ${slf4j.api.version}
112 |
113 |
114 | org.slf4j
115 | slf4j-simple
116 | ${slf4j.simple.version}
117 |
118 |
119 | io.github.bonigarcia
120 | webdrivermanager
121 | ${webdrivermanager.version}
122 |
123 |
124 | gson
125 | com.google.code.gson
126 |
127 |
128 | slf4j-api
129 | org.slf4j
130 |
131 |
132 |
133 |
134 | io.github.lukehutch
135 | fast-classpath-scanner
136 | ${fast.classpath.scanner.version}
137 |
138 |
139 | com.thoughtworks.qdox
140 | qdox
141 | ${thoughtworks.qdox.version}
142 | compile
143 |
144 |
145 | com.github.lalyos
146 | jfiglet
147 | ${lalyos.jfiglet.version}
148 |
149 |
150 | com.typesafe
151 | config
152 | ${typesafe.config.version}
153 |
154 |
155 | org.aeonbits.owner
156 | owner-java8
157 | ${aeonbits.owner.version}
158 |
159 |
160 | com.google.code.gson
161 | gson
162 | ${gson.version}
163 |
164 |
165 | com.jayway.jsonpath
166 | json-path
167 | ${jsonpath.version}
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 | org.apache.maven.plugins
176 | maven-compiler-plugin
177 | ${maven.compiler.plugin.version}
178 |
179 | ${maven.compiler.target}
180 | ${maven.compiler.source}
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 | release
189 |
190 |
191 |
192 | org.apache.maven.plugins
193 | maven-surefire-plugin
194 | ${maven.surefire.plugin.version}
195 |
196 |
197 | org.apache.maven.plugins
198 | maven-checkstyle-plugin
199 | ${maven.checkstyle.plugin.version}
200 |
201 |
202 | com.puppycrawl.tools
203 | checkstyle
204 | [${puppycrawl.checkstyle.version},)
205 |
206 |
207 |
208 | ${basedir}/google-style.xml
209 | ${project.build.sourceEncoding}
210 | true
211 | true
212 | true
213 | true
214 |
215 |
216 |
217 | validate
218 | validate
219 |
220 | check
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 | org.apache.maven.plugins
234 | maven-checkstyle-plugin
235 | ${maven.checkstyle.plugin.version}
236 |
237 | ${basedir}/google-style.xml
238 | ${project.build.sourceEncoding}
239 | false
240 | true
241 | true
242 | true
243 |
244 |
245 |
246 |
247 | checkstyle
248 |
249 |
250 |
251 |
252 |
253 | org.apache.maven.plugins
254 | maven-jxr-plugin
255 | ${maven.jxr.plugin.version}
256 |
257 | true
258 |
259 |
260 |
261 | org.apache.maven.plugins
262 | maven-project-info-reports-plugin
263 | 2.9
264 |
265 |
266 |
267 |
268 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/Author.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Author {
11 | String[] value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/Description.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Description {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/Headless.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Headless {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/Incognito.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Incognito {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/PageName.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.TYPE)
10 | public @interface PageName {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/Retry.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Retry {
11 | int maxRetry() default 0;
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/URL.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD})
10 | public @interface URL {
11 | String value() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/Chrome.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Chrome {
11 | String value() default "Chrome";
12 |
13 | String type() default "BROWSER";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/Edge.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Edge {
11 | String value() default "Edge";
12 |
13 | String type() default "BROWSER";
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/Firefox.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Firefox {
11 | String value() default "Firefox";
12 |
13 | String type() default "BROWSER";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnoreChrome.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface IgnoreChrome {
11 | String value() default "";
12 |
13 | String type() default "BROWSER_IGNORE";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnoreEdge.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface IgnoreEdge {
11 | String value() default "";
12 |
13 | String type() default "BROWSER_IGNORE";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnoreFirefox.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface IgnoreFirefox {
11 | String value() default "";
12 |
13 | String type() default "BROWSER_IGNORE";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnoreInternetExplorer.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface IgnoreInternetExplorer {
11 | String value() default "";
12 |
13 | String type() default "BROWSER_IGNORE";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnoreOpera.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface IgnoreOpera {
11 | String value() default "";
12 |
13 | String type() default "BROWSER_IGNORE";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/IgnorePhantomJs.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Deprecated
9 | @Retention(RetentionPolicy.RUNTIME)
10 | @Target({ElementType.TYPE, ElementType.METHOD})
11 | public @interface IgnorePhantomJs {
12 | String value() default "";
13 |
14 | String type() default "BROWSER_IGNORE";
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/InternetExplorer.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface InternetExplorer {
11 | String value() default "InternetExplorer";
12 |
13 | String type() default "BROWSER";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/Opera.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ElementType.TYPE, ElementType.METHOD})
10 | public @interface Opera {
11 | String value() default "Opera";
12 |
13 | String type() default "BROWSER";
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/annotations/browser/PhantomJs.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.annotations.browser;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Deprecated
9 | @Retention(RetentionPolicy.RUNTIME)
10 | @Target({ElementType.TYPE, ElementType.METHOD})
11 | public @interface PhantomJs {
12 | String value() default "PhantomJs";
13 |
14 | String type() default "BROWSER";
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/ansonliao/selenium/factory/ChromeFactory.java:
--------------------------------------------------------------------------------
1 | package com.github.ansonliao.selenium.factory;
2 |
3 | import org.openqa.selenium.WebDriver;
4 | import org.openqa.selenium.chrome.ChromeDriver;
5 | import org.openqa.selenium.chrome.ChromeOptions;
6 | import org.openqa.selenium.remote.DesiredCapabilities;
7 | import org.slf4j.Logger;
8 | import org.slf4j.LoggerFactory;
9 | import org.testng.util.Strings;
10 |
11 | import java.io.File;
12 | import java.util.List;
13 | import java.util.Map;
14 |
15 | import static com.github.ansonliao.selenium.utils.CapsUtils.getCaps;
16 | import static com.github.ansonliao.selenium.utils.CapsUtils.getCliArgs;
17 | import static com.github.ansonliao.selenium.utils.CapsUtils.getExtensions;
18 | import static com.github.ansonliao.selenium.utils.PlatformUtils.getPlatform;
19 | import static com.github.ansonliao.selenium.utils.StringUtils.removeQuoteMark;
20 | import static com.github.ansonliao.selenium.utils.config.SEConfigs.getConfigInstance;
21 | import static java.util.stream.Collectors.toList;
22 | import static org.openqa.selenium.remote.BrowserType.CHROME;
23 |
24 | /**
25 | * 1.
26 | * Chromedriver Capabilities & ChromeOptions:
27 | * http://chromedriver.chromium.org/capabilities
28 | * https://stackoverflow.com/a/46786163
29 | * 2.
30 | * About set the mobile emulator, please refer to:
31 | * http://chromedriver.chromium.org/mobile-emulation
32 | * 3.
33 | * ChromeDriver options argument list can refer to:
34 | * http://peter.sh/experiments/chromium-command-line-switches/
35 | * https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc
36 | * https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc
37 | */
38 | public class ChromeFactory extends DriverManager {
39 |
40 | private static final Logger logger = LoggerFactory.getLogger(ChromeFactory.class);
41 | private static ChromeFactory instance = new ChromeFactory();
42 | private ChromeOptions options = new ChromeOptions();
43 |
44 | private ChromeFactory() {
45 | super();
46 | }
47 |
48 | public synchronized static ChromeFactory getInstance() {
49 | return instance;
50 | }
51 |
52 | @Override
53 | public WebDriver getDriver() {
54 | List