#11 Playwright with Python | PyTest framework with Playwright Part 1
New Section
In this section, the video introduces the topic of test framework development and covers the installation process for a specific plugin called "playwright" for pytest.
Installing the Plugin
- To convert a plain Python file into a pytest script, it is necessary to install the "playwright" plugin.
- The "playwright" plugin is maintained by Microsoft and can be installed using pip.
- Installation command:
pip install playwright
- After installing the plugin, several packages will be downloaded as dependencies.
- Checking installed packages: Use
pip listto see the newly installed packages.
Generating Pytest Scripts Automatically
- Playwright has a feature that allows generating pytest scripts automatically.
- This feature is accessed through Playwright Inspector, which provides a Python script but not specifically a pytest script.
- Upgrading Playwright to version 1.22 enables support for generating pytest tests.
- Upgrading Playwright: Use
pip install -u playwrightto upgrade to version 1.22.
Reinstalling Browser Binaries
- After upgrading Playwright, it is necessary to reinstall browser binaries due to potential compatibility issues with previous versions.
- Reinstalling browser binaries ensures that drivers are updated accordingly.
- Reinstalling browser binaries: Use
playwright installto download and reinstall the latest browser binaries.
The transcript provided does not include timestamps for some sections.
Selecting the Script Language
The speaker explains how to select the language for generating the script using Playwright's code generator.
Selecting the Script Language
- By default, Python is selected as the target language for generating the script.
- The speaker demonstrates selecting different languages such as Java and JavaScript.
- They mention wanting to generate the script in PyTest framework, which reduces the code to just three lines.
- Actions are performed, such as entering a username and clicking on login and logout buttons.
- The auto-generated PyTest script is copied.
Creating a Package and Python File
The speaker explains how to create a package and a Python file for the PyTest script.
Creating a Package and Python File
- A package named "bytest" is created for PyTest framework.
- A Python file named "my_test_script.py" or "my_test_script.py" is created within the package.
- The speaker mentions making a mistake with naming conventions but will rectify it later.
Executing the PyTest Script
The speaker demonstrates executing the PyTest script using command line or terminal.
Executing the PyTest Script
- The command
pytestis used to execute the PyTest script from the command line or terminal.
- Initially, no test is executed due to naming convention issues. The file/module name should start with "test_" keyword.
- After renaming/refactoring, running
pytestexecutes the test successfully with one passed test case.
- To execute in headed mode instead of headless mode, use
--headedflag. Additional flags like-scan be used for output printing.
Understanding Assertions and Running the Script
The speaker explains assertions in PyTest scripts and runs the modified script.
Understanding Assertions and Running the Script
- The speaker mentions auto-generated assertions in the PyTest script.
- They uncomment a print statement for output printing.
- The modified script is executed, and the browser opens, completes the test, and closes.
- The test completion message is displayed due to passing
-sflag.
Recap and Next Steps
The speaker provides a recap of the video content and discusses future plans.
Recap and Next Steps
- The video demonstrates how to generate a PyTest script using Playwright's code generator.
- Naming conventions for files/modules (starting with "test_") and classes (starting with capital "Test") are important in PyTest.
- Future videos will cover converting an existing test to a PyTest script, creating fixtures, and explaining the usage of
pageobject.
Understanding the Script
In this section, the speaker discusses the importance and benefits of understanding a script.
Importance of Understanding the Script
- The speaker emphasizes that understanding the script is crucial.
- It allows for better comprehension and delivery of the content.
- Understanding the script helps in conveying the intended message effectively.
Benefits of Understanding the Script
- When you understand the script, it becomes easier to connect with your audience.
- It enables improvisation and adaptation during presentations or performances.
- Understanding the script enhances confidence and reduces anxiety.
Conclusion
Understanding a script is essential for effective communication. It improves comprehension, delivery, connection with the audience, and allows for improvisation.