Integrating automation suite with Azure pipeline

 Azure DevOps provides features like version control, requirement management, testing, automated builds, etc. The entire product life cycle can be covered using its DevOps services. In this tutorial, we're talking about the integration of an automation suite with Azure Pipeline

Azure Pipelines allow you to automatically run builds, perform tests, and release the artifacts to the required environments. Azure Pipelines is created in the form of YAML files and it has stages of every action like download the code, build it, deploy it, run automation suites and publish the results 

We've created an automation suite for this post and which is available in GitHub. The automation suite which is written in Python. In this repository, you can find the YAML file which is named as smoketest-pipeline.yml. Let's have a look into each stage

The first stage is used for declaring the variables, in which root directory and url are supplied

The second stage is talking about pulling the code from repositories 

The next stage is about machine details in which the pipeline should run. Users can specify the operating system type and other configurations. Since it is a Python project, Python version has specified

The fourth stage, installing the required packages for the automation suite

The last stage, running the automation suite

This is about the structure of YAML file and let's look into its execution part. Navigate to Azure Devops and select the Pipeline from your repository then Run it. You can see its status of each stage 

This is a simple YAML file and there are different stages available that should definitely meet your needs.   

Learn Pytest for free - Step by step tutorial for beginners

Pytest is a testing framework based on Python. Python is very flexible to test any kind of services like web, database, API, cloud, etc. This tutorial gives a basic idea about pytest, write test scripts and integration with other services. This tutorial intended for beginners and they will get the basic idea to start the high-level tasks. This package contains 5 steps and try to complete it in a series manner. Selenium integration also included in the tutorial. Happy learning !!!

Step 1 - pytest installation

Step 2 - Create the first pytest script

Step 3 - pytest rules and features

Step 4 - Creating the first script using Selenium

Step 5 - Validating the first test 

Selenium with Pytest - Validating the first test

In the previous post, you've created the first script. Let's see how we can validate a test. Please see below test case to automate it

1. Launch the
2. Make sure that testodev loaded successfully
3. Ensure that "Privacy Policy" present in the header

Using selenium, we can identify the web objects using different method such as id, xpath, classname etc. We can use any convenient method. As mentioned in the pytest rules, all test must have an assert to validate the output. The script is given below
import pytest
from selenium import webdriver
from import Options

options = Options()
driver = webdriver.Chrome(
    options=options, executable_path=r".\\chromedriver\\chromedriver.exe")

#Test 1 - Validating the testodev launch
def test_ValidateTestodev():
    assert "" in driver.current_url, "testodev failed to load"

#Test 2 - Validating the privacy policy text
def test_ValidatePrivacyPolicy():
    txtValidate = driver.find_element_by_class_name(
    assert txtValidate == "Privacy Policy", "Privacy Policy text validation failed"

Creating the first script using Selenium with Pytest

Selenium is one of the topmost tool used for web automation. You can download the selenium package and interact with the applications using web drivers. Selenium package available here and can be download using pip command

pip install selenium  

Selenium requires a driver to interface with the chosen browser. Chrome, for example, requires chromedriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH

Yes, you've completed the required installation. Now we can write a simple script to launch the testodev.
import pytest
from selenium import webdriver
from import Options

options = Options()
driver = webdriver.Chrome(
    options=options, executable_path=r".\\chromedriver\\chromedriver.exe")
You run the script via command line using the command pytest <script name> 
The script launches the testodev via chromedriver. 

Pytest - Rules and Features

In the previous post, we've learned about creating the first script using pytest framework. This post will discuss the rules and features

1. Header - All pytest script should include import pytest at header of the script 
2. File naming - pytest only identifies the file names starting with test_ or ending with _test as the test files
3. Method naming - All pytest methods should start with test_
4. Assertions in PyTest - Assertions are used for validating the test conditions. Assertions are checks that return either True or False status. if an assertion fails in a test method, then that method execution is stopped there. The remaining code in that test method is not executed, and pytest will continue with the next test method.
assert "tree" == "tree" is a successful assertion.
assert 10==3 is a assertion failure
assert True is a successful assertion
assert False is an assertion failure.
assert "orange" == "apple" is a assertion failure.
These are basic rules to validate the application with pytest framework. pytest also supports parallel execution, annotation etc, which testodev will cover in the later posts