293. quit( ) - Selenium WebDriver method for closing the Test Browser window

quit( ) predefined method of Selenium 'WebDriver' Class is used to close the test browser window at the end of our Automation Test.


_driver.quit( );

Lets Implement This:

1. Open the specified URL using the Selenium WebDriver command get( ) as explained in our previous Post#14
2. Create a new method say tearDown( ) as shown below:

3. Specify the newly created tearDown( ) with @After JUnit annotation as shown below:

4. Observe that an error is displayed with the @After Annotation as shown below:

5. Resolve the error by importing the After Class from org.junit package as shown below:

6. Ensure that the selected import statement got added to the code and also the error got resolved as shown below:

7.  Inside the @After specified method, Type _driver object of Selenium 'WebDriver' Class and press dot '.' on your keyboard as shown below and ensure that the list of selenium WebDriver commands are displayed for selection:

8. Type 'quit' text after the dot to filter the displayed Selenium WebDriver predefined methods and select the 'quit( )' method option as shown below:

9. Ensure that the 'quit( )' method got added as shown below:

10. Add semicolon to the end of the statement as shown below:

11. Save and Run the Test using JUnit Test and observe that the URL specified in the above step got opened by the browser and at the end the opened browser got closed as shown below:

This is how the 'quit( )' predefined method of Selenium 'WebDriver' Class works.

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.

What are Locators ? will be explained in the next post.

No comments: