SELENIUM BASICS:

  • What is Automation Testing - Advantages & Types of Tools
  • What is Selenium IDE, Selenium RC, Selenium WebDriver, Selenium Grid?
  • Selenium IDE, Firebug & Firepath Installation

  • SELENIUM WEBDRIVER:

  • Selenium WebDriver Architecture
  • Selenium Installation
  • Challenges and Limitations of Selenium
  • First Selenium WebDriver Script
  • Working with Firefox Browser
  • Solution - Failed To Launch Browser Using Selenium WebDriver
  • Working with Chrome Browser
  • Working with IE Browser
  • Difference Between FindElement & FindElements
  • Install Firebug, Fire path and other add on for Selenium
  • Locators in Selenium
  • Dynamic Xpath
  • Dynamic CSS
  • Handle drop-downs
  • How to work with file upload
  • Handle Alerts & Popups
  • Handle Multiple Windows
  • Mouse Hover event in Selenium
  • Right Click
  • Double Click
  • Drag and Drop
  • Capture Screenshots in Selenium
  • Parameterization
  • Synchronization
  • Implicit Wait, Explicit Wait and Fluent Wait in Selenium
  • Implicit Waits
  • Explicit WebDriver Waits
  • Fluent Wait In Selenium
  • Apache POI
  • How To Read Data From Excel File
  • How To Write Data In Excel File
  • Database Testing Using MSSQL
  • Database Testing Using MySQL
  • Database Testing Using DB2
  • Handle Ajax Call in Selenium
  • Listeners in Selenium
  • Handling JavaScript in Selenium
  • Stale Element Reference Exception in Selenium
  • Integrate Sikuli with Selenium
  • Headless Browser Testing 
  • Headless Browser Testing using HtmlUnitDriver
  • Headless Browser Testing using PhanthomJSDriver

  • TESTNG:

  • TestNG Installation
  • TestNG Complete Tutorial

  • REPORTS:

  • Extent Reports Introduction
  • Extent Reports Generation
  • Capturing Screenshots & Including In Extent Reports
  • Extent Reports Version 4

  • BUILD & CONTINUOUS INTEGRATION TOOLS:

  • ANT Build Tool - How To Download & Install
  • Maven Build Tool - How To Download & Install
  • Creating Maven Selenium Project
  • GIT Integration with Selenium
  • Jenkins - How To Download & Install
  • Jenkins - Executing TestNG Scripts
  • Jenkins - Generating Reports After Test Execution
  • Jenkins - Executing Maven Project
  • Create build and Execute build for nightly execution
  • Send Email report based on build Status
  • Selenium Continuous Integration with Jenkins [Selenium – Maven – Git – Jenkins] – Step By Step Guide

  • CROSS BROWSER TESTING:

  • Running Selenium Tests On BrowserStack
  • Kobiton - Mobile Testing Platform with Real Devices

  • MOBILE TESTING:

  • Mobile Testing Platform with Real Devices

  • AUTOMATION FRAMEWORKS:

  • What is Framework & Types of Framework
  • Page Object Model Design Pattern
  • Data Driven Framework
  • How to explain Test Automation Framework or Selenium Automation Framework Architecture In Interview

  • API Testing:

  • Learn API Testing
  • Postman Tutorial (API Testing with Postman)

  • INTERVIEW QUESTIONS:

  • Test Automation Framework Interview Questions
  • Selenium Interview Questions
  • TestNG Interview Questions
  • Java Interview Questions
  • Python Interview Questions
  • API Testing Interview Questions

  • SAMPLE RESUME:

  • Automation Tester Resume
  • Assertions in Selenium Python

    In the previous articles on Selenium Python Tutorial, we have covered “How To Handle Mouse & Keyboard Interactions in Selenium Python“. In this tutorial, we will learn Assertions in Selenium Python. 

    In automation testing, the pass and failure test of a test case is determined by the checkpoints or validation points in our tests. Often people may use conditional statements like if-else or switch statements, to conclude a result. However, these statements do not bear any report generating features.

    Assertions are the checkpoints in a test case, which help us to conclude on test results and report generation of the test results. There are multiple assertions available, let us discuss some of them.

    assertEqual () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If both the values are the same, the execution continues with a pass result. In case they do not match, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertNotEqual () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If both the values are not the same, the execution continues with a pass result. In case they match, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertTrue () – This type of assertion can have more than two parameters. It checks if a parameter returns true or false. If true value is returned, the execution continues with a pass result. In case false value is returned, the test case fails. We can compare relational operators with this assertion. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertFalse () – This type of assertion can have more than two parameters. It checks if a parameter returns true or false. If a false value is returned, the execution continues with a pass result. In case true value is returned, the test case fails. We can compare relational operators with this assertion. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertIs () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If both are the same, the execution continues with a pass result. In case they are not the same, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertIsNot () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If both are not the same, the execution continues with a pass result. In case they are the same, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertIsNone () – This type of assertion can have two parameters. The first parameter in this assertion is checked to see if it yields none. If the result is found to be none, the execution continues with the past result. In case it is not none, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    In the above scenario, r is tested to see if it is none, if yes it shall give a pass result.

    assertIsNotNone () – This type of assertion can have two parameters. The first parameter in this assertion is checked to see if it does not yield none. If the result is found to be not none, the execution continues with the pass result. In case it is none, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    In the above scenario, r is tested to see if it is not none, if yes it shall give a pass result.

    assertIn () – This type of assertion can have three parameters. The first parameter in this assertion is checked to see if it subsists in the second parameter. If the result is found to be true, the execution continues with a pass result, otherwise, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertNotIn () – This type of assertion can have three parameters. The first parameter in this assertion is checked to see if it subsists in the second parameter. If the result is found to be false, the execution continues with a pass result, otherwise, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertIsInstance () – This type of assertion can have three parameters. The first parameter in this assertion refers to an object. The second parameter in this assertion refers to a class. This assertion verifies if the object is an instance of the second parameter class. If yes, the execution continues with a pass result, otherwise, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertNotIsInstance () – This type of assertion can have three parameters. The first parameter in this assertion refers to an object. The second parameter in this assertion refers to a class. This assertion verifies if the object is an instance of the second parameter class. If no, the execution continues with a pass result, otherwise, the test case fails. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result. Let us now discuss some of the assertions available for Collections.

    assertListEqual () – This type of assertion can have three parameters. The first and second parameter represents two lists. In this assertion, comparison is done between these two lists. If they are found to be similar, the execution continues with a pass result. If not, an error message is thrown that highlights the differences between them. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a fail result as two lists are not equal.

    assertTupleEqual () – This type of assertion can have three parameters. The first and second parameter represents two tuples. In this assertion, comparison is done between these two tuples. If they are found to be similar, the execution continues with a pass result. If not, an error message is thrown that highlights the differences between them. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result as two tuples are equal.

    assertSetEqual () – This type of assertion can have three parameters. The first and second parameter represents two sets. In this assertion, comparison is done between these two sets. If they are found to be similar, the execution continues with a pass result. If not, an error message is thrown that highlights the differences between them. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result if sets s1 and s2 are equal.

    assertDictEqual () – This type of assertion can have three parameters. The first and second parameter represents two dictionaries. In this assertion, comparison is done between these two dictionaries. If they are found to be similar, the execution continues with a pass result. If not, an error message is thrown that highlights the differences between them. The last parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a fail result as two dictionaries are not equal.

    Let us now discuss some of the comparison assertions available.

    assertAlmostEqual () – This type of assertion can have five parameters. The first parameter in this assertion compares its value with the second parameter. If they are equal roughly, the execution continues with a passing result. In case they are not, the test case fails. The computation is done by calculating the differences between the two then rounding to the number of decimal places as specified in the third parameter called place. The default place value is 7.

    The penultimate parameter in this assertion is optional and is included to produce a message. If the last parameter called delta [optional parameter] is mentioned instead of place, then the differences between the first and second parameter should be less than equal to the delta. The default delta value is 0.

    Syntax:

    The above scenario shall give a fail result as two parameters are not roughly equal.

    assertNotAlmostEqual () – This type of assertion can have five parameters. The first parameter in this assertion compares its value with the second parameter. If they are not equal roughly, the execution continues with a passing result. In case they are roughly equal, the test case fails. The computation is done by calculating the differences between the two then rounding to the number of decimal places as specified in the third parameter called place and then comparing to 0. The default place value is 7.

    The penultimate parameter in this assertion is optional and is included to produce a message. If the last parameter called delta [optional parameter] is mentioned instead of place, then the differences between the first and second parameter should be less than equal to the delta. The default delta value is 0.

    Syntax:

    The above scenario shall give a pass result as two parameters are not roughly equal.

    assertGreater () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If the first parameter is greater than the second, the execution continues with a pass result. In case the second parameter is greater, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertGreaterEqual () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If the first parameter is greater than equal to the second, the execution continues with a pass result. If not, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertLess () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If the first parameter is lesser than the second, the execution continues with a pass result. In case the second parameter is lesser, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a failed result.

    assertLessEqual () – This type of assertion can have three parameters. The first parameter in this assertion compares its value with the second parameter. If the first parameter is less than equal to the second, the execution continues with a pass result. If not, the test case fails. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a failed result.

    assertRegexpMatches () – This type of assertion can have three parameters. The second parameter in this assertion [a regular expression object or a string] searches itself within the first parameter text. If the search is successful, the execution continues with a pass result. If not, an error message is thrown with the pattern and the original text. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a pass result.

    assertNotRegexpMatches () – This type of assertion can have three parameters. The second parameter in this assertion [a regular expression object or a string] searches itself within the first parameter text. If the search is unsuccessful, the execution continues with a pass result. If not, an error message is thrown with the pattern and the section of the text that matches. The third parameter in this assertion is optional and is included to produce a message.

    Syntax:

    The above scenario shall give a fail result as the regular expression Python is present in the original text Python Test.

    In the next article, we will learn Exceptions in Selenium Python

    Related posts:

    Get our latest blog posts delivered to your inbox

    Subscribe and get popular blog posts about software testing industry.

    Rajkumar

    Leave a Comment

    Share via
    Copy link
    Powered by Social Snap