如何使用python,selenium动态生成测试

时间:2019-01-14 17:51:26

标签: python selenium testing dynamic

我需要在20个站点上测试重置密码,我可以动态生成此tet,不想创建20种测试方法吗? 我试图以此为例,但是How do you generate dynamic (parameterized) unit tests in python?

无效
class TestSequense(unittest.TestCase):
    pass

def test_generator(site, form):
    def test(self):
        option = webdriver.ChromeOptions()
        option.add_argument("headless")
        option.add_argument("--window-size=1920,1080")
        driver = webdriver.Chrome(options=option)
        driver.implicitly_wait(30)
        reset_password_1 = ResetPasswordFirstForm(driver)
        if '1' in form:
            reset_password_1.get_customer_link(site)
            reset_password_1.wait_page_to_load(site)
            reset_password_1.go_to_reset_password()
            reset_password_1.set_email(reset_password['email'], site)
            reset_password_1.submit_form()
            reset_password_1.wait_for_popup(site)
    return test


if __name__ == '__main__':
    for site, form in all_sites.items():
        test_name = 'test_' + str(site)
        test = test_generator(site, form)
        setattr(TestSequense, test_name, test)

    unittest.main()

它说我的测试服是空的

Ran 0 tests in 0.000s

OK

Process finished with exit code 0
Empty test suite.

我知道这段代码是最好的,但是我至少需要一个主意

0 个答案:

没有答案