LRR/testWithZayid/conftest.py

64 lines
1.7 KiB
Python

import os
import pytest
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import subprocess
import requests
import zipfile
import shutil
import platform
@pytest.fixture
def restore_database():
"""Restore the database.
It is useful for making sure that each end-to-end test
starts with the same database.
Benefit: we can reproduce the same test result.
"""
PASSWORD = "localMysql.87" # root password
# PASSWORD = "" # root password
DB_NAME = "lrr" # database name used for LRR
# commands used to import data to DB_NAME
cmds = [
f'mysql -u root -p{PASSWORD} -e "DROP DATABASE IF EXISTS {DB_NAME};"',
f'mysql -u root -p{PASSWORD} -e "CREATE DATABASE {DB_NAME};"',
f'mysql -u root -p{PASSWORD} -e "GRANT ALL PRIVILEGES ON {DB_NAME}.* TO lrr@localhost WITH GRANT OPTION;"',
f"mysql -u root -p{PASSWORD} {DB_NAME} < ../../lrr_database.sql", # the directory was not correct for me,so we added ../
]
# for command in cmds:
# os.system(command)
# return None
for command in cmds:
result = subprocess.run(command, shell=True)
if result.returncode != 0:
raise RuntimeError(f"Command failed: {command}")
@pytest.fixture
def url():
return "http://localhost:8081/LRR"
# return "http://localhost/LRR/" # URL of LRR
@pytest.fixture
def driver():
# install the latest version of ChromeDriver
# mirror web link: https://registry.npmmirror.com/chromedriver/
driver = webdriver.Chrome(ChromeDriverManager().install())
return driver
@pytest.fixture
def admin_username():
return "admin@qq.com"
@pytest.fixture
def admin_password():
return "123"