Google+

389. Understanding how close( ) and quit( ) commands work when only one window is opened






In our previous post, we've seen how close( ) and quit( ) WebDriver commands work when more than one Browser window is opened by the Automation code.

Now lets see how close( ) and quit( ) WebDriver commands work when only one Browser is opened by the  Automation code.

As per my explanation in our previous post, close( ) and quit( ) WebDriver commands will work in the same way when only one Browser window is opened by the Automation code. Lets prove this statement by implementing it on Eclipse IDE.

Lets Implement the Test on Eclipse IDE:

Pre-requisites:

1. Create a new Project say 'WebDriver-Project34' in Eclipse IDE
2. Configure the Project to work with Selenium WebDriver
3. Create a package say 'package34' under the newly created project.
4. Create a Java Class file say 'Class34' under the newly created package as shown below:



Actual Steps:

1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:



2. Write a test method which opens the Home Page of a website as shown below:


3. Now write @AfterClass specified method as shown below:


4. Write Selenium Automation code for closing the Browser window using close( ) WebDriver command as shown below:


5. Save and Run the 'Class34.java' file using JUnit Test and observe that one Browser window got opened by the Selenium Automation code and close( ) WebDriver command has closed it as shown in the below video:

Watch the below video:

Click here to watch the video.

Download this Project:


Click here to download this project and import into Eclipse IDE  on your machine.

6. Now lets replace the close( ) with quit( ) WebDriver command as shown below:



7. Save and Run the 'Class34.java' file using JUnit Test and observe that one Browser window got opened by the Selenium Automation code and quit( ) WebDriver command has closed it as shown in the below video:

Watch the below video:

Click here to watch the video.

Download this Project:


Click here to download this project and import into Eclipse IDE  on your machine.

From the above steps it is very clear that, when the automation code opens a single browser window, both WebDriver commands i.e. close( ) and quit( ) work in the same way. 




Please comment below to feedback or ask questions.


Try this if close( ) WebDriver command is not closing the Browser window   will be explained in the next post.



No comments:

Followers :)

Blog Index