This repository was archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathparallel.py
More file actions
46 lines (36 loc) · 1.4 KB
/
parallel.py
File metadata and controls
46 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from threading import Thread
from selenium import webdriver
import time
USERNAME = "mikeh"
API_KEY = ""
def get_browser(caps):
return webdriver.Remote(
desired_capabilities=caps,
command_executor="http://%s:%s@hub.crossbrowsertesting.com:80/wd/hub" % (USERNAME, API_KEY)
)
browsers = [
{"os_api_name": "Win7x64-C2", "browser_api_name": "IE10", "name": "Python Parallel"},
{"os_api_name": "Win8.1", "browser_api_name": "Chrome43x64", "name": "Python Parallel"},
]
browsers_waiting = []
def get_browser_and_wait(browser_data):
print "starting %s\n" % browser_data["browser_api_name"]
browser = get_browser(browser_data)
browser.get("http://crossbrowsertesting.com")
browsers_waiting.append({"data": browser_data, "driver": browser})
print "%s ready" % browser_data["browser_api_name"]
while len(browsers_waiting) < len(browsers):
print "working on %s.... please wait" % browser_data["browser_api_name"]
browser.get("http://crossbrowsertesting.com")
time.sleep(3)
threads = []
for i, browser in enumerate(browsers):
thread = Thread(target=get_browser_and_wait, args=[browser])
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
print "all browsers ready"
for i, b in enumerate(browsers_waiting):
print "browser %s's title: %s" % (b["data"]["name"], b["driver"].title)
b["driver"].quit()