In this blog, we are working on how to run a single test in the Pytest file.
As a pre-requisite we have to check whether the following dependencies or installed or not:
- Project setup.
- Run pip list in PyCharm terminal to check whether playwright is installed or not.
As shown in the above picture playwright should be installed in the project.
If the playwright is not installed refer to Web Automation Testing using Playwright.
What is Pytest?
Pytest is the python testing framework, which allows the user to write the python programming language for Web and API Automation. Using Pytest we can maintain the test cases in a systematic way.
Advantages of Pytest:
- Can run tests in parallel.
- Can run a specific test or a subset of tests
- Can run the test suite.
- Automatically detect tests
- Skip tests
- Automatically generate the reports.
Playwright supports the Pytest Framework. We can use the same Pytest command for both Sync and Async API.
To install Pytest we have to run the following command in the terminal.
After the Successful installation of Pytest run pip list in terminal to check whether the Pytest is installed successfully or not.
File Naming Convention:
After the successful installation of Pytest to run a single Pytest file, we have to follow the following syntax for file and function naming:
- The test script file name should be either saved by test_ at the beginning of the test script file name or _test at the end of the test script file name.
- The function name in the test script should begin with test_ then only Pytest will consider it for execution.
To Run Single File:
To run the single test script in Pytest we have to pass the file name in the terminal.
Pytest file name
Step 1: – Launch the Browser.
Step 2: – Navigate to https://www.google.com
Step 3: – Fill the text in the input box as welcome to close ops in playwright.
Step 4: – Close the page and browser.
To run the above script in Pytest we have to run the following command in the terminal.
The command will run the test script name as test_run_single.py.
Read the next Playwright blog Here.