Advertisement
Guest User

tests

a guest
Apr 8th, 2020
1,394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. import subprocess
  2. import os
  3. import pytest
  4. import time
  5. from selenium import webdriver
  6. from selenium.webdriver.common.keys import Keys
  7. import time
  8.  
  9.  
  10. @pytest.fixture(scope="session")  # possibly, it should be "function" scope, but
  11. def driver():                     # starting a new driver each time could be costly
  12.     # setup
  13.  
  14.     options = webdriver.ChromeOptions()
  15.     options.add_argument("--headless")
  16.     options.add_argument('--no-sandbox')
  17.     options.add_argument('--window-size=1420,1080')
  18.     options.add_argument('--disable-gpu')
  19.     _driver = webdriver.Chrome(options=options, executable_path='./chromedriver')
  20.  
  21.     # driver is ready to be used
  22.     yield _driver
  23.  
  24.     # teardown
  25.     _driver.quit()
  26.  
  27.  
  28. @pytest.fixture(scope="session")
  29. def server_starting():
  30.  
  31.     print('starting server')
  32.     current_path = os.path.join(os.getcwd(), os.pardir)
  33.     front_path = os.path.join(current_path, 'front-end')
  34.  
  35.     back_path = os.path.join(current_path, 'back-end')
  36.  
  37.     subprocess.call(['python3', 'manage.py', 'migrate'], cwd=back_path)
  38.     print('migrations applied')
  39.     front_start = subprocess.Popen(['npm', 'start'], cwd=front_path)
  40.     back_start = subprocess.Popen(['python3', 'manage.py', 'runserver'], cwd=back_path)
  41.     time.sleep(15.)  # some extra time for servers to start
  42.  
  43.     yield "ok"  # indication of started servers
  44.  
  45.     # teardown
  46.  
  47.     front_start.kill()
  48.     back_start.kill()
  49.  
  50.  
  51.  
  52. def test_login_page(server_starting, driver):
  53.     """
  54.    check that out page has "Alemira" as title
  55.    """
  56.     print(driver.current_url)
  57.     driver.get("http://127.0.0.1:35000/login")
  58.     print("title", driver.title)
  59.     assert "Alemira" in driver.title
  60.  
  61.  
  62. def test_01(server_starting, driver):
  63.     driver.get("http://127.0.0.1:35000/login")
  64.     print(driver.current_url)
  65.     input_field = driver.find_element_by_id('id_username')
  66.     input_field.send_keys('Aglaya')
  67.     input_field.send_keys(Keys.ENTER)
  68.  
  69.     time.sleep(2)
  70.  
  71.     input_field = driver.find_element_by_name('id_password')
  72.     input_field.send_keys('12345')
  73.     input_field.send_keys(Keys.ENTER)
  74.  
  75.     error = driver.find_element_by_class_name("alert")
  76.     assert "please" in error.text.lower()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement