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

"alert text" gives "Unhandled alert: alert must be confirmed or dismissed before test can continue. Alert text: ..etc..." #634

Open
pvbemmelen62 opened this issue Apr 12, 2024 · 6 comments

Comments

@pvbemmelen62
Copy link
Contributor

I have a script that tests a webapplication.
It tests that the webapplication generates the correct alerts when input doesn't meet the requirements of the webapplication.

image

Sometimes the command "alert text" , that gets the expected alert message , generates an "Unhandled alert" error; see screenshot.
Why does Fitnesse generate that error ? Surely the "alert text" command expects an alert to be present .

The script uses IndWebBrowser that it is a subclass of WebBrowser, that is a subclass of BrowserTest . The subclasses of BrowserTest do not override alertText() .

@fhoeben
Copy link
Owner

fhoeben commented Apr 12, 2024

I don't know. Maybe you can check with a debugger what is happening exactly (where this error is being raised in code).
Getting the alert text of course expects the alert to be present.

Maybe some generic handling (which is active before or after the actual alertText method) throws this error? I've had similar issues in the past when I created subclasses where I forgot to take into account alert handling. It could be something from the subclasses of BrowserTest that are being used, or something in BrowserTest itself.

Given that error only occurs sometimes makes it very hard to track down. Without some additional details I'm afraid I won't be able to help you

@pvbemmelen62
Copy link
Contributor Author

I've searched the source code from hsac-fitnesse-fixtures , and found only lines that catch an UnhandledAlertException (in BrowserTest.java and AllFramesDecorator.java), but no lines that throw such an exception .

I have the feeling that the webdriver throws an UnhandledAlertException when it shouldn't. I don't see how generic handling before or after the actual alertText method would be responsible for throwing such an alert; nor do see a reason for such generic handling code to intercept an UnhandledAlertException in case of an alertText method.

On page https://www.w3.org/TR/webdriver2/#user-prompts it says:

When a user prompt appears, it is the task of the subsequent command to handle it. If the subsequent requested command is not one listed in this chapter, an unexpected alert open error will be returned.

image

The command "Get Alert Text" is allowed when an alert is present. So no "unexpected alert open error" should be generated.

What should I do to confirm that the webdriver is the root cause ? Maybe show in the W3C Protocol data that the browser driver generates an "unexpected alert open error" when it shouldn't ?
Webpage https://www.browserstack.com/guide/architecture-of-selenium-webdriver , section Architecture of Selenium 4 WebDriver , shows the W3C Protocol connecting "Selenium Client Libraries" and "Browser Drivers" .
Maybe I can set a breakpoint somewhere in the Selenium Client Library .

@tcnh
Copy link
Contributor

tcnh commented Apr 16, 2024

Does executing this snippet:

|script|browser test                                        |
|open  |https://the-internet.herokuapp.com/javascript_alerts|
|click |Click for JS Alert                                  |
|show  |alert text                                          |
|confirm alert                                              |
|click |Click for JS Confirm                                |
|show  |alert text                                          |
|confirm alert                                              |
|click |Click for JS Prompt                                 |
|show  |alert text                                          |
|dismiss alert                                              |

Give you the same exception in some cases?

In terms of setting breakpoints, I would start at get alert text and step into the selenium code from there

@pvbemmelen62
Copy link
Contributor Author

I ran the snippet 20 times, and never got the "Unhandled alert" .

@pvbemmelen62
Copy link
Contributor Author

pvbemmelen62 commented Apr 17, 2024

Is it possible to set the log level of the webdriver ?
That might shed some light onto the problem.

https://www.selenium.dev/documentation/webdriver/browsers/edge/
shows java system properties
EdgeDriverService.EDGE_DRIVER_LOG_PROPERTY
and
EdgeDriverService.EDGE_DRIVER_LOG_LEVEL_PROPERTY

I've tried these with command that starts FixtureDebugTest.main . That didn't work. The log file location doesn't get written to.

And I've tried these as value for COMMAND_PATTERN at the top of the test script:

!define COMMAND_PATTERN {java -DEdgeDriverService.EDGE_DRIVER_LOG_PROPERTY=C:\Users\PBEMMELE\paul\tmp\FixtureDebugTest\log.txt -DEdgeDriverService.EDGE_DRIVER_LOG_LEVEL_PROPERTY=ALL -cp %p %m}

Doesn't work either: the log file doesn't get written to.

@pvbemmelen62
Copy link
Contributor Author

From looking at code from https://github.com/SeleniumHQ/seleniumhq.github.io/tree/trunk/examples/java
I found the correct command :
!define COMMAND_PATTERN {java -Dwebdriver.edge.logfile=C:\Users\PBEMMELE\paul\tmp\FixtureDebugTest\log.txt -Dwebdriver.edge.loglevel=all -cp %p %m}

The hope is, that the log file will provide some clue when the Unhandled alert arises.

I'm not sure how to make sense of the contents of the log file; it contains many lines, and I guess I'll have to look up the protocol for DevTools WebSocket .
And use grep to look at specific lines .
For example, for the test snippet suggested by tnch 5 days ago, that opens https://the-internet.herokuapp.com/javascript_alerts , I got the following lines when using some grep command:

pbemmele@V2W1-PBEMMELE /cygdrive/c/git/seleniumhq.github.io-trunk/examples/java/src/test/java $ wc !$ wc "C:\Users\PBEMMELE\paul\tmp\FixtureDebugTest\log.txt" 4417 18069 351047 C:\Users\PBEMMELE\paul\tmp\FixtureDebugTest\log.txt pbemmele@V2W1-PBEMMELE /cygdrive/c/git/seleniumhq.github.io-trunk/examples/java/src/test/java $ grep -A1 -B1 "using" "C:\Users\PBEMMELE\paul\tmp\FixtureDebugTest\log.txt" [1713717717.236][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "link text", "value": "Click for JS Alert" -- [1713717717.264][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//a[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Alert']]" -- [1713717717.287][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//button[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Alert']]" -- [1713717717.569][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "link text", "value": "Click for JS Confirm" -- [1713717717.594][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//a[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Confirm']]" -- [1713717717.612][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//button[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Confirm']]" -- [1713717717.766][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "link text", "value": "Click for JS Prompt" -- [1713717717.792][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//a[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Prompt']]" -- [1713717717.817][INFO]: [d9400923de8854e97989896069bb2098] COMMAND FindElements { "using": "xpath", "value": ".//button[descendant-or-self::text()[normalize-space(translate(., ' ', ' '))='Click for JS Prompt']]" pbemmele@V2W1-PBEMMELE /cygdrive/c/git/seleniumhq.github.io-trunk/examples/java/src/test/java

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

No branches or pull requests

3 participants