Esempio n. 1
0
 def wait_until_server_up(self):
     for i in range(50):
         with grpc.insecure_channel(f"localhost:{self.port}") as channel:
             try:
                 stub = playwright_pb2_grpc.PlaywrightStub(channel)
                 response = stub.Health(Request().Empty())
                 logger.info(
                     f"Connected to the playwright process at port {self.port}: {response}"
                 )
                 return
             except grpc.RpcError as err:
                 logger.info(err)
                 time.sleep(0.1)
     raise RuntimeError(
         f"Could not connect to the playwright process at port {self.port}")
    def grpc_channel(self):
        """Yields a PlayWrightstub on a newly initialized channel

        Acts as a context manager, so channel is closed automatically when control returns.
        """
        returncode = self._playwright_process.poll()
        if returncode is not None:
            raise ConnectionError(
                "Playwright process has been terminated with code {}".format(
                    returncode))
        channel = grpc.insecure_channel(f"localhost:{self.port}")
        try:
            yield playwright_pb2_grpc.PlaywrightStub(channel)
        except Exception as e:
            raise AssertionError(self.get_reason(e))
        finally:
            channel.close()
Esempio n. 3
0
    def grpc_channel(self, original_error=False):
        """Yields a PlayWrightstub on a newly initialized channel

        Acts as a context manager, so channel is closed automatically when control returns.
        """
        playwright_process = self._playwright_process
        if playwright_process:
            returncode = playwright_process.poll()
            if returncode is not None:
                raise ConnectionError(
                    "Playwright process has been terminated with code {}".
                    format(returncode))
        try:
            yield playwright_pb2_grpc.PlaywrightStub(self._channel)
        except grpc.RpcError as error:
            if original_error:
                raise error
            raise AssertionError(error.details())
        except Exception as error:
            logger.debug(f"Unknown error received: {error}")
            raise AssertionError(str(error))