PyTest Framework on Windows OS

PyTest Framework on Windows OS

Creating automation scripts using PyTest Framework on Windows OS. Let’s us LinkedIn website for our automation framework and basic test script. Below is the outline of our approach.

  1. Development Environment Setup
  2. Directory Structure
  3. WebDriver Setup
  4. Basic Test using PyTest
  5. Customize PyTest Settings
  6. Install and Implement Dockers
  7. Generating Test Reports


Step by Step Guideline for Installation

Environment Setup

Installation of Python


Installation of PIP and check version from command prompt

Installation of Pytest, Selenium and WebDriver manager from command prompt

Step by Step Guideline for creating directory structure for PyTest framework

  1. Let’s open command prompt on your PC
  2. Lets create a main Project Directory

3. Let's create a Sub Directories for Testing and Configuration

4. Let's create a _init_.py files and initialize it.

Steps to Create WebDriver Setup

  1. Let’s create a file webdriver_setup.py in side utils directory

2. Let's add test code to webdriver_setup.py

Steps to Create Test Script

  1. Let’s create a file test_linkedin.py

2. Let's add come in test_linkedin.py

Steps to Run the Test file

  1. Let’s navigate to the project directory linkedin_automation

2. Run test file linkedin_automation in pytest


Directories and Files structure


Customize PyTest Settings

To customize PyTest settings we need to create a file pytest.ini in the root directory.

  1. Let's create pytest.ini file

2. Let's customize pytest.ini by configuration settings


Steps to Installation of Docker on Windows OS

  • Let's download and Install Dockers desktop from Dockers website and fellow the instruction given in the installation document.
  • Let's verify if dockers is installed properly from command prompt.

  • Let's create a file named Dockerfile inside the Project Directory and open in with notepad

notepad Dockerfile        

  • Let's add following content to the Dockerfile

# Use an official Python runtime as a parent image 
FROM python:3.9-slim
# Set the working directory in the container
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Install Chrome and ChromeDriver
RUN apt-get update && apt-get install -y \
wget \
gnupg \
unzip && \
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb https://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
apt-get update && apt-get install -y \
google-chrome-stable && \
wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.com/91.0.4472.101/chromedriver_linux64.zip && \
unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ && \
rm /tmp/chromedriver.zip
# Make port 80 available to the world outside this container
EXPOSE 80
# Run tests
CMD ["pytest", "--html=report.html"]         

Steps to Build and Run Docker Image

  • Let's go to command prompt and run it

docker build -t linkedin-tests .        
docker run -v %cd%:/app linkedin-tests        

Generating Test Report

  • Install pytest-html plugin to generate HTML reports.

pip install pytest-html        

  • Let's run test to generate reports

pytest --html=report.html        

Shirissh N Bet

Sr Product Consultant (Polyworking)

9 个月

This is just a basic framework. I will keep on adding and updating this post. Coming Up will be other Python frameworks keep checking my posts and please share your feedbacks

要查看或添加评论,请登录

Shirissh N Bet的更多文章

社区洞察

其他会员也浏览了