Working With Setup And Teardown


Advertisements

In this chapter, we will understand two important concepts of testing world − setup and teardown.<

Setup

This is a set of keywords or instruction to be executed before the start of test suite or test case execution.

Teardown

This is a set of keywords or instruction to be executed after the start of test suite or test case execution.

We will work on a project setup, where will use both setup and teardown. The opening and closing of browser are the common steps in test cases.

Now, we will add keyword open browser in the setup and close browser in teardown.

Open Ride using ride.py command from command line and create a new project.

Teardown

Click New Project to create project.

Create Teardown

Click OK to save the project.

Save Teardown

Click New Test Case to create one.

Test Case Teardown

Click OK to save the test case.

Now we need to import the SeleniumLibrary to use the keywords related to browser and interact with the pages.

To import the library, click Library −

Import library Teardown

Click library Teardown

Click OK to save the library.

Save library Teardown

In the above screenshot, the Settings section has Setup and Teardown options. For Setup, click Edit to enter the keyword.

Now, enter the Keyword −

Setup library Teardown

Arguments have to be separated with the pipe character (|).

pipe character

Click OK to save the Setup. We have entered the Keyword Open browser and also added the arguments as shown above.

Now, we will enter the teardown case.

Click Edit for Teardown and enter the keyword.

Edit Teardown

Click OK to save the teardown.

Now, we will enter the keywords for test case.

Keywords Teardown

We have only Input Text in the test case. The opening and closing of the browser is done from Setup and Teardown Settings.

Test Execution Details

Execution Teardown

Conclusion

Setup and teardown play a crucial role in the testing world. We have seen how to use setup and teardown in our test cases and also how they are executed.

Advertisements