Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import configparser
import os
import time
import pytest
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui 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()
dr.config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'spotify.config'))
dr.baseURL = dr.config.get("url", "baseURL")
dr.band = dr.config.get("music", "band")
dr.driver.get(dr.baseURL)
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_button.click()
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')))
search_input.click()
search_input.send_keys(dr.band)
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 dr.band in result.text
time.sleep(3)
dr.driver.quit()
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.