...
The initial code you were given was a sample piece of the code showing you the Selenium capabilities. But in order to use Selenium in a testing environment, you will need to structure your code as follows
Each file containing the tests should follow one of the these formats
test_<file_name>.py
<file_name>_test.py
The file should comprise of tests. Tests following follow the standard as defined my by pytest, see this link https://docs.pytest.org/en/reorganize-docs/new-docs/user/assert_statements.html
A test method should begin test_<method_name>()
...
We originally supplied you with the following piece of code
...
Notice we put any intialisation code in something called setup(). This is so we can reuse this code across multiple tests.
To run the above code use the following command
Code Block | ||
---|---|---|
| ||
pytest <file_name>.py |
We then place the rest of the code in a method called test_some)functionality(). we could have split this up further into two separate tests as shown here
...
Notice how we have cleaned up the code. The functions setup() and aftertfunction call setup() at line 47. because the code above is all function definitions, they don’t get called until setup() has been called because the code is executed sequentially.
If we put this code in a file called test_demo_selenium.py. It could be executed by simply typing pytest