Selenium Grid3 做多執行緒分散式測試
阿新 • • 發佈:2019-02-15
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())
“`