How to use wait_until_stopped method in Playwright Python

Best Python code snippet using playwright-python

traits_executor_tests.py

Source:traits_executor_tests.py Github

copy

Full Screen

...119 with self.long_running_task(self.executor):120 self.assertEqual(self.executor.state, RUNNING)121 self.executor.stop()122 self.assertEqual(self.executor.state, STOPPING)123 self.wait_until_stopped(self.executor)124 self.assertEqual(self.executor.state, STOPPED)125 self.assertEqual(self.listener.states, [RUNNING, STOPPING, STOPPED])126 def test_stop_method_with_no_jobs(self):127 self.assertEqual(self.executor.state, RUNNING)128 self.executor.stop()129 self.wait_until_stopped(self.executor)130 self.assertEqual(self.executor.state, STOPPED)131 self.assertEqual(self.listener.states, [RUNNING, STOPPING, STOPPED])132 def test_stop_method_raises_unless_running(self):133 with self.long_running_task(self.executor):134 self.assertEqual(self.executor.state, RUNNING)135 self.executor.stop()136 # Raises if in STOPPING mode.137 self.assertEqual(self.executor.state, STOPPING)138 with self.assertRaises(RuntimeError):139 self.executor.stop()140 self.wait_until_stopped(self.executor)141 # Raises if in STOPPED mode.142 self.assertEqual(self.executor.state, STOPPED)143 with self.assertRaises(RuntimeError):144 self.executor.stop()145 def test_shutdown_when_already_stopping(self):146 with self.long_running_task(self.executor):147 self.assertEqual(self.executor.state, RUNNING)148 self.executor.stop()149 self.assertEqual(self.executor.state, STOPPING)150 self.executor.shutdown(timeout=SAFETY_TIMEOUT)151 self.assertEqual(self.executor.state, STOPPED)152 def test_shutdown_does_nothing_if_stopped(self):153 self.assertEqual(self.executor.state, RUNNING)154 self.executor.stop()155 self.wait_until_stopped(self.executor)156 self.assertEqual(self.executor.state, STOPPED)157 self.executor.shutdown(timeout=SAFETY_TIMEOUT)158 self.assertEqual(self.executor.state, STOPPED)159 def test_shutdown_cancels_running_futures(self):160 future = submit_call(self.executor, pow, 3, 5)161 self.executor.shutdown(timeout=SAFETY_TIMEOUT)162 self.assertEqual(future.state, CANCELLED)163 self.assertTrue(self.executor.stopped)164 def test_no_future_updates_after_shutdown(self):165 future = submit_call(self.executor, pow, 3, 5)166 self.executor.shutdown(timeout=SAFETY_TIMEOUT)167 self.assertEqual(future.state, CANCELLED)168 self.exercise_event_loop()169 self.assertEqual(future.state, CANCELLED)170 def test_shutdown_goes_through_stopping_state(self):171 self.executor.shutdown(timeout=SAFETY_TIMEOUT)172 self.assertEqual(173 self.listener.states,174 [RUNNING, STOPPING, STOPPED],175 )176 def test_shutdown_waits_for_background_tasks(self):177 starting = self._context.event()178 stopping = self._context.event()179 submit_call(self.executor, slow_call, starting, stopping)180 # Make sure background task has started, else it might be181 # cancelled altogether.182 self.assertTrue(starting.wait(timeout=SAFETY_TIMEOUT))183 self.executor.shutdown(timeout=SAFETY_TIMEOUT)184 self.assertTrue(stopping.is_set())185 def test_shutdown_timeout(self):186 start_time = time.monotonic()187 with self.long_running_task(self.executor):188 with self.assertRaisesRegex(RuntimeError, "1 tasks still running"):189 self.executor.shutdown(timeout=0.1)190 actual_timeout = time.monotonic() - start_time191 self.assertLess(actual_timeout, 1.0)192 self.assertEqual(self.executor.state, STOPPING)193 self.executor.shutdown(timeout=SAFETY_TIMEOUT)194 self.assertEqual(self.executor.state, STOPPED)195 def test_cant_submit_new_unless_running(self):196 with self.long_running_task(self.executor):197 self.executor.stop()198 self.assertEqual(self.executor.state, STOPPING)199 with self.assertRaises(RuntimeError):200 submit_call(self.executor, len, (1, 2, 3))201 self.wait_until_stopped(self.executor)202 self.assertEqual(self.executor.state, STOPPED)203 with self.assertRaises(RuntimeError):204 submit_call(self.executor, int)205 def test_stop_cancels_running_futures(self):206 with self.long_running_task(self.executor) as future:207 self.wait_for_state(future, EXECUTING)208 self.assertEqual(future.state, EXECUTING)209 self.executor.stop()210 self.assertEqual(future.state, CANCELLING)211 self.wait_until_done(future)212 self.assertEqual(future.state, CANCELLED)213 self.wait_until_stopped(self.executor)214 self.assertEqual(self.executor.state, STOPPED)215 def test_running(self):216 self.assertTrue(self.executor.running)217 with self.long_running_task(self.executor):218 self.assertTrue(self.executor.running)219 self.executor.stop()220 self.assertFalse(self.executor.running)221 self.wait_until_stopped(self.executor)222 self.assertFalse(self.executor.running)223 def test_stopped(self):224 self.assertFalse(self.executor.stopped)225 with self.long_running_task(self.executor):226 self.assertFalse(self.executor.stopped)227 self.executor.stop()228 self.assertFalse(self.executor.stopped)229 self.wait_until_stopped(self.executor)230 self.assertTrue(self.executor.stopped)231 def test_submit_call_method(self):232 with self.assertWarns(DeprecationWarning) as warning_info:233 future = self.executor.submit_call(234 test_call, "arg1", "arg2", kwd1="kwd1", kwd2="kwd2"235 )236 self.wait_until_done(future)237 self.assertEqual(238 future.result,239 (("arg1", "arg2"), {"kwd1": "kwd1", "kwd2": "kwd2"}),240 )241 _, _, this_module = __name__.rpartition(".")242 self.assertIn(this_module, warning_info.filename)243 self.assertIn(244 "submit_call method is deprecated",245 str(warning_info.warning),246 )247 def test_submit_iteration_method(self):248 with self.assertWarns(DeprecationWarning) as warning_info:249 future = self.executor.submit_iteration(250 test_iteration,251 "arg1",252 "arg2",253 kwd1="kwd1",254 kwd2="kwd2",255 )256 results = []257 future.observe(lambda event: results.append(event.new), "result_event")258 self.wait_until_done(future)259 self.assertEqual(260 results,261 [("arg1", "arg2"), {"kwd1": "kwd1", "kwd2": "kwd2"}],262 )263 _, _, this_module = __name__.rpartition(".")264 self.assertIn(this_module, warning_info.filename)265 self.assertIn(266 "submit_iteration method is deprecated",267 str(warning_info.warning),268 )269 def test_submit_progress_method(self):270 with self.assertWarns(DeprecationWarning) as warning_info:271 future = self.executor.submit_progress(272 test_progress,273 "arg1",274 "arg2",275 kwd1="kwd1",276 kwd2="kwd2",277 )278 self.wait_until_done(future)279 self.assertEqual(280 future.result,281 ("arg1", "arg2", "kwd1", "kwd2"),282 )283 _, _, this_module = __name__.rpartition(".")284 self.assertIn(this_module, warning_info.filename)285 self.assertIn(286 "submit_progress method is deprecated",287 str(warning_info.warning),288 )289 def test_states_consistent(self):290 # Triples (state, running, stopped).291 states = []292 def record_states(event=None):293 states.append(294 (295 self.executor.state,296 self.executor.running,297 self.executor.stopped,298 )299 )300 self.executor.observe(record_states, "running")301 self.executor.observe(record_states, "stopped")302 self.executor.observe(record_states, "state")303 submit_call(self.executor, int)304 # Record states before, during, and after stopping.305 record_states()306 self.executor.stop()307 self.wait_until_stopped(self.executor)308 record_states()309 for state, running, stopped in states:310 self.assertEqual(running, state == RUNNING)311 self.assertEqual(stopped, state == STOPPED)312 def test_running_and_stopped_fired_only_once(self):313 submit_call(self.executor, int)314 self.executor.stop()315 self.wait_until_stopped(self.executor)316 self.assertEqual(self.listener.running_changes, [(True, False)])317 self.assertEqual(self.listener.stopped_changes, [(False, True)])318 def test_running_and_stopped_fired_only_once_no_futures(self):319 # Same as above but tests the case where the executor goes to STOPPED320 # state the moment that stop is called.321 self.executor.stop()322 self.wait_until_stopped(self.executor)323 self.assertEqual(self.listener.running_changes, [(True, False)])324 self.assertEqual(self.listener.stopped_changes, [(False, True)])325 def test_multiple_futures(self):326 futures = []327 for i in range(100):328 futures.append(submit_call(self.executor, str, i))329 listener = FuturesListener(futures=futures)330 # Wait for all futures to complete.331 self.run_until(332 listener, "all_done", lambda listener: listener.all_done333 )334 for i, future in enumerate(futures):335 self.assertEqual(future.result, str(i))336 def test_stop_with_multiple_futures(self):337 futures = []338 for i in range(100):339 futures.append(submit_call(self.executor, str, i))340 self.executor.stop()341 self.wait_until_stopped(self.executor)342 for future in futures:343 self.assertEqual(future.state, CANCELLED)344 def test_submit_from_background_thread(self):345 def target(executor, msg_queue):346 """347 Submit a simple callable to the given executor, and report348 the result of that submission to a queue.349 """350 try:351 future = submit_call(executor, pow, 2, 3)352 except BaseException as exc:353 msg_queue.put(("FAILED", exc))354 else:355 msg_queue.put(("DONE", future))356 msg_queue = queue.Queue()357 worker = threading.Thread(358 target=target, args=(self.executor, msg_queue)359 )360 worker.start()361 try:362 result_type, future_or_exc = msg_queue.get(timeout=SAFETY_TIMEOUT)363 finally:364 worker.join(timeout=SAFETY_TIMEOUT)365 self.assertEqual(result_type, "FAILED")366 self.assertIsInstance(future_or_exc, RuntimeError)367 # Helper methods and assertions ###########################################368 def wait_until_stopped(self, executor):369 """370 Wait for the executor to reach STOPPED state.371 """372 self.run_until(executor, "stopped", lambda executor: executor.stopped)373 def wait_until_done(self, future):374 self.run_until(future, "done", lambda future: future.done)375 def wait_for_state(self, future, state):376 self.run_until(future, "state", lambda future: future.state == state)377 @contextlib.contextmanager378 def long_running_task(self, executor, timeout=SAFETY_TIMEOUT):379 """380 Simulate a long-running task being submitted to the executor.381 This context manager waits for the task to start executing before382 yielding the future associated to that task. The task will be...

Full Screen

Full Screen

study_vm_service.py

Source:study_vm_service.py Github

copy

Full Screen

...89 if status not in ALLOWED_STATUSES:90 raise InvalidEc2Status(status)91 study.status = status92 study.save()93def wait_until_stopped(instance, study):94 try:95 """96 Waits until this Instance is stopped. This method calls EC2.Waiter.instance_stopped.wait() which polls.97 EC2.Client.describe_instances() every 15 seconds until a successful state is reached.98 An error is returned after 40 failed checks.99 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Instance.wait_until_stopped100 """101 instance.wait_until_stopped()102 update_study_state(study, Study.VM_STOPPED)103 except Exception as e:104 logger.exception("Error trying to wait until instance stopped", e)105 update_study_state(study, Study.ST_ERROR)106def get_and_update_study_instance(boto3_client, study, status_filter):107 """108 get the study instance, and update the database accordingly to the VM status109 :param boto3_client: boto3 client with access to the study instance110 :param study: Study Django model111 :param status_filter: A list of ec2 instance statuses to filter by112 :return: aws ec2 instance object113 """114 execution_token = study.execution.execution_user.email.split("@")[0]115 instance = get_instance(boto3_client, execution_token, status_filter)...

Full Screen

Full Screen

robotiq_2f_gripper_ctrl.py

Source:robotiq_2f_gripper_ctrl.py Github

copy

Full Screen

...49 # in mA50 def get_current(self):51 return self.cur_status.gCU * 0.152 # if timeout is negative, wait forever53 def wait_until_stopped(self, timeout=-1):54 r = rospy.Rate(30)55 start_time = rospy.get_time()56 while not rospy.is_shutdown():57 if (timeout >= 0. and rospy.get_time() - start_time > timeout) or self.is_reset():58 return False59 if self.is_stopped():60 return True61 r.sleep()62 return False63 def wait_until_moving(self, timeout=-1):64 r = rospy.Rate(30)65 start_time = rospy.get_time()66 while not rospy.is_shutdown():67 if (timeout >= 0. and rospy.get_time() - start_time > timeout) or self.is_reset():68 return False69 if not self.is_stopped():70 return True71 r.sleep()72 return False73 def reset(self):74 cmd = outputMsg()75 cmd.rACT = 076 self.cmd_pub.publish(cmd)77 def activate(self, timeout=-1):78 cmd = outputMsg()79 cmd.rACT = 180 cmd.rGTO = 181 cmd.rPR = 082 cmd.rSP = 25583 cmd.rFR = 15084 self.cmd_pub.publish(cmd)85 r = rospy.Rate(30)86 start_time = rospy.get_time()87 while not rospy.is_shutdown():88 if timeout >= 0. and rospy.get_time() - start_time > timeout:89 return False90 if self.is_ready():91 return True92 r.sleep()93 return False94 def auto_release(self):95 cmd = outputMsg()96 cmd.rACT = 197 cmd.rATR = 198 self.cmd_pub.publish(cmd)99 ##100 # Goto position with desired force and velocity101 # @param pos Gripper width in meters. [0, 0.087]102 # @param vel Gripper speed in m/s. [0.013, 0.100]103 # @param force Gripper force in N. [30, 100] (not precise)104 def goto(self, pos, vel, force, block=False, timeout=-1):105 cmd = outputMsg()106 cmd.rACT = 1107 cmd.rGTO = 1108 cmd.rPR = int(np.clip((13.-230.)/0.087 * pos + 230., 0, 255))109 cmd.rSP = int(np.clip(255./(0.1-0.013) * (vel-0.013), 0, 255))110 cmd.rFR = int(np.clip(255./(100.-30.) * (force-30.), 0, 255))111 self.cmd_pub.publish(cmd)112 rospy.sleep(0.1)113 if block:114 if not self.wait_until_moving(timeout):115 return False116 return self.wait_until_stopped(timeout)117 return True118 def stop(self, block=False, timeout=-1):119 cmd = outputMsg()120 cmd.rACT = 1121 cmd.rGTO = 0122 self.cmd_pub.publish(cmd)123 rospy.sleep(0.1)124 if block:125 return self.wait_until_stopped(timeout)126 return True127 def open(self, vel=0.1, force=100, block=False, timeout=-1):128 if self.is_opened():129 return True130 return self.goto(1.0, vel, force, block=block, timeout=timeout)131 def close(self, vel=0.1, force=100, block=False, timeout=-1):132 if self.is_closed():133 return True134 return self.goto(-1.0, vel, force, block=block, timeout=timeout)135def main():136 rospy.init_node("robotiq_2f_gripper_ctrl_test")137 gripper = RobotiqCGripper()138 gripper.wait_for_connection()139 if gripper.is_reset():...

Full Screen

Full Screen

backend_manager_test.py

Source:backend_manager_test.py Github

copy

Full Screen

...60 self.mgr.start()61 await self.mgr.wait_until_running()62 self.assertTrue(self.mgr.is_running)63 self.mgr.stop()64 await self.mgr.wait_until_stopped()65 self.assertFalse(self.mgr.is_running)66 async def test_start_fails(self):67 self.backend.exception_in_start = True68 self.mgr.start()69 with self.assertRaises(RuntimeError):70 await self.mgr.wait_until_running()71 self.assertFalse(self.mgr.is_running)72 async def test_stop_fails(self):73 self.backend.exception_in_stop = True74 self.mgr.start()75 await self.mgr.wait_until_running()76 self.mgr.stop()77 with self.assertRaises(RuntimeError):78 await self.mgr.wait_until_stopped()79 async def test_crashed(self):80 self.mgr.start()81 await self.mgr.wait_until_running()82 self.mgr.crashed()83 await self.backend.is_stopped.wait()84 async def test_stop_crashed(self):85 self.mgr.start()86 await self.mgr.wait_until_running()87 self.mgr.crashed()88 self.mgr.stop()89 await self.mgr.wait_until_stopped()90 async def test_restart(self):91 self.backend.num_restarts = 192 self.mgr.start()93 await self.mgr.wait_until_running()94 self.mgr.crashed()95 await self.backend.is_restarted.wait()96 self.mgr.stop()97 await self.mgr.wait_until_stopped()98 async def test_crash_and_stop_fails(self):99 error_handler_called = asyncio.Event(loop=self.loop)100 def error_handler(event_loop, context):101 error_handler_called.set()102 self.loop.set_exception_handler(error_handler)103 self.backend.exception_in_stop = True104 self.mgr.start()105 await self.mgr.wait_until_running()106 self.mgr.crashed()...

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