selenium用tomorrow多线程运行脚本

from time import time, sleep

from tomorrow import threads
from selenium import webdriver


def startBrowser(name):
    try:
        if name == "firefox" or name == "Firefox" or name == "ff":
            print("start browser name :Firefox time{}".format(time()))
            driver = webdriver.Firefox()
            return driver
        elif name == "chrome" or name == "Chrome":
            print("start browser name :Chrome time{}".format(time()))
            driver = webdriver.Chrome()
            sleep(8)
            return driver
        else:
            print("Not found this browser,You can use ‘firefox‘, ‘chrome‘")
    except Exception as msg:
        print("启动浏览器出现异常:%s" % str(msg))


@threads(2)
def test(name):
    driver = startBrowser(name)
    driver.get('https://***********/#/login')
    sleep(1)
    driver.find_element_by_xpath('//*[@placeholder="请输入用户名"]').send_keys('admin')
    sleep(1)
    driver.find_element_by_xpath('//*[@placeholder="请输入密码"]').send_keys('123456')
    sleep(1)
    driver.find_element_by_xpath('//*[@class="login-btn-box"]').click()
    sleep(1)
    driver.find_element_by_xpath('//span[contains(text(),"卡片管理")]').click()
    sleep(2)
    driver.find_element_by_xpath('//span[contains(text(),"电子就诊卡申请审核")]').click()
    sleep(3)
    print(driver.title)


if __name__ == "__main__":
    names = ["chrome", 'ff']
    for i in names:
        test(i)

 

你可能感兴趣的:(UI自动化测试框架)