-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
66 lines (58 loc) · 2.85 KB
/
conftest.py
File metadata and controls
66 lines (58 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import time
import pytest
import yaml
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
_BASE_URL = 'https://msi-c2-cms.fooyo.shop/#/login'
email = 'huyang@fooyo.sg'
psd = '11111111'
__ENG = (By.CSS_SELECTOR, '[class="login__language__text"]')
__USERNAMR = (By.CSS_SELECTOR,'[placeholder="Please Input The Email"]')
__PASSWORD = (By.CSS_SELECTOR, '[placeholder="Please Input The Password"]')
__BTN_LOGIN = (By.CSS_SELECTOR, '[class="el-button login-btn el-button--primary el-button--small"]')
@pytest.fixture(scope='session')
def login():
global driver
driver = webdriver.Chrome()
driver.get('https://msi-c2-cms.fooyo.shop')
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located(__ENG))
driver.find_element(By.CSS_SELECTOR, '[class="login__language__text"]').click()
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located(__USERNAMR))
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located(__PASSWORD))
driver.find_element(By.CSS_SELECTOR, '[placeholder="Please Input The Email"]').send_keys(email)
driver.find_element(By.CSS_SELECTOR, '[placeholder="Please Input The Password"]').send_keys(psd)
driver.find_element(By.CSS_SELECTOR,
'[class="el-button login-btn el-button--primary el-button--small"]').click()
time.sleep(5)
# 获取 Session Storage 只需将 localStorage 修改为 sessionStorage,修改获取的值为 token_bk 即可
user = driver.execute_script("return localStorage.getItem('user')")
# print(user)
with open('../Data/user.yaml', "w") as f:
# 第一个参数是要写入的数据,第二个字段是要进行数据操作的资源文件
yaml.safe_dump(user, f)
# print("保存成功")
yield driver
driver.quit()
@pytest.fixture(scope='session')
def local_storage():
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options)
# driver = webdriver.Chrome()
driver.implicitly_wait(60)
driver.get('https://msi-c2-cms.fooyo.shop')
WebDriverWait(driver, 30).until(expected_conditions.visibility_of_element_located(__ENG))
driver.find_element(By.CSS_SELECTOR, '[class="login__language__text"]').click()
# 定义cookie,从文件中获取
user = yaml.safe_load(open('../Data/user.yaml'))
# print(user)
# self.driver.execute_script('return window.localStorage.setItem("token", "value");')
driver.execute_script(f'localStorage.setItem("user", {[user]});')
# 再次访问
driver.get('https://msi-c2-cms.fooyo.shop')
time.sleep(5)
yield driver