Selenium Grid 3マルチスレッド分散テスト
2269 ワード
selenium Gride 3紹介:アドレス
まずローカルhub、node
次のコードを実行します.
“`
まずローカル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())
“`