Fix Bug553
parent
b7fe68c54d
commit
768c81828d
|
@ -10,9 +10,8 @@ from selenium.webdriver.common.by import By
|
|||
from webdriver_manager.chrome import ChromeDriverManager
|
||||
from selenium.webdriver.common.keys import Keys
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import pytest
|
||||
|
||||
# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
|
||||
# HOME_PAGE = 'http://121.4.94.30:91/'
|
||||
|
@ -25,19 +24,9 @@ HOME_PAGE = 'http://127.0.0.1:5000/'
|
|||
driver.implicitly_wait(10)
|
||||
|
||||
|
||||
# 加载存有测试数据的json文件
|
||||
def load_json_file(file_path):
|
||||
# 获取当前所在文件的目录
|
||||
dir_path = os.path.dirname(os.path.abspath(__file__))
|
||||
# 将目录路径和文件名进行拼接,获取最终的文件路径
|
||||
file_path = dir_path+"\\"+file_path
|
||||
# 加载文件
|
||||
with open(file_path,encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
|
||||
|
||||
def test_bug553_LinShan():
|
||||
@pytest.mark.parametrize("test_input",("‘test1’","'test2'","“test3”","it's","hello,I'm linshan","Happy New Year!?","My favorite book is 《Harry Potter》。"))
|
||||
@pytest.mark.parametrize("expected",(["test1"],["test2"],["test3"],["it's"],["hello","i'm","linshan"],["happy","new","year"],["potter","harry","my","favorite","book","is"]))
|
||||
def test_bug553_LinShan(test_input,expected):
|
||||
try:
|
||||
# 打开对应地址的网页
|
||||
driver.get(HOME_PAGE)
|
||||
|
@ -48,14 +37,9 @@ def test_bug553_LinShan():
|
|||
# 判断网页源代码中是否有English Pal -文字
|
||||
assert 'English Pal -' in driver.page_source
|
||||
|
||||
# 获取json格式的测试数据
|
||||
words = load_json_file("test_file.json")
|
||||
|
||||
# 遍历测试的数据
|
||||
for word in words:
|
||||
# 将测试的数据输入到主页的textarea里
|
||||
driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
|
||||
driver.find_element_by_xpath("//textarea[@name='content']").send_keys(word['key'])
|
||||
driver.find_element_by_xpath("//textarea[@name='content']").send_keys(test_input)
|
||||
time.sleep(2)
|
||||
|
||||
# 点击按钮获取单词
|
||||
|
@ -63,19 +47,20 @@ def test_bug553_LinShan():
|
|||
time.sleep(2)
|
||||
|
||||
# 获取筛选后的单词
|
||||
get_words = driver.find_elements_by_xpath("//p/a")
|
||||
words = driver.find_elements_by_xpath("//p/a")
|
||||
|
||||
# 遍历获取到的单词,并判断单词与预期的相同
|
||||
for w in get_words:
|
||||
for word in words:
|
||||
# 判断单词是否在预期结果中
|
||||
assert w.text in word['value']
|
||||
assert word.text in expected
|
||||
|
||||
# 返回上一页网页
|
||||
driver.find_element_by_xpath("//input[@value='确定并返回']").click()
|
||||
time.sleep(2)
|
||||
|
||||
except Exception as e:
|
||||
# 输出异常信息
|
||||
logging.error(e)
|
||||
finally:
|
||||
# 关闭浏览器
|
||||
finally:
|
||||
driver.quit()
|
Loading…
Reference in New Issue