How to test javascript dialogs ( alert, confirm, prompt )

Updated 2 months ago by CST

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, but 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 an alert, you need to acknowledge and close it... you can do this with the command:

clickcopado=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
clickcopado=button:Show a confirm
verifyConfirmation*

The choice is optional... you can omit chooseOkOnNextConfirmationchooseCancelOnNextConfirmation and by default the dialog will be closed by clicking 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.

answerOnNextPrompt10
clickcopado=button:Enter a number
verifyPrompt*


How did we do?