Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import configparser
import os
import time
import pytest
from import By
from import expected_conditions as EC
from import WebDriverWait
from selenium import webdriver
# Sample project to show how selenium and pytest work together
@pytest.fixture # This runs before every test as a pre-condition. It's result is an object which is used in every test below.
def dr():
dr.driver = webdriver.Chrome()
dr.wait = WebDriverWait(dr.driver, 10)
dr.config = configparser.ConfigParser(), 'spotify.config'))
dr.baseURL = dr.config.get("url", "baseURL") = dr.config.get("music", "band")
return dr
# Happy path: search for a band
def test_search_band(dr):
search_button = dr.wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[5]/div[1]/nav/div[1]/ul/li[2]/div/a/div/span')))
search_input = dr.wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[5]/div[2]/div/section/div[1]/div/div/input')))
result=dr.wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[5]/div[2]/div/section/div[2]/div/div/div[1]/div[2]/section/section/ol/div[1]/div/li/div[2]/div/div[2]/span[1]/span/span/a')))
assert in result.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.