最奇怪的事情是: 我从一个模块运行一个程序,这个模块从另一个模块调用一些函数。 问题是,相同的代码在使用基本函数时可以完美运行,但第三个函数只有在unittest类内部使用时才会失败,消息如下:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="app_skeleton"]/tbody/tr[6]/td/form/table/tbody/tr[2]/td/table/tbody/tr[2]/td[9]/a"}.
以下是完整的课程:
from Main_Package.General_Functions.Functions import
login,search_by_customer_id,add_subscriber_iden_and_activate,browser
class FirstTest(unittest.TestCase):
@staticmethod
def test_login():
login()
@staticmethod
def test_search_by_customer_id():
search_by_customer_id()
@staticmethod
def test_add_subscriber_iden_and_activate():
add_subscriber_iden_and_activate()
#login() ******this is the block of code that will run perfectly without #
****
#search_by_customer_id()
#add_subscriber_iden_and_activate()
if __name__ == '__main__':
unittest.main()
当您执行单元测试时,您必须确保特定的测试已经准备好“环境”来执行测试。你知道吗
测试的执行不正常,因此:
可以在
如果要在每个测试之前和之后执行某些内容,可以使用方法
setUp()
和tearDown()
;如果要在所有测试之前和之后执行某些内容,可以使用方法setUpClass()
和tearDownClass()
。你知道吗Here文档。你知道吗
相关问题 更多 >
编程相关推荐