1
0
Fork 0
Bug555-chenshiying
陳詩穎 2024-06-25 01:57:59 +08:00
parent bb838ad51a
commit aa8d8b75e0
1 changed files with 43 additions and 34 deletions

View File

@ -1,34 +1,43 @@
import pytest import time
from selenium import webdriver import pytest
from selenium.webdriver.common.by import By import uuid
from selenium.webdriver.support.ui import WebDriverWait from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver import ActionChains
from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
@pytest.fixture() from selenium.webdriver.support import expected_conditions as EC
def driver(): from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException, NoSuchElementException, \
# 初始化Chrome WebDriver TimeoutException
driver = webdriver.Chrome() from conftest import URL
driver.maximize_window() driver = webdriver.Chrome()
yield driver def test_bug555():
# 测试结束后关闭浏览器 try:
driver.quit() driver.maximize_window()
base_url = "http://127.0.0.1:5000"
def test_bug555(driver): driver.get(base_url)
base_url = "http://127.0.0.1:5000" article = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'article')))
driver.get(base_url) perform_actions_on_article(driver, article)
# 定位文章元素并对其执行操作 next_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_next_article')))
article = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'article'))) next_button.click()
ActionChains(driver).move_to_element(article).click_and_hold().move_by_offset(450, 200).release().perform() print("Clicked next article button.")
print("Performed actions on article.")
prev_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article')))
# 导航到下一篇文章 prev_button.click()
next_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_next_article'))) print("Clicked previous article button.")
next_button.click()
print("Clicked next article button.") except (TimeoutException, NoSuchElementException) as e:
print(f"An error occurred: {e}")
# 返回上一篇文章
prev_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article'))) finally:
prev_button.click() driver.quit()
print("Clicked previous article button.") print("Driver closed.")
def perform_actions_on_article(driver, article):
actions = ActionChains(driver)
actions.move_to_element(article)
actions.click_and_hold()
actions.move_by_offset(450, 200)
actions.release()
actions.perform()
print("Performed actions on article.")