Skip to content

Commit

Permalink
[java] reformat code [deploy site]
Browse files Browse the repository at this point in the history
  • Loading branch information
harsha509 committed Sep 27, 2024
1 parent 8389e17 commit 2db9a37
Showing 1 changed file with 59 additions and 58 deletions.
117 changes: 59 additions & 58 deletions examples/java/src/test/java/dev/selenium/interactions/AlertsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,69 +23,70 @@
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AlertsTest {

@Test
public void testForAlerts() throws Exception {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("disable-search-engine-choice-screen");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
driver.manage().window().maximize();
//Navigate to Url
driver.get("https://www.selenium.dev/documentation/webdriver/interactions/alerts/");
//Simple Alert
//Click the link to activate the alert
JavascriptExecutor js = (JavascriptExecutor) driver;
//execute js for alert
js.executeScript("alert('Sample Alert');");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
//Wait for the alert to be displayed and store it in a variable
wait.until(ExpectedConditions.alertIsPresent());
Alert alert=driver.switchTo().alert();
//Store the alert text in a variable and verify it
String text = alert.getText();
assertEquals(text,"Sample Alert");
//Press the OK button
alert.accept();
//Confirm
//execute js for confirm
js.executeScript("confirm('Are you sure?');");
//Wait for the alert to be displayed
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.alertIsPresent());
alert = driver.switchTo().alert();
//Store the alert text in a variable and verify it
text = alert.getText();
assertEquals(text,"Are you sure?");
//Press the Cancel button
alert.dismiss();
//Prompt
//execute js for prompt
js.executeScript("prompt('What is your name?');");
//Wait for the alert to be displayed and store it in a variable
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.alertIsPresent());
alert = driver.switchTo().alert();
//Store the alert text in a variable and verify it
text = alert.getText();
assertEquals(text,"What is your name?");
//Type your message
alert.sendKeys("Selenium");
//Press the OK button
alert.accept();
//quit the browser
driver.quit();

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("disable-search-engine-choice-screen");
WebDriver driver = new ChromeDriver(chromeOptions);

driver.manage().timeouts().implicitlyWait(Duration.ofMillis(500));
driver.manage().window().maximize();
//Navigate to Url
driver.get("https://www.selenium.dev/documentation/webdriver/interactions/alerts/");

//Simple Alert
//Click the link to activate the alert
JavascriptExecutor js = (JavascriptExecutor) driver;
//execute js for alert
js.executeScript("alert('Sample Alert');");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
//Wait for the alert to be displayed and store it in a variable
wait.until(ExpectedConditions.alertIsPresent());

Alert alert = driver.switchTo().alert();
//Store the alert text in a variable and verify it
String text = alert.getText();
assertEquals(text, "Sample Alert");
//Press the OK button
alert.accept();

//Confirm
//execute js for confirm
js.executeScript("confirm('Are you sure?');");
//Wait for the alert to be displayed
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.alertIsPresent());


alert = driver.switchTo().alert();
//Store the alert text in a variable and verify it
text = alert.getText();
assertEquals(text, "Are you sure?");
//Press the Cancel button
alert.dismiss();

//Prompt
//execute js for prompt
js.executeScript("prompt('What is your name?');");
//Wait for the alert to be displayed and store it in a variable
wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(ExpectedConditions.alertIsPresent());

alert = driver.switchTo().alert();
//Store the alert text in a variable and verify it
text = alert.getText();
assertEquals(text, "What is your name?");
//Type your message
alert.sendKeys("Selenium");
//Press the OK button
alert.accept();
//quit the browser
driver.quit();
}
}

0 comments on commit 2db9a37

Please sign in to comment.