Accept javascript alerts does not work

Hi,
I’m recording a test with a save button. After the button is clicked the page posts data and the response contains javascript with an alert.

In the test recording I click the button and click OK on the alert. The recorder records the button click and “assertAlert” with the alert text as target.

When I play the test the assertAlert gets yellow and does not find the alert. Later it breaks with timeout.

Dear,

Thanks for the post. I have the same issue, as Katalon Studio Web Spy or Object Spy is not able to capture a simple JavaScript - alert event, to let me do proper web test automation or even load-testing with this tool. I am stock here and all forum does not mention how to handle this type of situations.

Interestingly, a lot of Katalon tutorials, talks about simple web automation, but in real web-testing scenarios, is not able to do that!

I am really shocked and could not find any help there.

Thanks and BR,
Mohee Jarada

1 Like

Are you guys using Katalon Recorder or our Object Spy? By the way , you can’t capture any alert popup from your web application, and you have to handle it manually by using some Alert keywords such as ‘Accept Alert’ or ‘Dismiss Alert’.

Alex said:

Are you guys using Katalon Recorder or our Object Spy? By the way , you can’t capture any alert popup from your web application, and you have to handle it manually by using some Alert keywords such as ‘Accept Alert’ or ‘Dismiss Alert’.

As I said in the first post the “assertAlert” command does not work. Other Commands like “acceptAlert” do also not work.

Hi Kay

First, AFAICT, acceptAlert is not available in Katalon Recorder, so don’t bother trying it.

I have never managed to get a replay of assertAlert to work, it always complains the text is wrong (even when it is perfectly correct). So until KMS fix it, I am taking those out. Do you NEED to check the text? If not, just take the step out, and do this:

chooseOkOnNextConfirmation

Good luck!
Russ

Hi everyone,

Would this sample help you https://gist.github.com/devalex88/500b2f0135d6163aa9d6e98f28c8b25d?

Could you please share some screenshots that would help with the investigation.

Hi Alex

What is that HTML file for? What am I meant to do with it? (my mind-reading powers are not so good these days).

Russ

Sorry for leaving out the description :). That sample test suite demos “assertAlert” command. If it does not work on your machines, I will investigate further.

Ah, “drag it on to KR” is what I was missing (slow brain today).

Okay, so, KR runs the script, my browser goes to the w3schools tryit app and…

Nothing happens.

The test is marked pass (all green) but no alert() appears. I tried running the test super slow too. Nothing.

With that “evidence” I’m distrustful of the result.

Did I do something wrong?

Alex - I exported the test and pasted it into Katalon Studio, same result, the alert() never appears.

I added WebUI.delay(5) after the click and before the assert: I see the button highlighted like it has been clicked but the alert dialog still does not appear.

The test says it passed. As a functional test, this is not valid.

@Russ,

The speed is fine on my machine. Could you please tell me how slow it is and for which steps?

Also, the call to alert() JavaScript function was overwritten by KR. That’s the way KR extracts the alert messages and do verification/assertion steps. That’s why you didn’t see the alert box. But the assertion was really done. You can verify by changing the text in the command and the step will fail. Also, if you add assertAlert to a test case with no alert(), KR will wait 30 seconds and mark that test case as failed.

Ah, now I understand. I think perhaps that should be given more prominence in the docs somewhere.

Thanks, Alex.

Russ

That’s a good suggestion - I will update the docs in the next release. Thank you, Russ.

@devalex88 or @Russ_Thomas
Could you please provide more detailed info on the accept javascript alert that has been talked about here.
We are facing an issue where a popup appears stating that the javascript is blocked midway during the execution.
As we execute on a headless browser with linux OS not sure what is the best solution to go ahead here to pass through this.

@Raghu

Are you talking about Katalon Recorder? If so, I can’t help you - I only use Katalon Studio.