Created
November 2, 2021 17:46
-
-
Save RDayal11/e5b6329cd6d872e9bd910438ef3c2137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LambdaTest; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.AssertJUnit; | |
import org.testng.Reporter; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
class MinimizeBrowserWindow { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public static RemoteWebDriver driver = null; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@BeforeClass | |
public void setUp() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "chrome"); | |
capabilities.setCapability("version", "95.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeBrowserWindow"); | |
capabilities.setCapability("name", "MinimizeBrowserWindowUsingSelenium"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
@Test | |
public void minimizeBrowserWindow() { | |
try { | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
driver.manage().window().minimize(); | |
Reporter.log("Minimized the browser window", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
} catch (Exception e) { | |
} | |
} | |
@AfterClass | |
public void closeBrowser() { | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LambdaTest; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.AssertJUnit; | |
import org.testng.Reporter; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import java.awt.*; | |
import java.awt.event.KeyEvent; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
class MinimizeBrowserWindowUsingKeyboardShorcut { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public static RemoteWebDriver driver = null; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@BeforeClass | |
public void setUp() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "chrome"); | |
capabilities.setCapability("version", "95.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeBrowserWindow"); | |
capabilities.setCapability("name", "MinimizeBrowserWindowUsingWindowShortcut"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
@Test | |
public void minimizeBrowserWindowUsingKeyboardShortcut() { | |
try { | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
Robot robot = new Robot(); | |
robot.keyPress(KeyEvent.VK_WINDOWS); | |
robot.keyPress(KeyEvent.VK_D); | |
Reporter.log("Minimizing the window", true); | |
robot.keyRelease(KeyEvent.VK_WINDOWS); | |
robot.keyRelease(KeyEvent.VK_D); | |
Reporter.log("Minimized the browser window", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
} catch (Exception e) { | |
} | |
} | |
@AfterClass | |
public void closeBrowser() { | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LambdaTest; | |
import org.openqa.selenium.Point; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.AssertJUnit; | |
import org.testng.Reporter; | |
import org.testng.annotations.AfterClass; | |
import org.testng.annotations.BeforeClass; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
class MinimizeBrowserWindowUsingPosition { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public static RemoteWebDriver driver = null; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@BeforeClass | |
public void setUp() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "chrome"); | |
capabilities.setCapability("version", "95.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeBrowserWindowBySettingPosition"); | |
capabilities.setCapability("name", "MinimizeBrowserWindowBySettingPositionUsingSelenium"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
@Test | |
public void minimizeBrowserWindowBySettingPosition() { | |
try { | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
driver.manage().window().setPosition(new Point(0,-1000)); | |
Reporter.log("Minimized the browser window by setting its position", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
} catch (Exception e) { | |
} | |
} | |
@AfterClass | |
public void closeBrowser() { | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LambdaTest; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.AssertJUnit; | |
import org.testng.Reporter; | |
import org.testng.annotations.Test; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
class MinimizeMultipleBrowserWindow { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@Test | |
public void minimizeWindowInChromeBrowser() { | |
try { | |
RemoteWebDriver driver = null; | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "Chrome"); | |
capabilities.setCapability("version", "latest"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeChromeBrowserWindow"); | |
capabilities.setCapability("name", "MinimizeChromeBrowserWindowUsingChromeBrowser"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
driver.manage().window().minimize(); | |
Reporter.log("Minimized the browser window", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} catch (Exception e) { | |
} | |
} | |
@Test | |
public void minimizeWindowInFirefoxBrowser() { | |
try { | |
RemoteWebDriver driver = null; | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "Firefox"); | |
capabilities.setCapability("version", "94.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeFirefoxBrowserWindow"); | |
capabilities.setCapability("name", "MinimizeFirefoxBrowserWindowUsingFireFoxBrowser"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
driver.manage().window().minimize(); | |
Reporter.log("Minimized the browser window", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} catch (Exception e) { | |
} | |
} | |
@Test | |
public void minimizeWindowInMicrosoftEdgeBrowser() { | |
try { | |
RemoteWebDriver driver = null; | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "MicrosoftEdge"); | |
capabilities.setCapability("version", "95.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "MinimizeEdgeBrowserWindow"); | |
capabilities.setCapability("name", "MinimizeEdgeBrowserWindowUsingEdgeBrowser"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
Reporter.log("Logging into Selenium Playground", true); | |
driver.get("http://labs.lambdatest.com/selenium-playground/"); | |
driver.manage().window().minimize(); | |
Reporter.log("Minimized the browser window", true); | |
String title=driver.getTitle(); | |
Reporter.log("The title of web page is:"+title, true); | |
AssertJUnit.assertEquals("The actual and expected messages do not match","Selenium Playground | LambdaTest",title); | |
driver.close(); | |
Reporter.log("Closing the browser", true); | |
} catch (Exception e) { | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>LambdaTest</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-api</artifactId> | |
<version>4.0.0-alpha-7</version> | |
</dependency> | |
<dependency> | |
<groupId>org.testng</groupId> | |
<artifactId>testng</artifactId> | |
<version>6.14.3</version> | |
</dependency> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-remote-driver</artifactId> | |
<version>4.0.0-alpha-7</version> | |
</dependency> | |
</dependencies> | |
<properties> | |
<maven.compiler.source>8</maven.compiler.source> | |
<maven.compiler.target>8</maven.compiler.target> | |
</properties> | |
</project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> | |
<suite name="MinimizeBrowserWindowSuite" parallel="methods" thread-count="3"> | |
<test name="MinimizeBrowserWindowTest" > | |
<classes> | |
<class name="LambdaTest.MinimizeMultipleBrowserWindow" > | |
<methods> | |
<include name="minimizeWindowInChromeBrowser"/> | |
<include name="minimizeWindowInFirefoxBrowser"/> | |
<include name="minimizeWindowInMicrosoftEdgeBrowser"/> | |
</methods> | |
</class> | |
</classes> | |
</test> | |
</suite> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment