publicclassJavaScriptAlertTest {WebDriver driver; @BeforeClassvoidsetUp() { driver =newChromeDriver();driver.get("https://the-internet.herokuapp.com/javascript_alerts"); } @TestvoidclickForJSAlert(){driver.findElement(By.xpath("//button[.='Click for JS Alert']")).click();driver.switchTo().alert().accept(); // ~ click on OK button on alert popupString result =driver.findElement(By.id("result")).getText();Assert.assertEquals(result,"You successfully clicked an alert"); } @TestvoiddismissForJsConfirm(){driver.findElement(By.xpath("//button[.='Click for JS Confirm']")).click();driver.switchTo().alert().dismiss(); // ~ click on Cancel button on alert popupString result =driver.findElement(By.id("result")).getText();Assert.assertEquals(result,"You clicked: Cancel"); } @TestvoidacceptForJsConfirm(){driver.findElement(By.xpath("//button[.='Click for JS Confirm']")).click();driver.switchTo().alert().accept(); // ~ click on Cancel button on alert popupString result =driver.findElement(By.id("result")).getText();Assert.assertEquals(result,"You clicked: Ok"); } @TestvoidclickForJsPrompt(){driver.findElement(By.xpath("//button[.='Click for JS Prompt']")).click();driver.switchTo().alert().sendKeys("hello");driver.switchTo().alert().accept();String result =driver.findElement(By.id("result")).getText();Assert.assertEquals(result,"You entered: hello"); } @AfterClassvoidtearDown(){driver.quit(); }}