18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
Issue working with _expectConfirm() API
Hi Sumitra,
I'm facing the same problem mentioned by users girija and spark164 in this post.
_expectConfirm is not working for me. I tried the method given by you in last post.
In my app, when I deactivate a user by unchecking the check box it gives an alert "Do you want to deactivate user?" with Ok and Cancel buttons.
If i do recording by selecting Ok, it generates the code
_expectConfirm("Do you want to deactivate user?", true);
and for selecting cancel it generates the code
_expectConfirm("Do you want to deactivate user?", false);
But when I play back, both statements are doing the same action, it selects OK only.
Another thing I observed is if i don't use the _expectConfirm statement or if i use a wrong alert message in _expectConfirm, then also it is passing the test. Irrespective of the usage of _expectConfirm it is always selecting Ok in playback and always passing the test.
Please help me with this.
Browser: FF 3.6.24
Sahi version: V3.5
Regards,
Anoop.
I'm facing the same problem mentioned by users girija and spark164 in this post.
_expectConfirm is not working for me. I tried the method given by you in last post.
In my app, when I deactivate a user by unchecking the check box it gives an alert "Do you want to deactivate user?" with Ok and Cancel buttons.
If i do recording by selecting Ok, it generates the code
_expectConfirm("Do you want to deactivate user?", true);
and for selecting cancel it generates the code
_expectConfirm("Do you want to deactivate user?", false);
But when I play back, both statements are doing the same action, it selects OK only.
Another thing I observed is if i don't use the _expectConfirm statement or if i use a wrong alert message in _expectConfirm, then also it is passing the test. Irrespective of the usage of _expectConfirm it is always selecting Ok in playback and always passing the test.
Please help me with this.
Browser: FF 3.6.24
Sahi version: V3.5
Regards,
Anoop.
This discussion has been closed.
Comments
Make sure that you use _expectConfirm(label, false); before the statement which triggers the confirm dialog.
Here is an example which works for me:
Regards
Sumitra
I am using _expectConfirm(label, false) only. The example URL you gave works fine, but our app doesn't work.
Here is my script. When playback, it select "Ok" and deactivates the user instead of selecting Cancel. Also it failed the assertion even though the alert mentioned in script is correct. If i don't user the assertion the script will show as passed.
Here is what the log shows.
Starting script
_uncheck(_checkbox("checkStatus",_near(_cell("testuser")))); at Jan 19, 2012 10:42:45 AM
_expectConfirm("Do you want to deactivate the testuser user account?", false); at Jan 19, 2012 10:42:45 AM
_assertEqual("Do you want to deactivate the testuser user account?",_lastAlert());
Assertion Failed.
Expected:[Do you want to deactivate the testuser user account?]
Actual:[null] at Jan 19, 2012 10:42:55 AM
Stopping script
I observed another thing. I think this could be the actual issue.
From playback screen in the controller, after i the load page and selected the script name I pressed "Set" button. The page auto refreshed.
After doing this, when I uncheck/check the check box manually also, it was directly deactivating/activating the user without showing the alert. So, i think during playback also it doesn't popup the alert and it directly does an "Ok" operation. That's why assertion also failed. Before doing a "set" popups are showing properly in the page.
Is it a bug in the tool or I need to do something else to get it working?
Regards,
Anoop.
You will have to use:
_expectConfirm("Do you want to deactivate the testuser user account?", false); // should be mentioned before the confirm dialog is triggered.
Therefore, try using:
_expectConfirm("Do you want to deactivate the testuser user account?", false);
_uncheck(_checkbox("checkStatus",_near(_cell("testuser"))));
Check if this solves your issue.
Also, during playback you cannot see the confirm dialog and therefore you can use _expectConfirm() API .
Regards
Sumitra
If i want to assert the same confirmation alert can i use _lastAlert() ?
_assertEqual("Do you want to deactivate the testuser user account?",_lastAlert());
shows assertion failed. Assertion statement was given after the statement which triggers the confirm dialog.
Also if use a wrong alert (which is not present in the app) in _expectConfirm() the script doesn't fail, it will select "ok" by default (if the _expectConfirm statement not present also). Is that the expected behavior?
Regards,
Anoop
This is for your information:
_expectConfirm() should be mentioned before the confirm dialog is triggered and the assertEqual should be given after the confirm dialog is triggered as you will be asserting on the confirm dialog's message.
If the message in the confirm dialog is wrong then the script will fail. In the above example mentioned by me works fine for a wrong message in the confirm dialog.
Could you please point us to an example so that i can help you to come out of this issue.
Regards
Sumitra
Now about using a wrong confirmation message _expectConfirm().
Lets consider the same example you have pointed out. Here I have used a wrong alert message in the script, still the script is 100% pass for me.
Here is the log
Starting script
_navigateTo("http://www.pms.ifi.lmu.de/mitarbeiter/ohlbach/multimedia/JAVASCRIPT/javascript2.html#1"
_expectConfirm("Wrong alert message entered here?",true); at Jan 19, 2012 12:37:55 PM
_click(_button("Click here>>")); at Jan 19, 2012 12:37:56 PM
_assertEqual("Good!",_lastAlert()); at Jan 19, 2012 12:37:56 PM
Stopping script
Could you try with the following code:
Check if this solves your issue.
Regards
Sumitra
The issue which i was trying is resolved when i used the _expectConfirm before the triggering event as u suggested.
I was tying to understand handling a wrong confirmation message used in _expectConfirm as script was not failing just because of the reason that the alert is wrong. In your above post script fails because the _assertEqual statement is given before the click event where as the alert will be displayed only after the click.
In future if the confirm alert in the webpage changes, the script won't fail for that reason.
I overcame this situation by adding one more assert using _lastConfirm() API to get the script failed if the confirm alert is different. Now it works fine.
Thanks for helping.
Regards,
Anoop