File tree Expand file tree Collapse file tree
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 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