Skip to content

Instantly share code, notes, and snippets.

@FriendlyTester
Created April 25, 2020 17:07
Show Gist options
  • Save FriendlyTester/fb05db771f215047392e812abfe7e597 to your computer and use it in GitHub Desktop.
Save FriendlyTester/fb05db771f215047392e812abfe7e597 to your computer and use it in GitHub Desktop.
Selenium Minimize Browser Window
import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.Duration;
public class MinimizeWebDriver
{
@Test
public void TryWebDriverMinimise() throws InterruptedException
{
ChromeDriver driver = new ChromeDriver();
//driver.manage().window().maximize();
driver.manage().window().minimize();
driver.navigate().to("https://automationintesting.online");
driver.findElement(By.id("next")).click();
driver.findElement(By.id("next")).click();
driver.findElement(By.id("next")).click();
driver.findElement(By.id("next")).click();
driver.findElement(By.id("closeModal")).click();
driver.findElement(By.id("name")).sendKeys("Richard");
driver.findElement(By.id("email")).sendKeys("[email protected]");
driver.findElement(By.id("phone")).sendKeys("4407123456789");
driver.findElement(By.id("subject")).sendKeys("Checking out WebDriver Minimize");
driver.findElement(By.id("description")).sendKeys("This is my message, I would like to let you know that you should use Window Minimize selectively!");
driver.findElement(By.id("submitContact")).click();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#root > div > div > div.row.contact > div:nth-child(2) > div > h2")));
assertEquals(driver.findElementByCssSelector("#root > div > div > div.row.contact > div:nth-child(2) > div > h2").getText(), "Thanks for getting in touch Richard!");
driver.quit();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>WebDriverMinimize</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment