Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#447] NEW: Adding example for sleep before wait is used #476

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vaibhavsahni009
Copy link

@vaibhavsahni009 vaibhavsahni009 commented Apr 4, 2023

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.

@vaibhavsahni009
Copy link
Author

@yashaka any further change you would recommend here?

@yashaka
Copy link
Owner

yashaka commented Jul 22, 2023

@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...

@vaibhavsahni009
Copy link
Author

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

@vaibhavsahni009 vaibhavsahni009 force-pushed the feature/sleep_before_wait_starts branch 2 times, most recently from e8641e0 to badd4fa Compare September 16, 2023 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants