Modifying methods in test files

This commit is contained in:
Sandeep Kumar 2016-10-02 18:01:49 +05:30
parent fe59ea2923
commit d4e7c9d4af
6 changed files with 56 additions and 115 deletions

View File

@ -1,36 +1,48 @@
<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"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.baeldung</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>selenium-junit-testng</artifactId> <groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version> <artifactId>selenium-junit-testng</artifactId>
<build> <version>0.0.1-SNAPSHOT</version>
<sourceDirectory>src</sourceDirectory> <build>
<plugins> <sourceDirectory>src</sourceDirectory>
<plugin> <plugins>
<artifactId>maven-compiler-plugin</artifactId> <plugin>
<version>3.1</version> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <version>3.1</version>
<source>1.8</source> <configuration>
<target>1.8</target> <source>1.8</source>
</configuration> <target>1.8</target>
</plugin> </configuration>
</plugins> </plugin>
</build> <plugin>
<dependencies> <groupId>org.apache.maven.plugins</groupId>
<dependency> <artifactId>maven-surefire-plugin</artifactId>
<groupId>org.seleniumhq.selenium</groupId> <version>2.19.1</version>
<artifactId>selenium-java</artifactId> <configuration>
<version>2.53.1</version> <testSourceDirectory></testSourceDirectory>
</dependency> <includes>
<dependency> <include>Test*.java</include>
<groupId>junit</groupId> </includes>
<artifactId>junit</artifactId> </configuration>
<version>4.8.1</version> </plugin>
</dependency> </plugins>
<dependency> </build>
<groupId>org.testng</groupId> <dependencies>
<artifactId>testng</artifactId> <dependency>
<version>6.9.10</version> <groupId>org.seleniumhq.selenium</groupId>
</dependency> <artifactId>selenium-java</artifactId>
</dependencies> <version>2.53.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
</dependency>
</dependencies>
</project> </project>

View File

@ -6,9 +6,8 @@ import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumExample { public class SeleniumExample {
private WebDriver webDriver; private WebDriver webDriver;
private final String url = "http://www.baeldung.com/"; private String url = "http://www.baeldung.com/";
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
public SeleniumExample() { public SeleniumExample() {
webDriver = new FirefoxDriver(); webDriver = new FirefoxDriver();
webDriver.get(url); webDriver.get(url);
@ -18,12 +17,8 @@ public class SeleniumExample {
webDriver.close(); webDriver.close();
} }
public String getActualTitle() { public String getTitle() {
return webDriver.getTitle(); return webDriver.getTitle();
} }
public String getExpectedTitle() {
return expectedTitle;
}
} }

View File

@ -10,6 +10,7 @@ import org.junit.Test;
public class TestSeleniumWithJUnit { public class TestSeleniumWithJUnit {
private SeleniumExample seleniumExample; private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@Before @Before
public void setUp() { public void setUp() {
@ -23,8 +24,8 @@ public class TestSeleniumWithJUnit {
@Test @Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() { public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String expectedTitle = seleniumExample.getExpectedTitle(); String actualTitle = seleniumExample.getTitle();
String actualTitle = seleniumExample.getActualTitle(); assertNotNull(actualTitle);
assertEquals(actualTitle, expectedTitle); assertEquals(actualTitle, expectedTitle);
} }
} }

View File

@ -10,6 +10,7 @@ import org.testng.annotations.Test;
public class TestSeleniumWithTestNG { public class TestSeleniumWithTestNG {
private SeleniumExample seleniumExample; private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@BeforeSuite @BeforeSuite
public void setUp() { public void setUp() {
@ -23,8 +24,8 @@ public class TestSeleniumWithTestNG {
@Test @Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() { public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String expectedTitle = seleniumExample.getExpectedTitle(); String actualTitle = seleniumExample.getTitle();
String actualTitle = seleniumExample.getActualTitle(); assertNotNull(actualTitle);
assertEquals(actualTitle, expectedTitle); assertEquals(actualTitle, expectedTitle);
} }
} }

View File

@ -1,34 +0,0 @@
package com.baeldun.selenium.testng;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestSeleniumWithTestNG {
private WebDriver webDriver;
private final String url = "http://www.baeldung.com/";
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@BeforeSuite
public void setUp() {
webDriver = new FirefoxDriver();
webDriver.get(url);
}
@AfterSuite
public void tearDown() {
webDriver.close();
}
@Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String actualTitleReturned = webDriver.getTitle();
assertNotNull(actualTitleReturned);
assertEquals(expectedTitle, actualTitleReturned);
}
}

View File

@ -1,34 +0,0 @@
package com.baeldung.selenium.junit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestSeleniumWithJUnit {
private WebDriver webDriver;
private final String url = "http://www.baeldung.com/";
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@Before
public void setUp() {
webDriver = new FirefoxDriver();
webDriver.get(url);
}
@After
public void tearDown() {
webDriver.close();
}
@Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String actualTitleReturned = webDriver.getTitle();
assertNotNull(actualTitleReturned);
assertEquals(expectedTitle, actualTitleReturned);
}
}