上传文件至 app/test
parent
ea7c2ff9e7
commit
b33d6a77f7
|
@ -1,49 +1,28 @@
|
||||||
import pytest
|
|
||||||
from selenium import webdriver
|
|
||||||
from selenium.webdriver.common.action_chains import ActionChains
|
from selenium.webdriver.common.action_chains import ActionChains
|
||||||
import time
|
import time
|
||||||
from webdriver_manager.chrome import ChromeDriverManager
|
from helper import signup
|
||||||
|
|
||||||
@pytest.fixture
|
def test_highlight(driver, URL):
|
||||||
def driver():
|
try:
|
||||||
# 初始化浏览器驱动
|
# 打开网页
|
||||||
driver = webdriver.Chrome(ChromeDriverManager().install())
|
|
||||||
driver.maximize_window()
|
driver.maximize_window()
|
||||||
|
driver.get(URL)
|
||||||
|
|
||||||
yield driver
|
# 注册
|
||||||
|
time.sleep(1)
|
||||||
|
signup(URL, driver)
|
||||||
|
time.sleep(2)
|
||||||
|
|
||||||
|
# 选中单词(移动鼠标到起点位置、按下鼠标左键、拖动鼠标到结束位置、释放鼠标左键、执行操作链)
|
||||||
|
article = driver.find_element_by_id("article")
|
||||||
|
actions = ActionChains(driver)
|
||||||
|
actions.move_to_element(article).click_and_hold().move_by_offset(450,60).release().perform()
|
||||||
|
|
||||||
|
# 判断所有高亮单词是否有间隔
|
||||||
|
marks = driver.find_elements_by_tag_name("mark")
|
||||||
|
for mark in marks:
|
||||||
|
assert mark.value_of_css_property("padding") == '0px'
|
||||||
|
finally:
|
||||||
# 测试结束后关闭浏览器
|
# 测试结束后关闭浏览器
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
|
||||||
def test_highlight(driver):
|
|
||||||
# 打开网页
|
|
||||||
driver.get("http://127.0.0.1:5000/")
|
|
||||||
|
|
||||||
# login
|
|
||||||
elem = driver.find_element_by_link_text('登录')
|
|
||||||
elem.click()
|
|
||||||
uname = 'xshh'
|
|
||||||
password = 'kk123ll'
|
|
||||||
elem = driver.find_element_by_id('username')
|
|
||||||
elem.send_keys(uname)
|
|
||||||
elem = driver.find_element_by_id('password')
|
|
||||||
elem.send_keys(password)
|
|
||||||
|
|
||||||
elem = driver.find_element_by_class_name('btn') # 找到登录按钮
|
|
||||||
elem.click()
|
|
||||||
|
|
||||||
article = driver.find_element_by_id("article")
|
|
||||||
|
|
||||||
# 创建 ActionChains 对象
|
|
||||||
actions = ActionChains(driver)
|
|
||||||
|
|
||||||
# 移动鼠标到起点位置
|
|
||||||
actions.move_to_element(article)
|
|
||||||
# 按下鼠标左键
|
|
||||||
actions.click_and_hold()
|
|
||||||
# 拖动鼠标到结束位置
|
|
||||||
actions.move_by_offset(450,60)
|
|
||||||
# 释放鼠标左键
|
|
||||||
actions.release()
|
|
||||||
# 执行操作链
|
|
||||||
actions.perform()
|
|
||||||
time.sleep(15)
|
|
||||||
|
|
Loading…
Reference in New Issue