How to Test Javascript Dialogs: Alert, Confirm, Prompt.
Javascript dialogs (alert, confirm and prompt ) are not part of the browser's DOM, so their actions and events cannot be recorder or executed in a regular way. However, there are a series of special commands to manage the three types of javascript dialogs:
Alert
alert() dialogs have a single ok button, and no choice is given. Right after the action (clicking on a link or a button ) that triggers the alert, you need to acknowledge and close it. You can do this with the command:
click | copado=button:Show an alert | |
verifyAlert | * |
The parameter "*" means "any text", and will match any text shown in the dialog.
Confirm
confirm() dialogs have two buttons, typically ok and cancel.
If you need to make a choice between the two actions, you need to add one of the following commands before the action that will open a dialog, and acknowledge the confirm() dialog afterwards:
chooseCancelOnNextConfirmation | ||
click | copado=button:Show a confirm | |
verifyConfirmation | * |
The choice is optional. You can omit chooseOkOnNextConfirmation/chooseCancelOnNextConfirmation, and by default the dialog will be closed by clicking on OK.
Prompt
prompt() dialogs have two buttons, typically ok and cancel, and the user can enter some text in it.
In order to enter the text, you need to add answerOnNextPrompt before the action that will open it.
answerOnNextPrompt | 10 | |
click | copado=button:Enter a number | |
verifyPrompt | * |