Skip to content

Commit 95b8cb4

Browse files
authored
Merge pull request #2 from mfaisalkhatri/issue-1
Selenium Manager tests as per 4.11.0 version added.
2 parents 82aa2b8 + 052640d commit 95b8cb4

File tree

10 files changed

+5483
-119
lines changed

10 files changed

+5483
-119
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# IntelliJ IDEA
2+
/.idea/
3+
*.iml
4+
5+
# Other output folders
6+
/target/
7+
/bin/
8+
/test-output/
9+
/logs/
10+
/reports/
11+
12+
# Mac OSX
13+
/.DS_Store
14+
.DS_Store
15+
16+
#VS code
17+
/.vscode

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
This simple example demonstrates how to use Selenium Manager in Selenium 4.6 (and above). For the demonstration, I have made use of Selenium 4.7.
1+
This simple example demonstrates how to use Selenium Manager in Selenium 4.6 (and above). For the demonstration, I have
2+
made use of Selenium 4.11.0
23

34
## What is Selenium Manager
45

56
Selenium Manager is a new tool that helps to get a working environment to run Selenium out of the box.
67

7-
Available with Selenium v4.6 (and above), it automatically configures the browser drivers for Chrome, Firefox, Internet Explorer, and Edge.
8+
Available with Selenium v4.6 (and above), it automatically configures the browser drivers for Chrome, Firefox, Internet
9+
Explorer, and Edge.
810

911
More information about Selenium Manager is available in the following locations:
1012

@@ -14,13 +16,17 @@ More information about Selenium Manager is available in the following locations:
1416

1517
## How to use Selenium Manager in Java
1618

17-
* Add [Selenium Manager dependency](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-manager/4.7.0) in pom.xml
19+
* Add [Selenium Java 4.11.0](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.11.0) dependency
20+
in pom.xml
1821

19-
<img width="459" alt="Selenium-Manager-POM" src="https://user-images.githubusercontent.com/1688653/207520606-b6d87531-3341-4aab-a31f-b979deeeb1a5.png">
20-
21-
* Add [Selenium Java 4.7.0](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.7.0) dependency in pom.xml
22-
23-
<img width="459" alt="Selenium-Java-POM" src="https://user-images.githubusercontent.com/1688653/207520702-f7140f2f-1791-481d-a538-2a6eecc9966d.png">
22+
```xml
23+
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
24+
<dependency>
25+
<groupId>org.seleniumhq.selenium</groupId>
26+
<artifactId>selenium-java</artifactId>
27+
<version>4.11.0</version>
28+
</dependency>
29+
```
2430

2531
## Execution
2632

@@ -30,10 +36,12 @@ Here is all what is needed to instantiate the browsers:
3036
* Firefox ------> WebDriver driver = new FirefoxDriver();
3137
* Edge --------> WebDriver driver = new EdgeDriver();
3238

33-
For demonstration, I used the *getInstance* method in *SeleniumManager* to print the location where the respective browser drivers are downloaded:
39+
For demonstration, I used the *getInstance* method in *SeleniumManager* to print the location where the respective
40+
browser drivers are downloaded:
3441

3542
<img width="1420" alt="VS_IDE_Selenium_Manager_2" src="https://user-images.githubusercontent.com/1688653/207524076-dfa57992-93fb-460b-9ee5-1d4d85cd6fcc.png">
3643

37-
On execution, the browser drivers are downloaded in */Users/applemacbook_pro/.cache/selenium* folder. These would be re-downloaded in case there is any update in the browser version.
44+
On execution, the browser drivers are downloaded in */Users/applemacbook_pro/.cache/selenium* folder. These would be
45+
re-downloaded in case there is any update in the browser version.
3846

3947
<img width="728" alt="CMD_Selenium_Manager" src="https://user-images.githubusercontent.com/1688653/207521761-bcebdaa1-e30a-4743-8b62-8d350d98ab3f.png">

pom.xml

Lines changed: 56 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,119 +2,80 @@
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
6-
<groupId>org.example</groupId>
7-
<artifactId>TestNG_Demo</artifactId>
8-
<version>1.0-SNAPSHOT</version>
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.lambdatest</groupId>
7+
<artifactId>selenium-manager-demo</artifactId>
8+
<version>1.0-SNAPSHOT</version>
99

10-
<properties>
11-
<maven.compiler.source>1.8</maven.compiler.source>
12-
<maven.compiler.target>1.8</maven.compiler.target>
13-
</properties>
10+
<properties>
11+
<selenium-java.version>4.11.0</selenium-java.version>
12+
<webdrivermanager.version>5.4.1</webdrivermanager.version>
13+
<testng.version>7.8.0</testng.version>
14+
<maven.compiler.version>3.11.0</maven.compiler.version>
15+
<surefire-version>3.1.2</surefire-version>
16+
<java.release.version>17</java.release.version>
17+
<maven.source.encoding>UTF-8</maven.source.encoding>
18+
<suite-xml>test-suite/testng.xml</suite-xml>
19+
<argLine>-Dfile.encoding=UTF-8 -Xdebug -Xnoagent</argLine>
20+
</properties>
1421

15-
<dependencies>
16-
<dependency>
17-
<groupId>org.testng</groupId>
18-
<artifactId>testng</artifactId>
19-
<version>7.6.1</version>
20-
<scope>test</scope>
21-
</dependency>
22-
<dependency>
23-
<groupId>org.slf4j</groupId>
24-
<artifactId>slf4j-nop</artifactId>
25-
<version>1.7.28</version>
26-
<scope>test</scope>
27-
</dependency>
28-
<dependency>
29-
<groupId>org.seleniumhq.selenium</groupId>
30-
<artifactId>selenium-java</artifactId>
31-
<version>4.7.0</version>
32-
</dependency>
33-
<dependency>
34-
<groupId>org.seleniumhq.selenium</groupId>
35-
<artifactId>selenium-chrome-driver</artifactId>
36-
<version>4.7.0</version>
37-
</dependency>
38-
<dependency>
39-
<groupId>junit</groupId>
40-
<artifactId>junit</artifactId>
41-
<version>4.12</version>
42-
<scope>test</scope>
43-
</dependency>
44-
<dependency>
45-
<groupId>org.apache.httpcomponents</groupId>
46-
<artifactId>httpclient</artifactId>
47-
<version>4.5.13</version>
48-
</dependency>
49-
<!-- https://mvnrepository.com/artifact/com.github.sdrss/reportng -->
50-
<dependency>
51-
<groupId>org.uncommons</groupId>
52-
<artifactId>reportng</artifactId>
53-
<version>1.1.4</version>
54-
</dependency>
55-
<dependency>
56-
<groupId>com.google.inject</groupId>
57-
<artifactId>guice</artifactId>
58-
<version>4.2.2</version>
59-
</dependency>
60-
<dependency>
61-
<groupId>org.apache.maven.plugins</groupId>
62-
<artifactId>maven-surefire-plugin</artifactId>
63-
<version>3.0.0-M5</version>
64-
<type>maven-plugin</type>
65-
</dependency>
66-
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
67-
<dependency>
68-
<groupId>io.github.bonigarcia</groupId>
69-
<artifactId>webdrivermanager</artifactId>
70-
<version>5.3.0</version>
71-
</dependency>
72-
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-manager -->
73-
<dependency>
74-
<groupId>org.seleniumhq.selenium</groupId>
75-
<artifactId>selenium-manager</artifactId>
76-
<version>4.7.0</version>
77-
</dependency>
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.seleniumhq.selenium</groupId>
25+
<artifactId>selenium-java</artifactId>
26+
<version>${selenium-java.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.testng</groupId>
30+
<artifactId>testng</artifactId>
31+
<version>${testng.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
35+
<dependency>
36+
<groupId>io.github.bonigarcia</groupId>
37+
<artifactId>webdrivermanager</artifactId>
38+
<version>${webdrivermanager.version}</version>
39+
</dependency>
7840

79-
</dependencies>
80-
81-
<build>
82-
<defaultGoal>install</defaultGoal>
41+
</dependencies>
42+
<build>
8343
<plugins>
8444
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
8546
<artifactId>maven-compiler-plugin</artifactId>
86-
<version>3.7.0</version>
47+
<version>${maven.compiler.version}</version>
8748
<configuration>
88-
<source>1.8</source>
89-
<target>1.8</target>
49+
<release>${java.release.version}</release>
50+
<encoding>${maven.source.encoding}</encoding>
51+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
9052
</configuration>
9153
</plugin>
9254
<plugin>
9355
<groupId>org.apache.maven.plugins</groupId>
9456
<artifactId>maven-surefire-plugin</artifactId>
95-
<version>3.0.0-M5</version>
57+
<version>${surefire-version}</version>
58+
<executions>
59+
<execution>
60+
<goals>
61+
<goal>test</goal>
62+
</goals>
63+
</execution>
64+
</executions>
9665
<configuration>
97-
<properties> <property>
98-
<name>usedefaultlisteners</name>
99-
<value>false</value>
100-
</property>
66+
<useSystemClassLoader>false</useSystemClassLoader>
67+
<properties>
10168
<property>
102-
<name>listener</name>
103-
<value>org.uncommons.reportng.HTMLReporter,
104-
org.uncommons.reportng.JUnitXMLReporter
105-
</value>
106-
</property> </properties>
69+
<name>usedefaultlisteners</name>
70+
<value>false</value>
71+
</property>
72+
</properties>
10773
<suiteXmlFiles>
108-
<!-- TestNG suite XML files -->
109-
<suiteXmlFile>testng.xml</suiteXmlFile>
74+
<suiteXmlFile>${suite-xml}</suiteXmlFile>
11075
</suiteXmlFiles>
76+
<argLine>${argLine}</argLine>
11177
</configuration>
11278
</plugin>
113-
<plugin>
114-
<groupId>org.apache.maven.plugins</groupId>
115-
<artifactId>maven-surefire-report-plugin</artifactId>
116-
<version>3.0.0-M5</version>
117-
</plugin>
11879
</plugins>
11980
</build>
12081
</project>

src/.DS_Store

0 Bytes
Binary file not shown.

src/test/.DS_Store

0 Bytes
Binary file not shown.

src/test/java/SeleniumManagerDemo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import org.openqa.selenium.chrome.ChromeDriver;
33
import org.openqa.selenium.edge.EdgeDriver;
44
import org.openqa.selenium.firefox.FirefoxDriver;
5+
import org.testng.annotations.Ignore;
56
import org.testng.annotations.Test;
6-
import org.openqa.selenium.manager.SeleniumManager;
77

88
public class SeleniumManagerDemo
99
{
1010
protected static ThreadLocal<WebDriver> ThreadLocal
1111
= new ThreadLocal<WebDriver>();
1212

1313
String testURL = "https://www.lambdatest.com";
14-
14+
1515
@Test(description="Demonstration of Toggle Buttons on LambdaTest Selenium Grid")
1616
public void testEdge() throws InterruptedException {
1717
/* Selenium Manager - MS Edge */
@@ -39,6 +39,7 @@ public void testEdge() throws InterruptedException {
3939
Thread.sleep(5000);
4040
}
4141

42+
@Ignore
4243
@Test(description="Demonstration of Toggle Buttons on LambdaTest Selenium Grid")
4344
public void testFirefox() throws InterruptedException {
4445
/* Selenium Manager - Firefox */
@@ -89,6 +90,5 @@ public void testChrome() throws InterruptedException {
8990
driver.quit();
9091
ThreadLocal.remove();
9192

92-
Thread.sleep(5000);
9393
}
9494
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import org.openqa.selenium.WebDriver;
2+
import org.openqa.selenium.chrome.ChromeDriver;
3+
import org.openqa.selenium.chrome.ChromeOptions;
4+
import org.openqa.selenium.edge.EdgeDriver;
5+
import org.openqa.selenium.firefox.FirefoxDriver;
6+
import org.testng.annotations.AfterMethod;
7+
import org.testng.annotations.DataProvider;
8+
import org.testng.annotations.Test;
9+
10+
import java.util.ArrayList;
11+
import java.util.Iterator;
12+
import java.util.List;
13+
14+
import static org.testng.Assert.assertEquals;
15+
16+
public class SeleniumWebDriverManagerTests {
17+
18+
private WebDriver driver;
19+
@Test
20+
public void testOnChromeOldVersionWithSeleniumManager() {
21+
final ChromeOptions options = new ChromeOptions();
22+
options.setBrowserVersion("113");
23+
this.driver = new ChromeDriver(options);
24+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
25+
26+
assertEquals(this.driver.getTitle(), "Your Store");
27+
}
28+
29+
@DataProvider
30+
public Iterator<Object[]> browserVersions() {
31+
final List<Object[]> versions = new ArrayList<>();
32+
versions.add(new Object[]{"stable"});
33+
versions.add(new Object[]{"beta"});
34+
versions.add(new Object[]{"dev"});
35+
versions.add(new Object[]{"canary"});
36+
return versions.iterator();
37+
}
38+
39+
@Test(dataProvider = "browserVersions")
40+
public void testChromeVersionsWithSeleniumManager(final String browserVersion) {
41+
final ChromeOptions options = new ChromeOptions();
42+
options.setBrowserVersion(browserVersion);
43+
this.driver = new ChromeDriver(options);
44+
45+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
46+
47+
assertEquals(this.driver.getTitle(), "Your Store");
48+
}
49+
50+
@Test
51+
public void testChromeLatestVersionWithSeleniumManager() {
52+
this.driver = new ChromeDriver();
53+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
54+
55+
assertEquals(this.driver.getTitle(), "Your Store");
56+
}
57+
58+
@Test
59+
public void testOnChromeOldVersion112() {
60+
final ChromeOptions options = new ChromeOptions();
61+
options.setBrowserVersion("112");
62+
63+
this.driver = new ChromeDriver(options);
64+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
65+
66+
assertEquals(this.driver.getTitle(), "Your Store");
67+
}
68+
69+
70+
@Test
71+
public void testOnChromeBySettingEnvVariablePath() {
72+
73+
//Update the chromedriver.exe path in the Environment variable before running this test.
74+
final WebDriver driver = new ChromeDriver();
75+
driver.get("https://ecommerce-playground.lambdatest.io/");
76+
driver.quit();
77+
78+
}
79+
80+
@Test
81+
public void testOnChromeBySettingBinaryPathUsingSetProperty() {
82+
83+
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/src/test/resources/chromedriver_mac_arm64/chromedriver");
84+
this.driver = new ChromeDriver();
85+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
86+
87+
assertEquals(this.driver.getTitle(), "Your Store");
88+
}
89+
90+
@Test
91+
public void testOnFirefoxLatestVersionWithSeleniumManager() {
92+
this.driver = new FirefoxDriver();
93+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
94+
95+
assertEquals(this.driver.getTitle(), "Your Store");
96+
}
97+
98+
@Test
99+
public void testOnEdgeLatestVersionWithSeleniumManager() {
100+
this.driver = new EdgeDriver();
101+
this.driver.get("https://ecommerce-playground.lambdatest.io/");
102+
103+
assertEquals(this.driver.getTitle(), "Your Store");
104+
}
105+
106+
@AfterMethod(alwaysRun = true)
107+
public void tearDown() {
108+
this.driver.quit();
109+
}
110+
}

0 commit comments

Comments
 (0)