Compare commits

...

5 Commits

Author SHA1 Message Date
唐娇 739094e844 Fix Test File 2024-04-22 04:59:51 +08:00
唐娇 8d76133cca Merge branch 'Alpha-snapshot20230621' of http://118.25.96.118:3000/mrlan/EnglishPal into Bug528-TangJiao 2024-04-22 04:57:36 +08:00
Lan Hui 6dbb1e2c06 No webdriver manager 2024-04-21 15:40:35 +08:00
Lan Hui 8ef62395ed Revise README.md 2024-04-21 15:33:45 +08:00
Lan Hui 374da86174 Why not use PyPI's webdriver-manager? 2024-04-21 15:31:39 +08:00
3 changed files with 5 additions and 14 deletions

View File

@ -150,6 +150,8 @@ Run English Pal first, then run the test using pytest as follows: pytest --html=
The above command will generate a HTML report file pytest_report.html after finishing executing test_add_word.py. Note: you need to install pytest-html package first: pip install pytest-html.
You may also want to use [webdriver-manager](https://pypi.org/project/webdriver-manager/) from PyPI, so that you can avoid tediously installing a web driver executable manually. However, my experience shows that webdriver-manager is too slow. For example, it took me 16 minutes to run 9 tests, while with the pre-installed web driver executable, it took less than 2 minutes.
## TODO

View File

@ -2,6 +2,7 @@ import pytest
import sqlite3
import time
from selenium import webdriver
from pathlib import Path
@pytest.fixture
@ -11,7 +12,7 @@ def URL():
@pytest.fixture
def driver():
return webdriver.Edge() # uncomment this line if you wish to run the test on your laptop
return webdriver.Edge() # follow the "End-to-end testing" section in README.md to install the web driver executable
@pytest.fixture

View File

@ -6,18 +6,6 @@ from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
# 使用 Pytest 的 fixture 初始化 WebDriver 和 URL
@pytest.fixture(scope="module")
def driver():
# 初始化WebDriver
driver = webdriver.Edge(executable_path=r'D:\codeapp\python-3.8.5\Lib\site-packages\selenium\webdriver\edge\MicrosoftWebDriver.exe')
driver.implicitly_wait(10)
yield driver # yield 语句之后的代码在测试用例执行完毕后运行
driver.quit() # 测试用例执行完毕后关闭 WebDriver
@pytest.fixture(scope="module")
def URL():
return 'http://127.0.0.1:5000'
# 测试登录页面输入密码包含空格的情况
def test_login_password_with_space(driver, URL):
@ -44,7 +32,7 @@ def test_login_password_with_space(driver, URL):
assert "输入不能包含空格!" in alert.text
except (NoSuchElementException, TimeoutException) as e:
pytest.fail("页面元素未找到或超时: {}".format(e))
# 测试注册页面输入密码包含空格的情况