예제 #1
0
    def send_command(self, method, url, body=None):
        """
        Send a command to the remote end and validate its success.

        :param method: HTTP method to use in request.
        :param uri: "Command part" of the HTTP request URL,
            e.g. `window/rect`.
        :param body: Optional body of the HTTP request.

        :return: `None` if the HTTP response body was empty, otherwise
            the `value` field returned after parsing the response
            body as JSON.

        :raises ValueError: If the response body does not contain a
            `value` key.
        :raises error.WebDriverException: If the remote end returns
            an error.
        """
        response = self.transport.send(method,
                                       url,
                                       body,
                                       encoder=protocol.Encoder,
                                       decoder=protocol.Decoder,
                                       session=self)

        if response.status != 200:
            raise error.from_response(response)

        if "value" in response.body:
            value = response.body["value"]
        else:
            raise ValueError("Expected 'value' key in response body:\n"
                             "%s" % response)

        return value
예제 #2
0
    def send_command(self, method, url, body=None):
        """
        Send a command to the remote end and validate its success.

        :param method: HTTP method to use in request.
        :param uri: "Command part" of the HTTP request URL,
            e.g. `window/rect`.
        :param body: Optional body of the HTTP request.

        :return: `None` if the HTTP response body was empty, otherwise
            the `value` field returned after parsing the response
            body as JSON.

        :raises ValueError: If the response body does not contain a
            `value` key.
        :raises error.WebDriverException: If the remote end returns
            an error.
        """
        response = self.transport.send(method,
                                       url,
                                       body,
                                       encoder=protocol.Encoder,
                                       decoder=protocol.Decoder,
                                       session=self)

        if response.status != 200:
            err = error.from_response(response)

            if isinstance(err, error.SessionNotCreatedException):
                # The driver could have already been deleted the session.
                self.session_id = None

            raise err

        if "value" in response.body:
            value = response.body["value"]
            """
            Edge does not yet return the w3c session ID.
            We want the tests to run in Edge anyway to help with REC.
            In order to run the tests in Edge, we need to hack around
            bug:
            https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/14641972
            """
            if url == "session" and method == "POST" and "sessionId" in response.body and "sessionId" not in value:
                value["sessionId"] = response.body["sessionId"]
        else:
            raise ValueError("Expected 'value' key in response body:\n"
                             "%s" % response)

        return value
예제 #3
0
    def send_command(self, method, url, body=None):
        """
        Send a command to the remote end and validate its success.

        :param method: HTTP method to use in request.
        :param uri: "Command part" of the HTTP request URL,
            e.g. `window/rect`.
        :param body: Optional body of the HTTP request.

        :return: `None` if the HTTP response body was empty, otherwise
            the `value` field returned after parsing the response
            body as JSON.

        :raises ValueError: If the response body does not contain a
            `value` key.
        :raises error.WebDriverException: If the remote end returns
            an error.
        """
        response = self.transport.send(
            method, url, body,
            encoder=protocol.Encoder, decoder=protocol.Decoder,
            session=self)

        if response.status != 200:
            err = error.from_response(response)

            if isinstance(err, error.SessionNotCreatedException):
                # The driver could have already been deleted the session.
                self.session_id = None

            raise err

        if "value" in response.body:
            value = response.body["value"]
            """
            Edge does not yet return the w3c session ID.
            We want the tests to run in Edge anyway to help with REC.
            In order to run the tests in Edge, we need to hack around
            bug:
            https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/14641972
            """
            if url == "session" and method == "POST" and "sessionId" in response.body and "sessionId" not in value:
                value["sessionId"] = response.body["sessionId"]
        else:
            raise ValueError("Expected 'value' key in response body:\n"
                "%s" % response)

        return value
예제 #4
0
 def error(self):
     if self.status != 200:
         return error.from_response(self)
     return None
예제 #5
0
파일: transport.py 프로젝트: askeing/servo
 def error(self):
     if self.status != 200:
         return error.from_response(self)
     return None