SeleniumBase/examples/time_limit_test.py

28 lines
1.2 KiB
Python
Raw Normal View History

import pytest
from seleniumbase import BaseCase
2022-10-11 07:57:06 +08:00
from seleniumbase import decorators
2021-03-11 06:27:52 +08:00
class TimeLimitTests(BaseCase):
@pytest.mark.expected_failure
2022-10-11 07:57:06 +08:00
def test_runtime_limit_decorator(self):
"""This test fails on purpose to show the runtime_limit() decorator
for code blocks that run longer than the time limit specified."""
print("\n(This test should fail)")
self.open("https://xkcd.com/1190")
with decorators.runtime_limit(0.5):
self.sleep(0.75)
@pytest.mark.expected_failure
def test_set_time_limit_method(self):
"""This test fails on purpose to show the set_time_limit() method
for tests that run longer than the time limit specified (seconds).
The time-limit clock starts after the browser has fully launched,
which is after pytest starts it's own internal clock for tests.
Usage: (inside tests) => self.set_time_limit(SECONDS)
Usage: (command-line) => --time-limit=SECONDS"""
self.set_time_limit(2.5) # Fail test if time exceeds 2.5 seconds
2021-03-07 12:42:08 +08:00
print("\n(This test should fail)")
2022-10-11 07:57:06 +08:00
self.open("https://xkcd.com/1658")
self.sleep(3)