Manage browser windows [Resize and reposition] with selenium

We can change the browser window position on desktop and resize the windows using selenium commands.
These functionalities helps to view the tests running parallely on different browsers, [we can place browsers side by side to see the actions performed on the browsers].



package testPkg;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ManageWindows {
 public static void main(String[] args) throws InterruptedException {
  WebDriver driver = new FirefoxDriver();
  //driver.manage().window().maximize();
  driver.get("http://www.google.com");
  Thread.sleep(1000);
  driver.manage().window().setSize(new Dimension(500,800));
  Thread.sleep(1000);
  driver.manage().window().setPosition(new Point(100,100));
  
  System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
  WebDriver driver1 = new ChromeDriver();
  driver1.get("http://www.gmail.com");
  Thread.sleep(1000);
  driver1.manage().window().setSize(new Dimension(500,800));
  Thread.sleep(1000);
  driver1.manage().window().setPosition(new Point(700,100));
 }
}



No comments:

Post a Comment