0
votes

I'm new to Robot Framework and stuck with quite simple login web page test using SeleniumLibrary:

*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Input Username    admin
    Input Password    test
    Submit Credentials
    Dashboard Page Should Be Open
    [Teardown]    Close Browser

Most of the keywords are irrelevant to the question, except

Submit Credentials
    Click Button    login-button
Dashboard Page Should Be Open
    Location Should Be    ${DASHBOARD URL}
    Title Should Be    Dashboard

If I run this test, it will fail, because Location Should Be check is executed too early, while browser is still on the original login page. I found two solutions that work, but both seems to be conceptually wrong:

  1. Use sleep

    Submit Credentials
    sleep ${DELAY}
    Dashboard Page Should Be Open
    

    In this case ${DELAY} should be quite big (e.g. 10s) to be sure that page is definitely loaded or it may fail anyway. Also, I've read that best practice is to avoid sleeps. And I can't use some Wait Until Page Contains, because I don't know, whether login page will be loaded again with some error message or Dashboard page loaded in success.

  2. Use Form Submit instead of Click Button:

    Submit Credentials
        Submit Form  login-form
    

The Form Submit works fine, but it's different from actually clicking a button, because button may have some onclick handler that would prevent submitting a form.

Using Wait Until Keyword Succeeds as suggested in some other threads doesn't seem to help, as Click Button succeeds right away.

1

1 Answers

2
votes

You definitely should not use sleep since it introduces artificial delays that may make your whole suite slower than it needs to be. I personally also thing Wait until keyword succeeds should almost never be used. It litters the log with messages as it retries. Plus, I think it masks problems instead of fixing them.

The answer is to use one of the wait keywords. You say you can't use Wait Until Page Contains ""because I don't know, whether login page will be loaded again with some error message or Dashboard page loaded in success". I don't understand that reasoning.

Your application should be deterministic. That is, if you enter correct login credentials than you should be guaranteed that it will go to the dashboard page, and if you enter the wrong conditions you should see an error and/or be redirected back to the login page.

The point of the test is to verify those conditions. So, for a test that verifies whether you get the dashboard page or not, you should find an element on the dashboard page and wait for it to be visible after submitting the form. If it doesn't appear in the proper amount of time, your test should throw an error.

Personally I recommend using page objects. The library I wrote [1], for example, has a mechanism to wait for a page refresh, and assertions to verify you are on the page you think you should be on. You don't need to use my library though -- the core of the code is only a couple hundred lines of code, so it's easy to write your own.

[1] https://github.com/boakley/robotframework-pageobjectlibrary