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"

Share this