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.
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
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
2. Let's add test code to webdriver_setup.py
Steps to Create Test Script
2. Let's add come in test_linkedin.py
Steps to Run the Test file
领英推荐
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.
2. Let's customize pytest.ini by configuration settings
Steps to Installation of Docker on Windows OS
notepad 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
docker build -t linkedin-tests .
docker run -v %cd%:/app linkedin-tests
Generating Test Report
pip install pytest-html
pytest --html=report.html
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