1

I have Robot Framework tests that are automated in a Gitlab pipeline in a Docker environment (Apache + Robot Framework runs entirely on the Gitlab runner)

The problem is that regularly, tests fail because JS events are not yet fully applied when clicking a button. RF is faster than the browser and clicks the button before the JS has time to be fully executed.

I can't modify the application to apply the events as soon as possible, and in any case some are in external libraries.

I tried everything, nothing to do. I despair of being able to make these tests reliable.

Here is the code to reproduce the behavior, the setTimeout allows to simulate a certain delay in the execution of the JS.

<!doctype html>
<html lang=en>
<head>
    <meta charset=utf-8>
    <title>blah</title>
    <script src="jquery.js"></script>
</head>
<body>

<button id="button1">Click me 1</button>
<button id="button2">Click me 2</button>
<p id="result"></p>

<script>
    $(document).ready(function(){
        $('#button1').click(function() {
            setTimeout(function(){
                $('#button2').click(function() {
                    $('#result').text('Button 2 clicked');
                });
            }, 500)
        });
    });
</script>

</body>
</html>

And here is an example of RF test suite to reproduce the issue. I added a bunch of identical test cases and ran them in parallel with Pabot. It gives me random failures.

*** Settings ***

Library    SeleniumLibrary

*** Test Cases ***

test 0
    test click button with timeout
test 2
    test click button with timeout
test 3
    test click button with timeout
# .....

*** Keywords ***

test click button with timeout
    Open Browser    about:blank    headlessfirefox
    Go To    http://myapp-apache-1/test.html

    Click Element    id=button1
    Click Element    id=button2

    Wait Until Element Is Visible   //*[text()[contains(normalize-space(), "Button 2 clicked")]]

Any ideas? or I should resort to putting Sleep everywhere...

I've tried a bunch of various waiting solutions found here and elsewhere, but haven't found anything that works.

2
  • this is just a comment because contains only advices... the quickest solution would be to use Sleep in your test before trying to interact with the page. There are much better strategies like Wait Until Keyword Succeeds testing specific js conditions but I leave that to someone willing to share a proper answer Commented Feb 5 at 11:19
  • SeleniumTestability plugin explicitly addresses this issue but it has not been maintained for a very long time. Code is still github.com/MarketSquare/robotframework-seleniumtestability and could be easily adjusted ... Commented Mar 31 at 10:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.