File tree Expand file tree Collapse file tree
main/java/com/baeldung/selenium
test/java/com/baeldung/selenium Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
2+ <modelVersion >4.0.0</modelVersion >
3+ <groupId >com.baeldung</groupId >
4+ <artifactId >selenium-junit-testng</artifactId >
5+ <version >0.0.1-SNAPSHOT</version >
6+ <build >
7+ <sourceDirectory >src</sourceDirectory >
8+ <plugins >
9+ <plugin >
10+ <artifactId >maven-compiler-plugin</artifactId >
11+ <version >3.1</version >
12+ <configuration >
13+ <source >1.8</source >
14+ <target >1.8</target >
15+ </configuration >
16+ </plugin >
17+ </plugins >
18+ </build >
19+ <dependencies >
20+ <dependency >
21+ <groupId >org.seleniumhq.selenium</groupId >
22+ <artifactId >selenium-java</artifactId >
23+ <version >2.53.1</version >
24+ </dependency >
25+ <dependency >
26+ <groupId >junit</groupId >
27+ <artifactId >junit</artifactId >
28+ <version >4.8.1</version >
29+ </dependency >
30+ <dependency >
31+ <groupId >org.testng</groupId >
32+ <artifactId >testng</artifactId >
33+ <version >6.9.10</version >
34+ </dependency >
35+ </dependencies >
36+ </project >
Original file line number Diff line number Diff line change 1+ package main .java .com .baeldung .selenium ;
2+
3+ import org .openqa .selenium .WebDriver ;
4+ import org .openqa .selenium .firefox .FirefoxDriver ;
5+
6+ public class SeleniumExample {
7+
8+ private WebDriver webDriver ;
9+ private final String url = "http://www.baeldung.com/" ;
10+ private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials" ;
11+
12+ public SeleniumExample () {
13+ webDriver = new FirefoxDriver ();
14+ webDriver .get (url );
15+ }
16+
17+ public void closeWindow () {
18+ webDriver .close ();
19+ }
20+
21+ public String getActualTitle () {
22+ return webDriver .getTitle ();
23+ }
24+
25+ public String getExpectedTitle () {
26+ return expectedTitle ;
27+ }
28+
29+ }
Original file line number Diff line number Diff line change 1+ package test .java .com .baeldung .selenium .junit ;
2+
3+ import static org .testng .Assert .assertEquals ;
4+ import main .java .com .baeldung .selenium .SeleniumExample ;
5+
6+ import org .junit .After ;
7+ import org .junit .Before ;
8+ import org .junit .Test ;
9+
10+ public class TestSeleniumWithJUnit {
11+
12+ private SeleniumExample seleniumExample ;
13+
14+ @ Before
15+ public void setUp () {
16+ seleniumExample = new SeleniumExample ();
17+ }
18+
19+ @ After
20+ public void tearDown () {
21+ seleniumExample .closeWindow ();
22+ }
23+
24+ @ Test
25+ public void whenPageIsLoaded_thenTitleIsAsPerExpectation () {
26+ String expectedTitle = seleniumExample .getExpectedTitle ();
27+ String actualTitle = seleniumExample .getActualTitle ();
28+ assertEquals (actualTitle , expectedTitle );
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package test .java .com .baeldung .selenium .testng ;
2+
3+ import static org .testng .Assert .assertEquals ;
4+ import main .java .com .baeldung .selenium .SeleniumExample ;
5+
6+ import org .testng .annotations .AfterSuite ;
7+ import org .testng .annotations .BeforeSuite ;
8+ import org .testng .annotations .Test ;
9+
10+ public class TestSeleniumWithTestNG {
11+
12+ private SeleniumExample seleniumExample ;
13+
14+ @ BeforeSuite
15+ public void setUp () {
16+ seleniumExample = new SeleniumExample ();
17+ }
18+
19+ @ AfterSuite
20+ public void tearDown () {
21+ seleniumExample .closeWindow ();
22+ }
23+
24+ @ Test
25+ public void whenPageIsLoaded_thenTitleIsAsPerExpectation () {
26+ String expectedTitle = seleniumExample .getExpectedTitle ();
27+ String actualTitle = seleniumExample .getActualTitle ();
28+ assertEquals (actualTitle , expectedTitle );
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ package com .baeldun .selenium .testng ;
2+ import static org .testng .Assert .assertEquals ;
3+ import static org .testng .Assert .assertNotNull ;
4+
5+ import org .openqa .selenium .WebDriver ;
6+ import org .openqa .selenium .firefox .FirefoxDriver ;
7+ import org .testng .annotations .AfterSuite ;
8+ import org .testng .annotations .BeforeSuite ;
9+ import org .testng .annotations .Test ;
10+
11+ public class TestSeleniumWithTestNG {
12+
13+ private WebDriver webDriver ;
14+ private final String url = "http://www.baeldung.com/" ;
15+ private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials" ;
16+
17+ @ BeforeSuite
18+ public void setUp () {
19+ webDriver = new FirefoxDriver ();
20+ webDriver .get (url );
21+ }
22+
23+ @ AfterSuite
24+ public void tearDown () {
25+ webDriver .close ();
26+ }
27+
28+ @ Test
29+ public void whenPageIsLoaded_thenTitleIsAsPerExpectation () {
30+ String actualTitleReturned = webDriver .getTitle ();
31+ assertNotNull (actualTitleReturned );
32+ assertEquals (expectedTitle , actualTitleReturned );
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .selenium .junit ;
2+ import static org .junit .Assert .assertEquals ;
3+ import static org .junit .Assert .assertNotNull ;
4+
5+ import org .junit .After ;
6+ import org .junit .Before ;
7+ import org .junit .Test ;
8+ import org .openqa .selenium .WebDriver ;
9+ import org .openqa .selenium .firefox .FirefoxDriver ;
10+
11+ public class TestSeleniumWithJUnit {
12+
13+ private WebDriver webDriver ;
14+ private final String url = "http://www.baeldung.com/" ;
15+ private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials" ;
16+
17+ @ Before
18+ public void setUp () {
19+ webDriver = new FirefoxDriver ();
20+ webDriver .get (url );
21+ }
22+
23+ @ After
24+ public void tearDown () {
25+ webDriver .close ();
26+ }
27+
28+ @ Test
29+ public void whenPageIsLoaded_thenTitleIsAsPerExpectation () {
30+ String actualTitleReturned = webDriver .getTitle ();
31+ assertNotNull (actualTitleReturned );
32+ assertEquals (expectedTitle , actualTitleReturned );
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments