How to use test_two_clients method in devtools-proxy

Best Python code snippet using devtools-proxy_python

simple_test.py

Source:simple_test.py Github

copy

Full Screen

...7class SimpleTest():8 def run(self, port):9 self.setup(port)10 try:11 self.test_two_clients()12 finally:13 self.tear_down()14 def setup(self, port, host="localhost"):15 """Sets up a server and four clients."""16 self.server = Popen(["python", "server.py", str(port)])17 # Give the server time to come up.18 time.sleep(SLEEP_SECONDS)19 self.alice_client = Popen(["python", "client.py", "Alice", host, str(port)], stdin=PIPE, stdout=PIPE)20 self.kay_client = Popen(["python", "client.py", "Kay", host, str(port)], stdin=PIPE, stdout=PIPE)21 time.sleep(SLEEP_SECONDS)22 def tear_down(self):23 """ Stops the clients and server. """24 self.alice_client.kill()25 self.kay_client.kill()26 self.server.kill()27 def get_message_from_buffer(self, buf):28 """Strips all formatting, including [Me] and whitespace."""29 s = "".join(buf).replace('[Me]', '').strip()30 return s31 def check_for_output(self, client, expected_output, check_formatting=False):32 """ Verifies that the given client's stdout matches the given output."""33 output_buffer = []34 end_time = time.time() + 135 # Read one character at a time from stdout until either time timeout expires, or36 # the output is correct.37 while (self.get_message_from_buffer(output_buffer) != expected_output38 and time.time() < end_time):39 select_timeout = end_time - time.time()40 ready_to_read, ready_to_write, in_error = select.select(41 [client.stdout], [], [], select_timeout)42 for readable_socket in ready_to_read:43 char = readable_socket.read(1)44 output_buffer.append(char)45 message = self.get_message_from_buffer(output_buffer)46 if message != expected_output:47 raise Exception("Client output:\n{}; expected:\n{}".format(48 repr(message), repr(expected_output)))49 def test_two_clients(self):50 self.alice_client.stdin.write("/create tas\n")51 # Sleep to make sure that the message from Alice, to create the tas channel,52 # arrives at the server before Kay's message to join the channel.53 time.sleep(SLEEP_SECONDS)54 self.kay_client.stdin.write("/join tas\n")55 # Alice should get a message that Kay joined.56 self.check_for_output(self.alice_client, "Kay has joined")57 # When Kay sends a message, Alice should receive it.58 self.kay_client.stdin.write("Hi!\n")59 self.check_for_output(self.alice_client, "[Kay] Hi!")60 # When Alice sends a message, Kay should receive it.61 self.alice_client.stdin.write("Hello!\n")62 self.check_for_output(self.kay_client, "[Alice] Hello!")63if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devtools-proxy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful