Minimize Window in Selenium - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Friday 30 March 2018

Minimize Window in Selenium

Unfortunately, Selenium do not provide any built-in function for minimizing the browser window, there is only function for maximizing the window. But there are some work around for doing this.

You want window to be out of sight, then you need to use this code. by using it browser window will be out of your sight and you will not be able to see what is running, but don't worry your test cases will keep on executing. It is tried and tested work around.

//Snippet
 driver.manage().window().setPosition(new Point(-2000,0));


package com.neeraj.test.neeraj;

import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class ok {

    public static WebDriver driver = new ChromeDriver();

    @Test
    public void add1() throws InterruptedException{

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

        driver.get("https://www.facebook.com");
        driver.manage().window().setPosition(new Point(-2000,0));
       
    }

}

No comments:

Post a Comment