Created
March 13, 2019 14:32
-
-
Save besucherke/f828df85e71df8d118a5342d2496e19e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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