Google+

291. manage( ).window( ).setSize( ) - to resize the Browser window






'manage( ).window( ).setSize( )' predefined method of Selenium 'WebDriver' Class is used to re-size the test browser window in which the specified URL has been opened in our earlier post.

Example:  

_driver.manage( ).window( ).setSize( );

Lets Implement This:

1. Open the URL using the Selenium 'WebDriver' command get( ) as explained in our previous Post#14
2. Declare a Selenium WebDriver's  Dimension Class object say d  by initializing it with width as 500 and height as 600 as shown below:

Dimension d = new Dimension(500,600);

Copy and paste this statement to the Automation Test code as shown below:


3. Observe that an error is displayed with the copied statement as shown below:


4. Lets resolve the above error by hovering our mouse cursor over the Dimension Class and selecting the import statement  Import 'Dimension' (org.openqa.selenium) as shown below:


This means that we are importing the Dimension Class from org.openqa.selenium Selenium package.

5. Ensure that the selected Import statement got added to our test code and the error got resolved as shown below:


6. Now lets write the Selenium WebDriver statement for re-sizing the test browser window by following the next steps.
7. Type _driver object of Selenium 'WebDriver' Class and press dot '.' key on your keyboard as shown below:




8. Type 'manage' text followed by dot as shown below to filter the displayed Selenium 'WebDriver' predefined methods and select the 'manage( )' method as shown below:



9. Ensure that the selected method got added to the Code as shown below:



10. After manage( ) method, press dot '.' key on your keyboard and ensure that the Selenium commands are displayed for selection as shown below:



11. Type 'window' text followed by dot as shown below to filter the displayed Selenium 'WebDriver' predefined methods and select the 'window( )' method as shown below:



12. Ensure that the selected method got added to the Code as shown below:



13. After window( ) method, press dot '.' key on your keyboard as shown below:



14. Type 'set' text followed by dot as shown below to filter the displayed Selenium 'WebDriver' predefined methods and select the 'setSize( )' method as shown below:



15. Ensure that the selected method got added to the Code as shown below:



16. Now end the statement with a semicolon as shown below:




17. Provide the Dimension object created in our previous steps in the current statement as shown below and save:


18. Run the Automation Test using JUnit as shown below:



19. Observe that the Browser window got re-sized to width=500 and height=600 as shown below:



Watch This Video:

Click here to watch the Video

Download This Project

Click here to download the Project explained in this Post and import into Eclipse IDE on your machine.




Please comment below to feedback or ask questions.

Using Thread.sleep(milliseconds); to make the JUnit stop executing the Selenium WebDriver Code for specified milliseconds will be explained in the next post.


No comments: