Selenium Tutorials with Python

Run tests in parallel with pytest

When we have a lot of test cases in our framework, it takes a lot of time to execute all the test cases.

Instead of running tests sequentially, or one after the other, parallel testing allows us to execute multiple tests at the same and decrease the time taken. Parallel testing helps to faster testing and has a quicker turn around in release process.

To run tests in parallel using pytest, we need pytest-xdist plugin which extends pytest with some unique test execution modes.

Grouping automation tests using Pytest.mark

Pytest allows to group tests using markers. pytest.mark decorator is used to mark a test function with custom metadata like @pytest.mark.smoke

This is very handy when we want to run only a subset of tests like "smoke tests" to quickly verify if the changes made by the developer not breaking any major functionalities.

You can mark a test function with custom metadata like below:

WebDriver tests in PyTest using Fixtures and

Fixtures are a powerful feature of PyTest. Fixtures help us to setup some pre-conditions like setup a database connection / get test data from files etc that should run before any tests are executed. Earlier we have seen Fixtures and Scope of fixtures, In this article, will focus more on using fixtures with

Using Fixtures in Pytest

You might have heard of the setup method and teardown methods in Unittest [In java, there are similar methods available in TestNG/JUnit]. In pytest, we have fixtures which simplifies the workflow of writing setup and teardown code. Fixtures have explicit names and are activated by declaring them in test functions, modules, classes or whole projects.

Pytest introduction

Pytest is a Python testing tool. It is an open source testing tool used for testing all types of software’s. Internet is shifted from unittest or nose to pytest because it provides powerful features.

"pytest is a framework that makes building simple and scalable tests easy" - Pytest

Installing pytest

Locating elements in selenium python

To interact with any web page using selenium, you need to first find webelement/s to perform any action on element.

All the actions you do on a webpage like entering a text into a textbox or textarea and after filling out the form, you may want to click the button to submit data. There are many other operations we do like mousehover, selecting a value from dropdown and navigating between multiple windows/frames which we will discuss more in detail in coming tutorials.

First Example on how to use Selenium with Python

Selenium.webdriver module provides all the WebDriver implementations. WebDriver offers a multiple ways to find element/ find elements using one of the find_element_by_* methods.

Webdriver offers more than one way to locate the elements of your web application in order to find the elements. You can find elements by using ID, name, XPath, CSS Selectors, and more. Know more on Locators for Selenium

Getting started with Selenium Webdriver in Python

Python is a object-oriented programming which has simple syntax, making it the easy for someone trying to learn programming. Writing programs in Python both fun and easy.

Selenium automates browsers. Selenium is an open source library which can used to perform testing web applications. Selenium works multiple browsers Chrome, Firefox, IE, Edge, Safari etc.

To start with Selenium Webdriver Python tutorial, lets install Python and Selenium before starting.