Modify test cases for About Page
This commit is contained in:
parent
efaf0c4b85
commit
4639d46705
@ -37,12 +37,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.8.1</version>
|
<version>4.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testng</groupId>
|
<groupId>org.testng</groupId>
|
||||||
<artifactId>testng</artifactId>
|
<artifactId>testng</artifactId>
|
||||||
<version>6.9.10</version>
|
<version>6.9.13.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,11 @@
|
|||||||
package main.java.com.baeldung.selenium;
|
package main.java.com.baeldung.selenium;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
|
||||||
public class SeleniumExample {
|
public class SeleniumExample {
|
||||||
@ -10,6 +15,8 @@ public class SeleniumExample {
|
|||||||
|
|
||||||
public SeleniumExample() {
|
public SeleniumExample() {
|
||||||
webDriver = new FirefoxDriver();
|
webDriver = new FirefoxDriver();
|
||||||
|
webDriver.manage().window().maximize();
|
||||||
|
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||||
webDriver.get(url);
|
webDriver.get(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,4 +28,34 @@ public class SeleniumExample {
|
|||||||
return webDriver.getTitle();
|
return webDriver.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getAboutBaeldungPage() {
|
||||||
|
closeOverlay();
|
||||||
|
clickAboutLink();
|
||||||
|
clickAboutUsLink();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeOverlay() {
|
||||||
|
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
|
||||||
|
if (webElementList != null && !webElementList.isEmpty()) {
|
||||||
|
for (WebElement webElement : webElementList) {
|
||||||
|
if (webElement.getAttribute("title").equalsIgnoreCase("Close")) {
|
||||||
|
webElement.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clickAboutLink() {
|
||||||
|
webDriver.findElement(By.partialLinkText("About")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clickAboutUsLink() {
|
||||||
|
webDriver.findElement(By.partialLinkText("About Baeldung.")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAuthorInformationAvailable() {
|
||||||
|
return webDriver
|
||||||
|
.findElement(By.xpath("//*[contains(text(), 'Eugen – an engineer')]"))
|
||||||
|
.isDisplayed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +1,41 @@
|
|||||||
package test.java.com.baeldung.selenium.junit;
|
package test.java.com.baeldung.selenium.junit;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestSeleniumWithJUnit {
|
public class TestSeleniumWithJUnit {
|
||||||
|
|
||||||
private SeleniumExample seleniumExample;
|
private static SeleniumExample seleniumExample;
|
||||||
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
|
private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung";
|
||||||
|
|
||||||
@Before
|
@BeforeClass
|
||||||
public void setUp() {
|
public static void setUp() {
|
||||||
seleniumExample = new SeleniumExample();
|
seleniumExample = new SeleniumExample();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterClass
|
||||||
public void tearDown() {
|
public static void tearDown() {
|
||||||
seleniumExample.closeWindow();
|
seleniumExample.closeWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
|
||||||
String actualTitle = seleniumExample.getTitle();
|
try {
|
||||||
assertNotNull(actualTitle);
|
seleniumExample.getAboutBaeldungPage();
|
||||||
assertEquals(actualTitle, expectedTitle);
|
String actualTitle = seleniumExample.getTitle();
|
||||||
|
assertNotNull(actualTitle);
|
||||||
|
assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
|
||||||
|
assertTrue(seleniumExample.isAuthorInformationAvailable());
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
seleniumExample.closeWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package test.java.com.baeldung.selenium.testng;
|
package test.java.com.baeldung.selenium.testng;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
import main.java.com.baeldung.selenium.SeleniumExample;
|
import main.java.com.baeldung.selenium.SeleniumExample;
|
||||||
|
|
||||||
import org.testng.annotations.AfterSuite;
|
import org.testng.annotations.AfterSuite;
|
||||||
@ -10,7 +12,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";
|
private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung";
|
||||||
|
|
||||||
@BeforeSuite
|
@BeforeSuite
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@ -23,9 +25,16 @@ public class TestSeleniumWithTestNG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
|
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
|
||||||
String actualTitle = seleniumExample.getTitle();
|
try {
|
||||||
assertNotNull(actualTitle);
|
seleniumExample.getAboutBaeldungPage();
|
||||||
assertEquals(actualTitle, expectedTitle);
|
String actualTitle = seleniumExample.getTitle();
|
||||||
|
assertNotNull(actualTitle);
|
||||||
|
assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
|
||||||
|
assertTrue(seleniumExample.isAuthorInformationAvailable());
|
||||||
|
} catch (Exception exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
seleniumExample.closeWindow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user