Setup and Teardown
Often while writing tests you have some setup work that needs to happen before tests run, and you have some finishing work that needs to happen after tests run. Flood Element provides helper functions to handle this.
#
Setup#
beforeAll()Some setups need to be done before the main test begins, as a pre-condition. For example, you are going to test a web app, and in order to perform the main steps, you need to be authenticated first. In that case, you can do the authentication within beforeAll()
.
#
beforeEach()For the setup that needs to be repeated before each step, you can put it inside beforeEach()
#
Teardown#
afterEach()Sometimes, to avoid trash data while testing on production environment, you need to do the cleaning after each step. In that case, use afterEach()
.
#
afterAll()After the main steps have finished, you may want to do the final cleaning work, or simply just log out to kill the session. afterAll()
is a good choice for this.
#
Order of executionAs long as before*
and after*
handlers are put inside the default test suite, they will be executed in the following order, regardless of where you put them inside the suite:
beforeAll()
beforeEach()
- Your test
step()
afterEach()
afterAll()
Take the following code snippet as an example:
The output of the above code should be:
info
In case you have more than 1 beforeAll()
in your test script, they will be executed sequentially from top to down. Similarly for beforeEach()
, afterEach()
and afterAll()
.