Alert Assert

This commit is contained in:
Guillem Hernandez Sola
2026-06-15 10:58:19 +02:00
parent 24e4ea185a
commit e9cdaa1edd

View File

@@ -1,13 +1,15 @@
package com.agile611.testng.webdriver; package com.agile611.testng.webdriver;
import java.time.Duration;
import org.openqa.selenium.Alert; import org.openqa.selenium.Alert;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import java.time.Duration;
public class AlertsTest extends BaseTest { public class AlertsTest extends BaseTest {
public void acceptAlert() { public void acceptAlert() {
@@ -48,21 +50,26 @@ public class AlertsTest extends BaseTest {
@Test @Test
public void testApp() throws InterruptedException { public void testApp() throws InterruptedException {
driver.navigate().to("https://the-internet.herokuapp.com/javascript_alerts"); driver.navigate().to("https://the-internet.herokuapp.com/javascript_alerts");
WebElement resultBanner = driver.findElement(By.id("result"));
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[1]/button")).click(); driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[1]/button")).click();
Thread.sleep(2000); Thread.sleep(2000);
acceptAlert(); acceptAlert();
Thread.sleep(2000); Thread.sleep(2000);
Assert.assertEquals(resultBanner.getText(), "You successfully clicked an alert");
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click(); driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click();
Thread.sleep(2000); Thread.sleep(2000);
acceptAlert(); acceptAlert();
Thread.sleep(2000); Thread.sleep(2000);
Assert.assertEquals(resultBanner.getText(), "You clicked: Ok");
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click(); driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[2]/button")).click();
Thread.sleep(2000); Thread.sleep(2000);
dismissAlert(); dismissAlert();
Thread.sleep(2000); Thread.sleep(2000);
Assert.assertEquals(resultBanner.getText(), "You clicked: Cancel");
driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[3]/button")).click(); driver.findElement(By.xpath(".//*[@id='content']/div/ul/li[3]/button")).click();
Thread.sleep(2000); Thread.sleep(2000);
promptAlert(); promptAlert();
Thread.sleep(2000); Thread.sleep(2000);
Assert.assertEquals(resultBanner.getText(), "You entered: Hola hola super hola");
} }
} }