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 https://www.testodev.com/
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 selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('start-maximized')
driver = webdriver.Chrome(
    options=options, executable_path=r".\\chromedriver\\chromedriver.exe")
driver.get("https://www.testodev.com/")

#Test 1 - Validating the testodev launch
def test_ValidateTestodev():
    assert "https://www.testodev.com/" 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(
        'privacy').get_attribute("innerHTML")
    assert txtValidate == "Privacy Policy", "Privacy Policy text validation failed"
Previous Post Next Post