【问题标题】:Selenium (python): How to execute methods in orderSelenium(python):如何按顺序执行方法
【发布时间】:2018-11-05 21:39:51
【问题描述】:

我有一个带有几个方法的 Selenium 类:

class MyTest(unittest.TestCase):
    cls.USER = 'user'
    cls.PASSWORD = 'password'
    cls.browser = Chrome()
    cls.browser.get('http...')

    def test_1(self):
    .....

    def test_2(self):
    .....

    def test3(self):
    .....

随着我添加更多方法,当我执行整个MyTest 类时首先调用的方法会发生变化。有时会首先调用方法test3,但如果我添加另一个方法,可能会首先调用test2。如何确保始终首先调用test_1

【问题讨论】:

标签: python selenium-webdriver functional-testing


【解决方案1】:

根据单元测试库的documentation

请注意,各种测试用例的运行顺序是 通过对测试函数名称进行排序来确定 字符串的内置排序

所以您只需要按字母顺序定义方法名称即可按顺序运行它们。只需将方法名称 test3() 更改为 test_3()

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    相关资源
    最近更新 更多