How to use wait_for_event method in Playwright Python

Best Python code snippet using playwright-python

AttachTest.py

Source:AttachTest.py Github

copy

Full Screen

...29 the expected callback).30 """31 dut = self.android_devices[0]32 dut.droid.wifiAwareAttach(False)33 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)34 autils.fail_on_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)35 @test_tracker_info(uuid="82f2a8bc-a62b-49c2-ac8a-fe8460010ba2")36 def test_attach_with_identity(self):37 """Functional test case / Attach test cases / attach with identity callback38 Validates that attaching to the Wi-Fi Aware service works (receive39 the expected callbacks).40 """41 dut = self.android_devices[0]42 dut.droid.wifiAwareAttach(True)43 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)44 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)45 @test_tracker_info(uuid="d2714d14-f330-47d4-b8e9-ee4d5e5b7ea0")46 def test_attach_multiple_sessions(self):47 """Functional test case / Attach test cases / multiple attach sessions48 Validates that when creating multiple attach sessions each can be49 configured independently as to whether or not to receive an identity50 callback.51 """52 dut = self.android_devices[0]53 # Create 3 attach sessions: 2 without identity callback, 1 with54 id1 = dut.droid.wifiAwareAttach(False, None, True)55 time.sleep(10) # to make sure all calls and callbacks are done56 id2 = dut.droid.wifiAwareAttach(True, None, True)57 time.sleep(10) # to make sure all calls and callbacks are done58 id3 = dut.droid.wifiAwareAttach(False, None, True)59 dut.log.info('id1=%d, id2=%d, id3=%d', id1, id2, id3)60 # Attach session 1: wait for attach, should not get identity61 autils.wait_for_event(62 dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id1))63 autils.fail_on_event(64 dut,65 autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id1))66 # Attach session 2: wait for attach and for identity callback67 autils.wait_for_event(68 dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id2))69 autils.wait_for_event(70 dut,71 autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id2))72 # Attach session 3: wait for attach, should not get identity73 autils.wait_for_event(74 dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id3))75 autils.fail_on_event(76 dut,77 autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id3))78 @test_tracker_info(uuid="b8ea4d02-ae23-42a7-a85e-def52932c858")79 def test_attach_with_no_wifi(self):80 """Function test case / Attach test cases / attempt to attach with wifi off81 Validates that if trying to attach with Wi-Fi disabled will receive the82 expected failure callback. As a side-effect also validates that the83 broadcast for Aware unavailable is received.84 """85 dut = self.android_devices[0]86 wutils.wifi_toggle_state(dut, False)87 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)88 dut.droid.wifiAwareAttach()89 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)90 @test_tracker_info(uuid="7dcc4530-c936-4447-9d22-a7c5b315e2ce")91 def test_attach_with_doze(self):92 """Function test case / Attach test cases / attempt to attach with doze on93 Validates that if trying to attach with device in doze mode will receive the94 expected failure callback. As a side-effect also validates that the95 broadcast for Aware unavailable is received.96 """97 dut = self.android_devices[0]98 asserts.assert_true(utils.enable_doze(dut), "Can't enable doze")99 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)100 dut.droid.wifiAwareAttach()101 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)102 asserts.assert_true(utils.disable_doze(dut), "Can't disable doze")103 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)104 @test_tracker_info(uuid="2574fd01-8974-4dd0-aeb8-a7194461140e")105 def test_attach_with_location_off(self):106 """Function test case / Attach test cases / attempt to attach with location107 mode off.108 Validates that if trying to attach with device location mode off will109 receive the expected failure callback. As a side-effect also validates that110 the broadcast for Aware unavailable is received.111 """112 dut = self.android_devices[0]113 utils.set_location_service(dut, False)114 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)115 dut.droid.wifiAwareAttach()116 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACH_FAILED)117 utils.set_location_service(dut, True)118 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)119 @test_tracker_info(uuid="7ffde8e7-a010-4b77-97f5-959f263b5249")120 def test_attach_apm_toggle_attach_again(self):121 """Validates that enabling Airplane mode while Aware is on resets it122 correctly, and allows it to be re-enabled when Airplane mode is then123 disabled."""124 dut = self.android_devices[0]125 # enable Aware (attach)126 dut.droid.wifiAwareAttach()127 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED)128 # enable airplane mode129 utils.force_airplane_mode(dut, True)130 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_NOT_AVAILABLE)131 # wait a few seconds and disable airplane mode132 time.sleep(10)133 utils.force_airplane_mode(dut, False)134 autils.wait_for_event(dut, aconsts.BROADCAST_WIFI_AWARE_AVAILABLE)135 # try enabling Aware again (attach)136 dut.droid.wifiAwareAttach()...

Full Screen

Full Screen

ble_characteristic.py

Source:ble_characteristic.py Github

copy

Full Screen

...62 elif event == _IRQ_GATTS_INDICATE_DONE:63 print("_IRQ_GATTS_INDICATE_DONE", data[-1])64 if event not in waiting_events:65 waiting_events[event] = None66def wait_for_event(event, timeout_ms):67 t0 = time.ticks_ms()68 while time.ticks_diff(time.ticks_ms(), t0) < timeout_ms:69 if event in waiting_events:70 return waiting_events.pop(event)71 machine.idle()72 raise ValueError("Timeout waiting for {}".format(event))73# Acting in peripheral role.74def instance0():75 multitest.globals(BDADDR=ble.config("mac"))76 ((char_handle,),) = ble.gatts_register_services(SERVICES)77 print("gap_advertise")78 ble.gap_advertise(20_000, b"\x02\x01\x06\x04\xffMPY")79 multitest.next()80 try:81 # Write initial characteristic value.82 ble.gatts_write(char_handle, "periph0")83 # Wait for central to connect to us.84 conn_handle = wait_for_event(_IRQ_CENTRAL_CONNECT, TIMEOUT_MS)85 # A86 # Wait for a write to the characteristic from the central,87 # then reply with a notification.88 wait_for_event(_IRQ_GATTS_WRITE, TIMEOUT_MS)89 print("gatts_write")90 ble.gatts_write(char_handle, "periph1")91 print("gatts_notify")92 ble.gatts_notify(conn_handle, char_handle)93 # B94 # Wait for a write to the characteristic from the central,95 # then reply with value-included notification.96 wait_for_event(_IRQ_GATTS_WRITE, TIMEOUT_MS)97 print("gatts_notify")98 ble.gatts_notify(conn_handle, char_handle, "periph2")99 # C100 # Wait for a write to the characteristic from the central,101 # then reply with an indication.102 wait_for_event(_IRQ_GATTS_WRITE, TIMEOUT_MS)103 print("gatts_write")104 ble.gatts_write(char_handle, "periph3")105 print("gatts_indicate")106 ble.gatts_indicate(conn_handle, char_handle)107 wait_for_event(_IRQ_GATTS_INDICATE_DONE, TIMEOUT_MS)108 # Wait for the central to disconnect.109 wait_for_event(_IRQ_CENTRAL_DISCONNECT, TIMEOUT_MS)110 finally:111 ble.active(0)112# Acting in central role.113def instance1():114 multitest.next()115 try:116 # Connect to peripheral and then disconnect.117 print("gap_connect")118 ble.gap_connect(*BDADDR)119 conn_handle = wait_for_event(_IRQ_PERIPHERAL_CONNECT, TIMEOUT_MS)120 # Discover characteristics.121 ble.gattc_discover_characteristics(conn_handle, 1, 65535)122 value_handle = wait_for_event(_IRQ_GATTC_CHARACTERISTIC_RESULT, TIMEOUT_MS)123 wait_for_event(_IRQ_GATTC_CHARACTERISTIC_DONE, TIMEOUT_MS)124 # Issue read of characteristic, should get initial value.125 print("gattc_read")126 ble.gattc_read(conn_handle, value_handle)127 wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)128 # Write to the characteristic, which will trigger a notification.129 print("gattc_write")130 ble.gattc_write(conn_handle, value_handle, "central0", 1)131 wait_for_event(_IRQ_GATTC_WRITE_DONE, TIMEOUT_MS)132 # A133 wait_for_event(_IRQ_GATTC_NOTIFY, TIMEOUT_MS)134 print("gattc_read") # Read the new value set immediately before notification.135 ble.gattc_read(conn_handle, value_handle)136 wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)137 # Write to the characteristic, which will trigger a value-included notification.138 print("gattc_write")139 ble.gattc_write(conn_handle, value_handle, "central1", 1)140 wait_for_event(_IRQ_GATTC_WRITE_DONE, TIMEOUT_MS)141 # B142 wait_for_event(_IRQ_GATTC_NOTIFY, TIMEOUT_MS)143 print("gattc_read") # Read value should be unchanged.144 ble.gattc_read(conn_handle, value_handle)145 wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)146 # Write to the characteristic, which will trigger an indication.147 print("gattc_write")148 ble.gattc_write(conn_handle, value_handle, "central2", 1)149 wait_for_event(_IRQ_GATTC_WRITE_DONE, TIMEOUT_MS)150 # C151 wait_for_event(_IRQ_GATTC_INDICATE, TIMEOUT_MS)152 print("gattc_read") # Read the new value set immediately before indication.153 ble.gattc_read(conn_handle, value_handle)154 wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)155 # Disconnect from peripheral.156 print("gap_disconnect:", ble.gap_disconnect(conn_handle))157 wait_for_event(_IRQ_PERIPHERAL_DISCONNECT, TIMEOUT_MS)158 finally:159 ble.active(0)160ble = bluetooth.BLE()161ble.active(1)...

Full Screen

Full Screen

stress_log_filesystem.py

Source:stress_log_filesystem.py Github

copy

Full Screen

...84 elif event == _IRQ_GATTS_READ_REQUEST:85 print("_IRQ_GATTS_READ_REQUEST")86 if event not in waiting_events:87 waiting_events[event] = None88def wait_for_event(event, timeout_ms):89 t0 = time.ticks_ms()90 while time.ticks_diff(time.ticks_ms(), t0) < timeout_ms:91 periodic_log_write()92 if event in waiting_events:93 return waiting_events.pop(event)94 machine.idle()95 raise ValueError("Timeout waiting for {}".format(event))96# Acting in peripheral role.97def instance0():98 global log_file99 log_file = open(LOG_PATH_INSTANCE0, "w")100 write_log("start")101 ble.active(1)102 ble.irq(irq)103 multitest.globals(BDADDR=ble.config("mac"))104 ((char_handle,),) = ble.gatts_register_services(SERVICES)105 multitest.next()106 try:107 for repeat in range(2):108 print("gap_advertise")109 ble.gap_advertise(50_000, b"\x02\x01\x06\x04\xffMPY")110 # Wait for central to connect, do a sequence of read/write, then disconnect.111 wait_for_event(_IRQ_CENTRAL_CONNECT, TIMEOUT_MS)112 for op in range(4):113 wait_for_event(_IRQ_GATTS_READ_REQUEST, TIMEOUT_MS)114 wait_for_event(_IRQ_GATTS_WRITE, TIMEOUT_MS)115 wait_for_event(_IRQ_CENTRAL_DISCONNECT, 2 * TIMEOUT_MS)116 finally:117 ble.active(0)118 log_file.close()119 os.unlink(LOG_PATH_INSTANCE0)120# Acting in central role.121def instance1():122 global log_file123 log_file = open(LOG_PATH_INSTANCE1, "w")124 write_log("start")125 ble.active(1)126 ble.irq(irq)127 multitest.next()128 try:129 for repeat in range(2):130 # Connect to peripheral and then disconnect.131 print("gap_connect")132 ble.gap_connect(BDADDR[0], BDADDR[1], 5000)133 conn_handle = wait_for_event(_IRQ_PERIPHERAL_CONNECT, TIMEOUT_MS)134 # Discover services.135 print("gattc_discover_services")136 ble.gattc_discover_services(conn_handle)137 start_handle, end_handle = wait_for_event(_IRQ_GATTC_SERVICE_RESULT, TIMEOUT_MS)138 wait_for_event(_IRQ_GATTC_SERVICE_DONE, TIMEOUT_MS)139 # Discover characteristics.140 print("gattc_discover_characteristics")141 ble.gattc_discover_characteristics(conn_handle, start_handle, end_handle)142 value_handle = wait_for_event(_IRQ_GATTC_CHARACTERISTIC_RESULT, TIMEOUT_MS)143 wait_for_event(_IRQ_GATTC_CHARACTERISTIC_DONE, TIMEOUT_MS)144 for op in range(4):145 print("gattc_read")146 ble.gattc_read(conn_handle, value_handle)147 wait_for_event(_IRQ_GATTC_READ_RESULT, TIMEOUT_MS)148 wait_for_event(_IRQ_GATTC_READ_DONE, TIMEOUT_MS)149 print("gattc_write")150 ble.gattc_write(conn_handle, value_handle, "{}".format(op), 1)151 wait_for_event(_IRQ_GATTC_WRITE_DONE, TIMEOUT_MS)152 # Disconnect.153 print("gap_disconnect:", ble.gap_disconnect(conn_handle))154 wait_for_event(_IRQ_PERIPHERAL_DISCONNECT, 2 * TIMEOUT_MS)155 finally:156 ble.active(0)157 log_file.close()158 os.unlink(LOG_PATH_INSTANCE1)...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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