上传文件至 app/test

pull/109/head
lixiaofeng 2024-05-20 20:47:33 +08:00
parent d3d7b87e62
commit 024a1dbb61
1 changed files with 30 additions and 45 deletions

View File

@ -1,54 +1,39 @@
import pytest
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.action_chains import ActionChains
import time from helper import signup
from webdriver_manager.chrome import ChromeDriverManager
@pytest.fixture
def driver():
# 初始化浏览器驱动
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
yield driver def test_highlight(driver, URL):
# 测试结束后关闭浏览器 try:
driver.quit() # 打开网页
driver.get(URL)
driver.maximize_window()
def test_highlight(driver): # 注册
# 打开网页 signup(URL, driver)
driver.get("http://127.0.0.1:5000/")
# login # 取消勾选“划词入库按钮”
elem = driver.find_element_by_link_text('登录') highlight_checkbox = driver.find_element_by_id("test1")
elem.click() driver.execute_script("arguments[0].click();", highlight_checkbox)
uname = 'lxf'
password = 'kklo567'
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') # 找到登录按钮 article = driver.find_element_by_id("article")
elem.click()
# 取消勾选“划词入库按钮” # 创建 ActionChains 对象
highlight_checkbox = driver.find_element_by_id("test1") actions = ActionChains(driver)
driver.execute_script("arguments[0].click();", highlight_checkbox)
article = driver.find_element_by_id("article") # 移动鼠标到起点位置
actions.move_to_element(article)
# actions.move_to_element_with_offset(article, 50, 100)
# 按下鼠标左键
actions.click_and_hold()
# 拖动鼠标到结束位置
actions.move_by_offset(400,50)
# 释放鼠标左键
actions.release()
# 执行操作链
actions.perform()
# time.sleep(10)
# 创建 ActionChains 对象 assert driver.find_element_by_tag_name("mark") is not None
actions = ActionChains(driver) finally:
# 测试结束后关闭浏览器
# 移动鼠标到起点位置 driver.quit()
actions.move_to_element(article)
# actions.move_to_element_with_offset(article, 50, 100)
# 按下鼠标左键
actions.click_and_hold()
# 拖动鼠标到结束位置
actions.move_by_offset(400,50)
# 释放鼠标左键
actions.release()
# 执行操作链
actions.perform()
time.sleep(10)