コード例 #1
0
def browser(request, browser_config):
    caps = {}
    caps.update(browser_config)

    build_tag = "nerodia-build"
    username = environ.get('SAUCE_USERNAME', None)
    access_key = environ.get('SAUCE_ACCESS_KEY', None)

    selenium_endpoint = "http://ondemand.saucelabs.com/wd/hub"

    caps['username'] = username
    caps['accesskey'] = access_key
    caps['name'] = request.node.name
    caps['build'] = build_tag

    executor = RemoteConnection(selenium_endpoint, resolve_ip=False)
    remote = webdriver.Remote(command_executor=executor,
                              desired_capabilities=caps)

    browser = Browser(browser=remote, desired_capabilities=caps)
    yield browser

    sauce_result = "failed" if request.node.rep_call.failed else "passed"
    browser.execute_script("sauce:job-result={}".format(sauce_result))
    browser.quit()
コード例 #2
0
        if not t.goto_next_url(random.choice(range(1, 20))):
            tabs.remove(t)
            urls_visited = urls_visited + len(t.urls_visited)

    if urls_visited >= tabs_required_randomise_last + tabs_required_randomise_period:
        tabs_required = int(tabs_required * random.choice((0.25, 0.5, 2, 4)))
        tabs_required = max(1, min(tabs_required, params.tabs_max))
        tabs_required_randomise_last = urls_visited

    if workload_pause_period > 0 and urls_visited >= workload_pause_last + workload_pause_period:
        sleep(240)
        workload_pause_last = urls_visited

print('OK -- done', file=sys.stderr)
browser.close()
'''
with browser.window(handle=browser.wd.window_handles[0]) as w:
    browser.goto('google.com')
    w.close()
browser.execute_script('window.open()')
with browser.window(handle=browser.wd.window_handles[-1]) as w:
    browser.goto('google.com')
    w.close()

for wh in browser.wd.window_handles:
    w = browser.window(handle=wh)
    with w:
        browser.goto('google.com')
    # also 
    #w.use()
    #browser.goto()