10 Most Useful Python Test Automation Tips


As a software testing services company, we encounter many test automation challenges. In this blog article, we would like to list a few useful Python Test Automation Tips, With the hope that you will bookmark this article for future references.

Installing PIP on Windows

Installing PIP on Windows is a simple task and an One-time activity. When you are setting up a test bed for test automation scripts execution, you need to recollect the steps to install PIP on Windows.

Step #1 – Download get-pip.py

Step #2 – Run get-pip.py


Virtual Environments on Windows

Installing, creating and activating a Python virtual environment is pretty straight forward. On the contrary, when you play around with multiple OS, you must be aware of the fact that there are different steps involved to activate a virtual environment on Windows.

Step #1 – Install virtual environment package

Step #2 – Create a virtual environment

Note: In the above command, newenv is the environment name.

Step #3 – Activate the virtual environment. Go to the virtual environment folder on Command Prompt, navigate to ‘scripts’ folder, and run ‘activate’ command.


Creating requirements.txt

Managing the required Python packages in requirements.txt is a best practice. If you have already installed the required packages and want to create requirements.txt, then run the below command.

Note: Once the command is executed successfully, it creates the requirements.txt with the list of installed packages.

Behave JSON Report Generation

If you are using behave BDD framework and would like to generate JSON report after automated script execution, then kick-off the behave execution using the below command.


Customized PDF Report Generation

Publishing readable and useful report is one of the important test automation success factors. You can create customized PDF report using behave JSON report. Refer the following URL for more details – Customized Test Automation PDF Report. You can create PDF report as shown below using pdf_reports package & Pug template.

Customized Test Automation PDF Report

Python Selenium Headless Chrome

Starting Chrome in headless mode using Selenium WebDriver can be done using ChromeOptions. Refer the below Python snippet.


Behave Teardown

In most of the BDD frameworks, you need to write setup and tear-down in two different methods. However, in behave framework, you can write both in one method. Refer the below snippet.


Network Throttling

In Selenium WebDriver, you can set network upload & download throughput and latency to run the automation testing scripts in different network conditions.


Desktop App Automation Testing

Using pywinauto package, you can automate Desktop App Test cases.


BuildBot CI

If you want to manage all CI related operations using Python code, you can try BuildBot CI.

In ConclusionAs an automation testing company, we use Python and Selenium WebDriver for multiple projects. We hope you have gained incredible insights about various test automation tips that’s has been shared in this blog article, As a continuing trend we will be keep sharing more and more useful automation testing related articles in the coming weeks.


Leave a Reply

Your email address will not be published. Required fields are marked *