示例#1
0
def selenium_status(request, session, port):
    parts = request.path.split("/")
    parts[-1] = "status"
    status_cmd = "/".join(parts)
    status, headers, body, selenium_status_code = None, None, None, None

    for attempt in range(3):
        log.info("Attempt %s. Getting selenium-server-standalone status "
                 "for %s" % (attempt, session.id))

        wrapped_make_request = add_sub_step(session, session.make_request)
        for status, headers, body in wrapped_make_request(
                port, RequestHelper("GET", status_cmd)):
            yield status, headers, body
        selenium_status_code = json.loads(body).get("status", None)

        if selenium_status_code == 0:
            log.info("SUCCESS get selenium-server-standalone status for %s" %
                     session.id)
            break
        else:
            log.info("Attempt %s to get selenium status was FAILED. "
                     "Trying again..." % attempt)

    if selenium_status_code != 0:
        log.info("FAIL get selenium-server-standalone status for %s" %
                 session.id)
        raise CreationException("Failed to get selenium status: %s" % body)
    yield status, headers, body
示例#2
0
def start_selenium_session(request, session, port):
    status, headers, body = None, None, None

    for attempt_start in range(3):
        log.info(
            "Attempt %s. Starting selenium-server-standalone session for %s" %
            (attempt_start, session.id))
        log.debug(
            "with %s %s %s %s" %
            (request.method, request.path, request.headers, request.data))

        wrapped_make_request = add_sub_step(session, session.make_request)
        for status, headers, body in wrapped_make_request(
                port,
                RequestHelper(request.method, request.path, request.headers,
                              request.data)):
            yield status, headers, body
        if status == httplib.OK:
            log.info("SUCCESS start selenium-server-standalone status for %s" %
                     session.id)
            break
        else:
            log.info("Attempt %s to start selenium session was FAILED. "
                     "Trying again..." % attempt_start)

    if status != httplib.OK:
        log.info("FAILED start selenium-server-standalone status "
                 "for %s - %s : %s" % (session.id, status, body))
        raise CreationException("Failed to start selenium session: %s" % body)
    yield status, headers, body
示例#3
0
def take_screenshot(session, port):
    for status, headers, body in session.make_request(
            port, RequestHelper(method="GET", url="/takeScreenshot")):
        yield None
    if status == httplib.OK and body:
        json_response = json.loads(body)
        yield json_response["screenshot"]
    else:
        yield None
示例#4
0
def startup_script(session):
    r = RequestHelper(method="POST", data=session.run_script)
    status, headers, body = run_script(r, session)
    if status != httplib.OK:
        raise Exception("failed to run script: %s" % body)
    script_result = json.loads(body)
    if script_result.get("status") != 0:
        raise Exception(
            "failed to run script with code %s:\n%s" %
            (script_result.get("status"), script_result.get("output")))
示例#5
0
文件: helpers.py 项目: gridl/vmmaster
def transparent():
    status, headers, body = None, None, None
    swap_session(request, request.session.selenium_session)
    for status, headers, body in request.session.make_request(
            request.session.endpoint.selenium_port,
            RequestHelper(request.method, request.path, request.headers,
                          request.data)):
        yield status, headers, body

    swap_session(request, str(request.session.id))
    yield status, headers, body
示例#6
0
def transparent():
    status, headers, body = None, None, None
    swap_session(request, request.session.selenium_session)
    for status, headers, body in request.session.make_request(
            config.SELENIUM_PORT,
            RequestHelper(request.method, request.path, request.headers,
                          request.data)):
        yield status, headers, body

    swap_session(request, str(request.session.id))
    yield status, headers, body
示例#7
0
def selenium_status(request, session, port):
    parts = request.path.split("/")
    parts[-1] = "status"
    status_cmd = "/".join(parts)
    status, headers, body, selenium_status_code = None, None, None, None

    log.info("Getting selenium-server-standalone status for %s" % session.id)

    wrapped_make_request = add_sub_step(session, session.make_request)
    for status, headers, body in wrapped_make_request(
            port, RequestHelper("GET", status_cmd)):
        yield status, headers, body
    selenium_status_code = json.loads(body).get("status", None)

    if selenium_status_code != 0:
        log.info("FAILED get selenium-server-standalone status for %s" %
                 session.id)
        raise CreationException("Failed to get selenium status: %s" % body)

    log.info("SUCCESS get selenium-server-standalone status for %s" %
             session.id)
    yield status, headers, body
示例#8
0
def start_selenium_session(request, session, port):
    status, headers, body = None, None, None

    log.info("Starting selenium-server-standalone session for %s" % session.id)
    log.debug("with %s %s %s %s" %
              (request.method, request.path, request.headers, request.data))

    wrapped_make_request = add_sub_step(session, session.make_request)
    for status, headers, body in wrapped_make_request(
            port,
            RequestHelper(request.method, request.path, request.headers,
                          request.data)):
        yield status, headers, body

    if status != httplib.OK:
        log.info("FAILED start selenium-server-standalone status "
                 "for %s - %s : %s" % (session.id, status, body))
        raise CreationException("Failed to start selenium session: %s" % body)

    log.info("SUCCESS start selenium-server-standalone status for %s" %
             session.id)
    yield status, headers, body
示例#9
0
 def selenium_is_ready(self):
     for status, headers, body in network_utils.make_request(
             self.ip, self.selenium_port,
             RequestHelper("GET", "/wd/hub/status")):
         pass
     return status == 200