BAEL 298 | Intro to Selenium with JUnit / TestNg
This commit is contained in:
parent
ae907114c7
commit
2310cf8717
36
selenium-junit-testng/pom.xml
Normal file
36
selenium-junit-testng/pom.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>selenium-junit-testng</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
|
<artifactId>selenium-java</artifactId>
|
||||||
|
<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>
|
@ -0,0 +1,29 @@
|
|||||||
|
package main.java.com.baeldung.selenium;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
|
||||||
|
public class SeleniumExample {
|
||||||
|
|
||||||
|
private WebDriver webDriver;
|
||||||
|
private final String url = "http://www.baeldung.com/";
|
||||||
|
private final String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
||||||
|
|
||||||
|
public SeleniumExample() {
|
||||||
|
webDriver = new FirefoxDriver();
|
||||||
|
webDriver.get(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeWindow() {
|
||||||
|
webDriver.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActualTitle() {
|
||||||
|
return webDriver.getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExpectedTitle() {
|
||||||
|
return expectedTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package test.java.com.baeldung.selenium.junit;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestSeleniumWithJUnit {
|
||||||
|
|
||||||
|
private SeleniumExample seleniumExample;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
seleniumExample = new SeleniumExample();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
seleniumExample.closeWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||||
|
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||||
|
String actualTitle = seleniumExample.getActualTitle();
|
||||||
|
assertEquals(actualTitle, expectedTitle);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package test.java.com.baeldung.selenium.testng;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
|
import org.testng.annotations.AfterSuite;
|
||||||
|
import org.testng.annotations.BeforeSuite;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
public class TestSeleniumWithTestNG {
|
||||||
|
|
||||||
|
private SeleniumExample seleniumExample;
|
||||||
|
|
||||||
|
@BeforeSuite
|
||||||
|
public void setUp() {
|
||||||
|
seleniumExample = new SeleniumExample();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterSuite
|
||||||
|
public void tearDown() {
|
||||||
|
seleniumExample.closeWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
||||||
|
String expectedTitle = seleniumExample.getExpectedTitle();
|
||||||
|
String actualTitle = seleniumExample.getActualTitle();
|
||||||
|
assertEquals(actualTitle, expectedTitle);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user