密码正确的会通过,密码错误报错
import unittest
from selenium import webdriver
from time import sleep
from pages.first_page import FirstPage
from pages.login_page import LoginPage
from ddt import ddt,data
from xlrd import open_workbook
def getexcel():
excelFile = open_workbook('d:/data.xlsx')
sheet = excelFile.sheet_by_index(0)
rowNuber = sheet.nrows
data_list = []
for i in range(1,rowNuber):
data_list.append(sheet.row_values(i))
return data_list
@ddt
class TestTravel(unittest.TestCase):
def setUp(self):
self.dr = webdriver.Chrome()
self.dr.maximize_window()
self.dr.implicitly_wait(10)
@data(*getexcel())
def test_login_ddt(self,data):
username,password = tuple(data)
firstpage = FirstPage(driver=self.dr,path='http://django.t.mukewang.com/')
loginpage = LoginPage(driver=self.dr)
firstpage.cross_to_login()
sleep(2)
loginpage.login(username,password)
def tearDown(self):
self.dr.quit()
if __name__ == '__main__':
unittest.main()
C:\Users\王八蛋\PycharmProjects\travel_test\venv\Scripts\python.exe "D:\PyCharm Community Edition 2020.2.3\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --target test_travel_ddt.TestTravel
Testing started at 20:55 ...
Launching unittests with arguments python -m unittest test_travel_ddt.TestTravel in C:\Users\王八蛋\PycharmProjects\travel_test
Ran 2 tests in 36.406s
FAILED (errors=1)
Error
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\unittest\case.py", line 60, in testPartExecutor
yield
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\unittest\case.py", line 676, in run
self._callTestMethod(testMethod)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\unittest\case.py", line 633, in _callTestMethod
method()
File "C:\Users\王八蛋\PycharmProjects\travel_test\venv\lib\site-packages\ddt.py", line 182, in wrapper
return func(self, *args, **kwargs)
File "C:\Users\王八蛋\PycharmProjects\travel_test\test_travel_ddt.py", line 33, in test_login_ddt
loginpage.login(username,password)
File "C:\Users\王八蛋\PycharmProjects\travel_test\pages\login_page.py", line 25, in login
self.back_to_firstpage().click()
File "C:\Users\王八蛋\PycharmProjects\travel_test\pages\login_page.py", line 19, in back_to_firstpage
return self.by_xpath('//*[@id="app"]/div[1]/div[5]/div[1]')
File "C:\Users\王八蛋\PycharmProjects\travel_test\pages\base_page.py", line 16, in by_xpath
return self.driver.find_element_by_xpath(xpath)
File "C:\Users\王八蛋\PycharmProjects\travel_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\王八蛋\PycharmProjects\travel_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\王八蛋\PycharmProjects\travel_test\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\王八蛋\PycharmProjects\travel_test\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="app"]/div[1]/div[5]/div[1]"}
(Session info: chrome=89.0.4389.114)
Assertion failed
Process finished with exit code 1
Assertion failed
Assertion failed
14
收起
正在回答 回答被采纳积分+1
1回答
Python全栈工程师2020
- 参与学习 人
- 提交作业 5211 份
- 解答问题 2433 个
Facebook曾声称“只招全栈工程师”!全栈用人需求猛增,市面人才紧缺。 0基础进击Python全栈开发,诱人薪资在前方!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星