繁体   English   中英

重复或迭代 pytest 中的测试

[英]repeat or iterate the tests in pytest

我已经编写了一个工作正常的测试,并且想对不同的值重复相同的测试。

示例:Test1 的值为“Farnell”,

第二次测试价值为“探戈”,

“Bravo”的第三次测试等等

你能帮我重复测试吗? 谢谢

def test_supplier_Farnell(setup):
        test_login_infor(setup)
        # time.sleep(2)
        driver.find_element(By.LINK_TEXT, "Supplier Sites").click()
        time.sleep(0.5)
        **driver.find_element(By.LINK_TEXT, "Farnell").click()**
        time.sleep(0.5)
        driver.switch_to.frame("bottomframe")
        driver.switch_to.frame(driver.find_element_by_xpath("//frame[@name='Header']"))
        bodyText = driver.find_element_by_tag_name('body').text

如果您要更改的唯一内容是您正在搜索的字符串(“Farnell”、“Tango”等),那么您可以将该字符串作为参数添加到您的测试中,并在每次调用它时传递不同的参数。

test_strings = ["Farnell", "Tango", "Bravo"]
def test_supplier(setup, test_string):
        test_login_infor(setup)
        # time.sleep(2)
        driver.find_element(By.LINK_TEXT, "Supplier Sites").click()
        time.sleep(0.5)
        **driver.find_element(By.LINK_TEXT, test_string).click()**
        time.sleep(0.5)
        driver.switch_to.frame("bottomframe")
        driver.switch_to.frame(driver.find_element_by_xpath("//frame[@name='Header']"))
        bodyText = driver.find_element_by_tag_name('body').text

for test_string in test_strings:
    test_supplier(setup, test_string)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM