Optimize tests with Setup & Teardown methods

In this post, we will learn how we can use SeleniumBase Setup & Teardown methods to optimize our tests even further. If you are not familiar with setup & teardown concepts, essentially, it allows you to run certain steps before and after your a…


This content originally appeared on DEV Community and was authored by Automation Bro

In this post, we will learn how we can use SeleniumBase Setup & Teardown methods to optimize our tests even further. If you are not familiar with setup & teardown concepts, essentially, it allows you to run certain steps before and after your actual test.

So, when you run the Setup method, it will trigger the steps BEFORE your test will run and the TearDown will run the steps AFTER your test has finished.

Setup Method

The setup method will run the steps before each of your tests. Let’s take a look at the sample code below –

setup code

Typically, you would use your setup method for any repetitive code between your tests such as opening the page, test data creation, or log in.

TearDown method

The tearDown method will run the steps after each of your tests has finished running. Let’s take a look at the sample code below –

teardown code

Typically, you would use the tearDown method for actions such as taking screenshots after the test has finished running, logging some data, or for Logout.

Check out the video below to learn more about the Setup & TearDown methods using Selenium Python –

? Subscribe to my mailing list to get access to more content like this

? Follow automationbro on Twitter for the latest updates

...

This post was written with the help of a high amount of caffeine. And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and continue supporting my caffeine love :)

Buy me a coffee

You can also support me by liking and sharing this content.

Thanks for reading!


This content originally appeared on DEV Community and was authored by Automation Bro


Print Share Comment Cite Upload Translate
APA
Automation Bro | Sciencx (2022-12-09T06:09:26+00:00) » Optimize tests with Setup & Teardown methods. Retrieved from https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/.
MLA
" » Optimize tests with Setup & Teardown methods." Automation Bro | Sciencx - Sunday February 7, 2021, https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/
HARVARD
Automation Bro | Sciencx Sunday February 7, 2021 » Optimize tests with Setup & Teardown methods., viewed 2022-12-09T06:09:26+00:00,<https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/>
VANCOUVER
Automation Bro | Sciencx - » Optimize tests with Setup & Teardown methods. [Internet]. [Accessed 2022-12-09T06:09:26+00:00]. Available from: https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/
CHICAGO
" » Optimize tests with Setup & Teardown methods." Automation Bro | Sciencx - Accessed 2022-12-09T06:09:26+00:00. https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/
IEEE
" » Optimize tests with Setup & Teardown methods." Automation Bro | Sciencx [Online]. Available: https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/. [Accessed: 2022-12-09T06:09:26+00:00]
rf:citation
» Optimize tests with Setup & Teardown methods | Automation Bro | Sciencx | https://www.scien.cx/2021/02/07/optimize-tests-with-setup-teardown-methods/ | 2022-12-09T06:09:26+00:00
https://github.com/addpipe/simple-recorderjs-demo