diff --git a/selenium-junit-testng/test/com/baeldun/selenium/testng/TestSeleniumWithTestNG.java b/selenium-junit-testng/test/com/baeldun/selenium/testng/TestSeleniumWithTestNG.java new file mode 100644 index 0000000000..dcdfafc4f1 --- /dev/null +++ b/selenium-junit-testng/test/com/baeldun/selenium/testng/TestSeleniumWithTestNG.java @@ -0,0 +1,34 @@ +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); + } +} diff --git a/selenium-junit-testng/test/com/baeldung/selenium/junit/TestSeleniumWithJUnit.java b/selenium-junit-testng/test/com/baeldung/selenium/junit/TestSeleniumWithJUnit.java new file mode 100644 index 0000000000..a7b36c4e4e --- /dev/null +++ b/selenium-junit-testng/test/com/baeldung/selenium/junit/TestSeleniumWithJUnit.java @@ -0,0 +1,34 @@ +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); + } +}