Bug528-TangJiao #103

Merged
tangjiao merged 10 commits from Bug528-TangJiao into Alpha-snapshot20230621 2024-05-05 21:27:39 +08:00
4 changed files with 107 additions and 0 deletions

View File

@ -15,6 +15,10 @@
alert('输入不能为空!');
return false;
}
if (password.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
$.post(
"/login", {'username': username, 'password': password},
function (response) {

View File

@ -12,6 +12,10 @@
alert('输入不能为空!');
return false;
}
if (old_password.includes(' ') || new_password.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
if (new_password !== re_new_password) {
alert('新密码不匹配,请重新输入');
return false;

View File

@ -16,6 +16,10 @@ You're logged in already! <a href="/logout">Logout</a>.
alert('输入不能为空!');
return false;
}
if (password.includes(' ') || password2.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
if (password !== password2) {
alert('确认密码与输入密码不一致!');
return false;

View File

@ -0,0 +1,95 @@
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
# 测试登录页面输入密码包含空格的情况
def test_login_password_with_space(driver, URL):
try:
driver.get(URL+"/login")

@tangjiao

  • 这个路径 'D:\codeapp\python-3.8.5\Lib\site-packages\selenium\webdriver\edge\MicrosoftWebDriver.exe' 会导致你的测试脚本无法在别人的电脑上运行,因为别人没有这个路径。如何设置 PATH 变量,请参考 README.md 中的 End-to-end testing 那节。

  • 不需要额外定义 driver 这个 fixture,在 contest.py 中已有定义。

@tangjiao - 这个路径 'D:\codeapp\python-3.8.5\Lib\site-packages\selenium\webdriver\edge\MicrosoftWebDriver.exe' 会导致你的测试脚本无法在别人的电脑上运行,因为别人没有这个路径。如何设置 PATH 变量,请参考 README.md 中的 [End-to-end testing](http://118.25.96.118:3000/mrlan/EnglishPal/src/branch/Alpha-snapshot20230621/README.md#end-to-end-testing) 那节。 - 不需要额外定义 driver 这个 fixture,在 contest.py 中已有定义。
# 输入用户名
username_elem = driver.find_element_by_id('username')
username_elem.send_keys("test_user")
# 输入包含空格的密码
password_elem = driver.find_element_by_id('password')
password_elem.send_keys("password with space")
# 提交登录表单
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
elem.click()
# 显式等待直到警告框出现
WebDriverWait(driver, 10).until(EC.alert_is_present())
# 检查是否弹出警告框
alert = driver.switch_to.alert
assert "输入不能包含空格!" in alert.text
except (NoSuchElementException, TimeoutException) as e:
pytest.fail("页面元素未找到或超时: {}".format(e))
# 测试注册页面输入密码包含空格的情况
def test_signup_password_with_space(driver, URL):
try:
driver.get(URL+"/signup")
# 输入用户名
username_elem = driver.find_element_by_id('username')
username_elem.send_keys("new_user")
# 输入包含空格的密码
password_elem = driver.find_element_by_id('password')
password_elem.send_keys("password with space")
# 再次输入密码
password2_elem = driver.find_element_by_id('password2')
password2_elem.send_keys("password with space")
# 提交注册表单
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
elem.click()
# 显式等待直到警告框出现
WebDriverWait(driver, 10).until(EC.alert_is_present())
# 检查是否弹出警告框
alert = driver.switch_to.alert
assert "输入不能包含空格!" in alert.text
except (NoSuchElementException, TimeoutException) as e:
pytest.fail("页面元素未找到或超时: {}".format(e))
# 测试重设密码页面输入新密码包含空格的情况
def test_reset_password_with_space(driver, URL):
try:
driver.get(URL+"/reset")
# 输入用户名
username_elem = driver.find_element_by_id('username')
username_elem.send_keys("test_user")
# 输入包含空格的密码
password_elem = driver.find_element_by_id('password')
password_elem.send_keys("password with space")
# 提交重设密码表单
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
elem.click()
# 显式等待直到警告框出现
WebDriverWait(driver, 10).until(EC.alert_is_present())
# 检查是否弹出警告框
alert = driver.switch_to.alert
assert "输入不能包含空格!" in alert.text
except (NoSuchElementException, TimeoutException) as e:
pytest.fail("页面元素未找到或超时: {}".format(e))