Selenium Testing: Running First Pytest Script

Selenium Testing: Running First Pytest Script hackernoon.com2 years ago in #Dev Love33

Selenium as we know, is an open-source test suite used for cross-platform browser automation. Due to its popularity and ease of use, many compatible test frameworks with respect to different programming languages have been developed to extends support of Selenium for cross browser testing over multiple programming languages. Today we’re going to look into Selenium Python tutorial to run our first automation script using PyUnit framework with Selenium. PyUnit is a unit testing framework which is derived from JUnit for compatible execution of Selenium with Python language. PyUnit is a very popular testing framework to perform ‘Unit Testing’ – a mechanism to validate a particular piece of functionality in a module. The popularity of PyUnit as a Python specific unit testing framework has been a major reason for including PyUnit as an official Python module from version 2.5. The Python UnitTest library referred to as unittest is widely used to perform Selenium Python Testing. We will leverage the unittest library in this Selenium Python tutorial. Building Blocks Of Python Unit Test [PyUnit] Framework Let’s start the Selenium Python tutorial by understanding the building blocks of PyUnit framework. The unittest framework contains the following core-modules that are core to test case development & execution: Test Loader: The Test Loader Python class is used to load test cases and test suites. It is also termed as ‘Test Fixture’. Test Cases and Test Suite can be created locally or can be loaded from an external file/database. On successful execution, Test Suite object is released by the Test Loader and the same object can be used throughout the execution of the Test Case. Test Runner: Responsible for displaying the output of the executed test to an end user using a runnable interface. The output could be represented in a variety of ways. It could be displayed as a standard code, in the form of GUI or through a textual representation. Test Suite: Test Suite is a group of test cases that are ‘grouped logically’ based on the functionalities that are under test. Test suites are used for making the test code more modular & maintainable. Test Case: Test Case contains the actual implementation of the test code. In case some functionality is not ready, a developer can make use of Stubs i.e. dummy source code to test source code at a unit level. Test Report: Test Reports are ideally used to organize the results of test case execution i.e. whether test case execution result is pass/fail. It also details the time taken for execution, execution summary, etc. Better the maintenance of test report, easier it extracts useful information from it. TestCase class is used to create new tests and the FunctionTestCase acts as a subclass to TestCase class and make use of tests which are appended to the existing unittest framework. setUp() and tearDown() are important components of the TestCase class that are used for initialization & cleanup of the test fixture (that was created using setUp()). The primary purpose of using FunctionTestCase class is to aid the goal of code reusability. PyUnit/unittest Overview PyUnit also referred as unittest and works in a similar manner as xUnit which is a very popular unit testing framework whose structure & functionality is derived from Smalltalk’s SUnit. Hence, a developer who has prior experience with xUnit or other popular unit testing frameworks would find unittest easier to understand. Testcase/Testsuite written using unittest module follows a common format Define a class derived from unittest.TestCase().  » Read More

Like to keep reading?

This article first appeared on If you'd like to keep reading, follow the white rabbit.

View Full Article

Leave a Reply