Skip to content

Instantly share code, notes, and snippets.

@elucify elucify/sauce-wtf.py
Created Aug 31, 2015

Embed
What would you like to do?
from selenium import webdriver
from random import random
import contextlib
import sys
if len(sys.argv) != 4:
print "Usage: python sauce-wtf.py <iphone|firefox|firefox.local> username sauce-access-key"
sys.exit(1)
USERNAME="iebqa2"
ACCESS_KEY="9d812a1c-eaa7-440b-9d1d-d8740754e365"
BROWSER=sys.argv[1]
desired_capabilities = {
"iphone": {
'deviceName': 'iPhone Simulator',
'commandTimeout': 300,
'tags': ['timeout-problem-%s' % hex(int(1000 * random()))],
'device-orientation': 'portrait',
'platform': 'OS X 10.10',
'browserName': 'iPhone', 'version': '8.0'
},
"firefox": {
'tags': ['timeout-problem-%s' % hex(int(1000 * random()))],
'platform': 'OS X 10.10',
'browserName': 'firefox',
'version': '40',
},
}
@contextlib.contextmanager
def opendriver(args):
(browser, user, apikey) = args
if browser=="firefox.local":
driver = webdriver.Firefox()
else:
caps = desired_capabilities[browser]
caps["name"] = "How do I control timeout for " + browser
SAUCE_URL = "http://%s:%s@ondemand.saucelabs.com:80/wd/hub" % (user, apikey)
driver = webdriver.Remote(
desired_capabilities=caps,
command_executor=SAUCE_URL,
)
yield driver
driver.quit()
with opendriver(sys.argv[1:]) as driver:
driver.implicitly_wait(10)
driver.get('http://www.saucelabs.com')
driver.get_screenshot_as_file('saucelabs.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.