我已经阅读了各种教程和 Stack Overflow 帖子,并了解 Selenium 可以输出 XML 测试结果,Hudson 可以以 HTML 格式读取/报告它们。
我不明白的是 Python 中使用的语法,使结果看起来像这样: Testcase_LoginPage.VerifyButton1Present 失败
Testcase_LoginPage.VerifyButton2Present 通过
目前,当我深入 Hudson 中的结果时,它们不会按照我上面描述的那样以有用的方式进行格式化,而且它还会报告它只运行了一个测试,即使它运行了多个断言测试:
回溯(最近一次调用最后一次): 文件“D:\Temp\1TestingApps\Selenium\Scripts\SampleScripts\SamCodeSample\test\SOreports.py”,第22行,在tearDown中 self.assertEqual([], self.verificationErrors) AssertionError:列表不同:[] != ['注册按钮问题2']
第二个列表包含 1 个附加元素。 第一个额外元素 0: 注册按钮问题2
- []
- [“注册按钮问题2”]
在 13.610 秒内运行 1 次测试
失败(错误=1)
正在生成 XML 报告...
代码如下。预先感谢您的帮助!
从 Selenium 导入 Selenium 导入unittest、xmlrunner、os、re
类演示(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "https://workflowy.com/")
self.selenium.start()
def test_hh(self):
sel = self.selenium
sel.open("/accounts/register/")
try: self.assertEqual("Sign Up FAIL", "Sign Up FAIL","Sign Up button issue1")
except AssertionError, e: self.verificationErrors.append(str(e))
try: self.assertEqual("Sign Up FAIL", "Sign Up FAIL1","Sign Up button issue2")
except AssertionError, e: self.verificationErrors.append(str(e))
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
#have to format the code this way as SO is complaining about 'bad indent'
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))
最佳答案
您只定义了一项测试,因此它只能报告一项测试。一个测试是一种测试方法,而不是断言语句。您可以在一个测试中进行多个断言,因为您可能需要断言多个结果才能确认成功的测试结果。
因此,获得所需输出的第一步是将第二个断言放入第二个测试方法中,然后您应该看到两个测试结果。
关于python - 适用于 Hudson/jenkins 的验证的 Selenium 语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7654729/