Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import os
- import pytest
- import time
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- import time
- @pytest.fixture(scope="session") # possibly, it should be "function" scope, but
- def driver(): # starting a new driver each time could be costly
- # setup
- options = webdriver.ChromeOptions()
- options.add_argument("--headless")
- options.add_argument('--no-sandbox')
- options.add_argument('--window-size=1420,1080')
- options.add_argument('--disable-gpu')
- _driver = webdriver.Chrome(options=options, executable_path='./chromedriver')
- # driver is ready to be used
- yield _driver
- # teardown
- _driver.quit()
- @pytest.fixture(scope="session")
- def server_starting():
- print('starting server')
- current_path = os.path.join(os.getcwd(), os.pardir)
- front_path = os.path.join(current_path, 'front-end')
- back_path = os.path.join(current_path, 'back-end')
- subprocess.call(['python3', 'manage.py', 'migrate'], cwd=back_path)
- print('migrations applied')
- front_start = subprocess.Popen(['npm', 'start'], cwd=front_path)
- back_start = subprocess.Popen(['python3', 'manage.py', 'runserver'], cwd=back_path)
- time.sleep(15.) # some extra time for servers to start
- yield "ok" # indication of started servers
- # teardown
- front_start.kill()
- back_start.kill()
- def test_login_page(server_starting, driver):
- """
- check that out page has "Alemira" as title
- """
- print(driver.current_url)
- driver.get("http://127.0.0.1:35000/login")
- with open('tmp', 'w') as fout:
- print("title", driver.title, file=fout)
- print('url', driver.current_url, file=fout)
- print("title", driver.title)
- assert "Alemira" in driver.title
- def test_01(server_starting, driver):
- driver.get("http://127.0.0.1:35000/login")
- with open('tmp', 'w') as fout:
- print("title", driver.title, file=fout)
- print('url', driver.current_url, file=fout)
- print(driver.current_url)
- input_field = driver.find_element_by_id('id_username')
- input_field.send_keys('Aglaya')
- input_field.send_keys(Keys.ENTER)
- time.sleep(2)
- input_field = driver.find_element_by_name('id_password')
- input_field.send_keys('12345')
- input_field.send_keys(Keys.ENTER)
- error = driver.find_element_by_class_name("alert")
- assert "please" in error.text.lower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement