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.