The Sauce Labs Cookbook

Sauce Headless

Front End Performance Testing

Insights

External Resources

More Info


Page tree
Skip to end of metadata
Go to start of metadata

These examples use the pytest test framework to run tests on real devices. Feel free to clone these scripts directly from GitHub, and follow the instructions in the README file.

Python Config

This script initializes the test fixtures, as well as the prerequisite and post-requisite test tasks.

 conftest.py

Not found

Could not read the file selenium-examples/pytest/emusim/conftest.py

Test Objects

These scripts represents the individual test. Click below to see the script(s):

 test_add_to_cart.py

import pytest


def test_add_to_cart(emusim_driver):
    emusim_driver.get('https://www.saucedemo.com/inventory.html')
    emusim_driver.find_element_by_class_name('btn_primary').click()

    assert emusim_driver.find_element_by_class_name('shopping_cart_badge').text == '1'

    emusim_driver.get('https://www.saucedemo.com/cart.html')
    expected = emusim_driver.find_elements_by_class_name('inventory_item_name')
    assert len(expected) == 1

def test_add_two_to_cart(emusim_driver):
    emusim_driver.get('https://www.saucedemo.com/inventory.html')
    emusim_driver.find_element_by_class_name('btn_primary').click()
    emusim_driver.find_element_by_class_name('btn_primary').click()

    assert emusim_driver.find_element_by_class_name('shopping_cart_badge').text == '2'

    emusim_driver.get('https://www.saucedemo.com/cart.html')
    expected = emusim_driver.find_elements_by_class_name('inventory_item_name')
    assert len(expected) == 2

 test_login_fail.py

import pytest


def test_valid_crentials_login(emusim_driver):
    emusim_driver.get('https://www.saucedemo.com')

    emusim_driver.find_element_by_id('user-name').send_keys('locked_out_user')
    emusim_driver.find_element_by_id('password').send_keys('secret_sauce')
    emusim_driver.find_element_by_css_selector('.btn_action').click()

    assert emusim_driver.find_element_by_css_selector('.error-button').is_displayed()

 test_login_success.py

import pytest


def test_valid_crentials_login(emusim_driver):
    emusim_driver.get('https://www.saucedemo.com')

    emusim_driver.find_element_by_id('user-name').send_keys('standard_user')
    emusim_driver.find_element_by_id('password').send_keys('secret_sauce')
    emusim_driver.find_element_by_css_selector('.btn_action').click()

    assert "/inventory.html" in emusim_driver.current_url

Python Config

This script initializes the test fixtures, as well as the prerequisite and post-requisite test tasks.

 conftest.py

Not found

Could not read the file appium-examples/pytest/rdc/ios/conftest.py

Test Objects

These scripts represents the individual tests. Click below to see the script:

 test_invalid_login.py

import pytest


def test_blank_credentials(ios_driver):
    ios_driver.find_element_by_accessibility_id("test-Username").send_keys("")
    ios_driver.find_element_by_accessibility_id("test-Password").send_keys("")
    ios_driver.find_element_by_accessibility_id("test-LOGIN").click()

    assert ios_driver.find_element_by_accessibility_id("test-Error message").is_displayed()

 test_valid_login.py

import pytest
from time import sleep


def test_standard_user(ios_driver):
    sleep(5)
    ios_driver.find_element_by_accessibility_id("test-Username").send_keys("standard_user")
    ios_driver.find_element_by_accessibility_id("test-Password").send_keys("secret_sauce")
    ios_driver.find_element_by_accessibility_id("test-LOGIN").click()

    assert ios_driver.find_element_by_accessibility_id("test-PRODUCTS").is_displayed()