Resizing Windows in an Automation Script

Here, we'll be creating an automation script that resizes windows. The steps for completion of this process are as follows:

  1. Using the get() method in the ActivityLesson02 constructor, load any known website:
driver.get("https://www.google.com");
  1. Using the manage().window().setSize(Dimension) method, resize the current window:
driver.manage().window().setSize(new Dimension(300,500));
  1. Using the manage().window().getSize() method, verify that the size of the window is equal to the size of the one that you set in step 2. The manage().window().getSize(Dimension) method also provides the getSize().getHeight() and getSize().getWidth() methods:
if (driver.manage().window().getSize().getHeight() == 300
&& driver.manage().window().getSize().getWidth() == 500 )
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Load script worked, the
window was resized");
}
else {
System.out.println("Something went wrong
with the script, the window was not resized to the desired
size");
}
  1. Using the manage().window().maximize() method, maximize the current window:
driver.manage().window().maximize();
  1. Using the manage().window().getSize() method, verify that the size of the window is different from the one that you set in step 2. The manage().window().getSize method also provides the getSize().getHeight() and getSize().getWidth() methods:
if (driver.manage().window().getSize().getHeight() != 300
&& driver.manage().window().getSize().getWidth() != 500 )
  1. Using the System.out.println method, display messages that indicate whether the verification was successful:
{
System.out.println("Load script worked, the
window was resized");
}
else {
System.out.println("Something went wrong
with the script, the window was not resized");
}
  1. Compile and run the script.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.17.20