我用Python / Selenium / OpenPyxl编写了一个程序,该程序需要从电子表格中登录并插入网站。这不是正式的作业,我只是想尝试使用网上找到的一些练习来教自己(尽管在Java中没有Python)。
我想编写单元测试来检查我的测试,但仅了解基于在线研究的基本单元测试。寻找有关如何为此测试编写适当的单元测试的指南。
我有一个模块-该模块有以下模块
我的理解是我需要
def setupClass(cls):测试电子表格中的每一行凭据
一个def tearDown(self):为每行凭证关闭每个测试
我需要有关如何针对If / Else条件进行单元测试的指南
在单元测试中如何应用“尝试/例外”条件的指导
如果您可以指导我,那就太好了。我无法看到它
#loop through each row of spreadsheet and enter the username and password in login for each row
for r in range(2, rows+1):
username = spreadsheet.readData(path, "Sheet1", r, 1)
password = spreadsheet.readData(path, "Sheet1", r, 2)
login.enter_username(username)
login.enter_password(password)
login.click_login()
#If login if not successful then accept alert, if login is successful press back button to return to login page
try:
alert = driver.switch_to.alert
alert.accept()
except NoAlertPresentException:
driver.execute_script("window.history.go(-1)")
#If login is successful and goes to next page then pass test and populate spreadsheet. If login is not successful then update spreadsheet with fail result
if driver.current_url == "http://www.demo.guru99.com/V4/manager/Managerhomepage.php" :
print("test is passed")
spreadsheet.writeData(path, "Sheet1", r, 3, "test passed")
else:
print("test failed")
spreadsheet.writeData(path, "Sheet1", r, 3, "test failed")
#below is where i' looking for guideance.
Class Test_LoginTest(unittest.TestCase):
@classmethod
def setupClass(cls):
new_url = "http://www.demo.guru99.com/V4/manager/Managerhomepage.php"
def tearDown(self):
print('teardownClass')
def test_login_valid(self):
self.assertEqual()
我想我需要
assertert等于成功登录进入下一页
断言登录失败会发出警报
我需要断言Excel电子表格更新正确吗? (我不知道该怎么做)
4。是否需要对try / except起作用进行单元测试?