发表文章

[最新] Selenium Grid3 做多线程分布式测试

qq37884273 3月前 2

selenium Gride3 介绍:地址

首先启动本地一个hub,一个node
java -jar selenium-server-standalone-3.9.0.jar -role hub - port
java -jar selenium-server-standalone-3.9.0.jar -role hub - port 5555

运行下面的代码:

from threading import Thread
from selenium import webdriver
from time import ctime

#测试用例
def test_baidu(host, browser):
    print('start: %s' %ctime())
    print(host, browser)
    dc = {'browserName': browser}
    driver = webdriver.Remote(command_executor=host, desired_capabilities=dc)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('kw').send_keys(browser)
    driver.find_element_by_id('su').click()
    driver.close()

if __name__ == '__main__':
     # 启动参数(指定运行主机与浏览器)
     lists = {'http://127.0.0.1:4444/wd/hub': 'chrome',
            'http://127.0.0.1:5555/wd/hub': 'firefox',
            }
     threads = []
     files = range(len(lists))

     for host, browser in lists.items():
         t = Thread(target=test_baidu,args=(host, browser))
         threads.append(t)
     for i in files:
         threads[i].start()
     for j in files:
         threads[j].join()

     print('end: %s:' %ctime())

“`

相关推荐
最新评论 (0)
返回
发表文章
qq37884273
文章数
45
评论数
0
注册排名
1223985