Can not Handle two consecutives alerts

Hi, All my test that has double alerts are failing/unstables on jenkins. Locally they are working.

We are using robotframework == 4.1.1 , robotframework-browser == 8.0.2

The problem i think is that the promise of the second alert is being set up late and the alert is already visible in the UI.

The first alert is this one and is being handle by this keyword:

Confirm Operation With Dialog
[Arguments] ${action} ${text} ${button_path}
${promise}= Promise To Wait For Alert action=${action} text=${text}
Click xpath=${button_path}
${alert}= Wait For ${promise}

and is being handle by this keyword:
Alert Message Should Be
[Arguments] ${action} ${text}
${promise}= Promise To Wait For Alert action=${action} text=${text}
${alert}= Wait For ${promise}

but for me the reason is failing is that the promise is settled after the alert is visible.

The error from jenkins:

###Error Message

Keyword ‘Alert Message Should Be’ failed after retrying 2 times. The last error was: TimeoutError: page.waitForEvent: Timeout 20000ms exceeded while waiting for event “dialog” =========================== logs =========================== waiting for event “dialog” ============================================================

The possible solution that I tried is to set 2 promise before the first alert is triggered like this:

${promise}= Promise To Wait For Alert action=accept text=Approve request for [068556] 68556, TEST?
${promise2}= Promise To Wait For Alert action=accept text=Request Hours exceed available hours. [20.00]
Click xpath=${button_path}
${alert}= Wait For ${promise}
${alert2}= Wait For ${promise2}

but this doesn’t works because is taking the first promise text when should be the second promise

Failing LOG:
${alert2} = Browser . Wait For ${promise2}
FAIL Alert text was: “Approve request for [068556] 68556, TEST?” but it should have been: “Request Hours exceed available hours. [20.00]”

Is like can’t create to promise at once then use one continues and use the second one

If someone can help with this :slight_smile:

Thanks

1 Like

This could true, but first update to the latest Browser library release. If you still able to reproduce the problem, please raise an issue, event better if the issue has an example which we all can run.

Hello, I noticed same issue long time ago and I was willing that it will be resolved within next Browser releases but it still occurs.

ENV:

Win 11 E
Python 3.11.9
NodeJS v20.15.1
Browser library 18.6.3
Robot Framework version: 7.0.1
Playwright 1.45.0

I’ve created simple html page with two alerts and simple RFB script where you can easily debug this issue. Manually alerts are visible and interactive. RFB scripts fails as its not able to handle multiple alerts. Please check below example manually vs via script.

index.html





Multiple alerts issue - example


Click to show alerts

    <script>
        function showAlerts() {
            confirm("First alert accepted?");
            alert("Second alert!");
        }
    </script>
</body>
</html>

example.robot
*** Settings ***
Library Browser

*** Test Cases ***
Alert-Debug
    Browser Setup
    #provide correct index.html path below
    Go To    C:/alert_demo/index.html
    Click    //button
    Validate Alert Response    First alert accepted?
    Validate Alert Response    Second alert!

*** Keywords ***
Browser Setup
    Set Browser Timeout    30
    New Browser     browser=chromium     headless=false    args=["--start-maximized"]
    New Context    viewport=${None}
    New Page        url=about:blank

Validate Alert Response
    [Arguments]     ${messageValue}
    ${message} =    Wait For Alert    action=accept    text=${messageValue}    timeout=5

Actual failure message:

TimeoutError: page.waitForEvent: Timeout 5000ms exceeded while waiting for event “dialog”
=========================== logs ===========================
waiting for event “dialog”

Tip: Use “Set Browser Timeout” for increasing the timeout.

html.index (issue with code in org post)

<html lang="pl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multiple alerts issue - example</title>
</head>
<body>
    <button onclick="showAlerts()">Click to show alerts</button>

    <script>
        function showAlerts() {
            confirm("First alert accepted?");
            alert("Second alert!");
        }
    </script>
</body>
</html>

Sorry bro i van hice you updates about this topic, I have changed of employer and now I’m working in other langueaje and framework.