18. Using getEval( ) to re-size the browser window





As there is no direct command or predefined method in Selenium RC to re-size the browser window, we've to use getEval( ) Selenium RC predefined method which uses the JavaScript to perform few operations as shown below:

Syntax: getEval("JavaScript Code Here");

Example: getEval("alert("Hi")") -> This one will give alert message with text "Hi" while executing.

Here in this example you have to understand two things. i.e getEval( ) is a selenium RC predefined method where as alert("Hi") is the JavaScript code.

But we are in requirement of a JavaScript code which re-size our browser window. window.resizeTo(X,Y) is the JavaScript code to re-size the window. Here X and Y are height and width. Lets use this code with Selenium RC predefined method getEval( ) as shown below:

Example getEval("window.resizeTo(600,700)") -> This will re-size the browser window to 600 pixels width and 700 pixels height.

Lets Implement This:

1. Start the Selenium RC Driver as explained in our previous Post#14
2. Open the URL using the Selenium RC command as explained in our previous Post#15
3. Maximize the browser window having the opened URL using the Selenium RC command as explained in our previous Post#16
4. Re-size the maximized browser window in previous step to 600 pixels width and 700 pixels height by writing the getEval("window.resizeTo(600,700)");  into the Selenium RC code as shown below:


5. Save and Run the Selenium RC Code using JUnit and observe that the Browser window got re-sized to 600 pixels width and 700 pixels height as shown below:



Watch the Video on how the getEval("window.resizeTo(x,y)") command re-sizes the Test Browser Window:

Click here to watch the Video

6. But the execution was too fast. As a result we wont be able to clearly view when the window got maximized and then when it got re-sized properly. In order to view the execution steps with some delay, lets add Thread.sleep(3000) statements between the commands as shown below:



7. Save and Run the written Selenium RC code with JUnit. To understand how the Test has Run this time, watch the below video:

Watch the Video on how the getEval("window.resizeTo(x,y)") command re-sizes the Test Browser Window after adding few Thread.sleep( ) statements between the selenium commands:

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 close( ) to close the test browser window will be explained in the next post.



No comments:

Post a Comment

Followers

Labels