[#447] NEW: Adding example for sleep before wait is used
Issue:#447 Added an example that would sleep for 1 second before every wait action and created a test case for the same to verify.
@yashaka any further change you would recommend here?
@vaibhavsahni009, oh, sorry for late response...
seems like current implementation has sleep_time parameter, that never will be used... because if you pass custom sleep_time, the logic will be broken, won't it? Try to refactor your fixture to be not "autousable", to something like this:
@pytest.fixture(scope='function')
def browser_management_with_default_sleep():
browser.config._wait_decorator = sleep_before_wait
yield
@pytest.fixture(scope='function')
def browser_management_with_custom_sleep():
browser.config._wait_decorator = sleep_before_wait(0.5)
yield
def test_sleep_via__wait_decorator(browser_management_with_default_sleep):
...
def test_sleep_via_wait_decorator_with_custom_time(browser_management_with_custom_sleep):
...
# I suppose this test will fail... try to fix it... or get back to me with response that it works...
Makes sense
I am thinking of something like the following, additionally I believe default value won't be necessary as such, let me know if you think otherwise.
@pytest.fixture(scope='function')
def browser_management_with_custom_sleep():
def custom_sleep_decorator(fn):
return sleep_before_wait(fn, sleep_time=5)
browser.config._wait_decorator = custom_sleep_decorator
yield
def test_sleep_via_wait_decorator_with_custom_time(browser_management_with_custom_sleep):
"""
Waits 5 second each before typing and pressing enter
So the difference between epoch time should be equal to or more that 10
"""
browser.open('http://todomvc.com/examples/emberjs/')
for _ in range(2):
browser.element('#new-todo').type(f'{time.time()}').press_enter()
todo_items = browser.all('#todo-list>li')
initial_epoch_time = float(todo_items.first().text)
final_epoch_time = float(todo_items.second().text)
assert final_epoch_time - initial_epoch_time >= 2 * 5