Selenium IDE Example- Disabling or enabling JavaScript when running your test

JavaScript is the most important component of software web application. Developers generally using JavaScript to generate alert, to generate confirmation message, to handle client side validation etc.. If you will disable JavaScript of your browser then you will not get alert message or confirmation message or client side validation message on your action.

Let we take one example. Supposing you form is validated from client side as wel server side. Now If you want to test server side validation of form then first of all you need to disable JavaScript of your web browser manually. How can you do it in selenium IDE?

Selenium IDE does not have any built in command to disable javascript. For that you need to attach external user extension with selenium IDE. It will create two new commands "disableJavascript" and "enableJavascript" for selenium IDE. Download this user extension and save it as 'Userextension-disablejavascript.js' in your hard drive and then attach it with selenium IDE and then restart selenium IDE. CLICK HERE to view steps of - how to attach user extension file with selenium IDE. Now you are ready to use "disableJavascript" and "enableJavascript" command.

"disableJavascript" Command
"disableJavascript" command will disable the javascript support of your web browser Mozilla Firefox.

"enableJavascript" Command
"enableJavascript" command will enable the javascript support of Firefox.

Let we take simple example of both these commands.

New Test
verifyConfirmationPress 'OK' or 'Cancel' button!
verifyConfirmationPress 'OK' or 'Cancel' button!
verifyConfirmationPress 'OK' or 'Cancel' button!

CLICK HERE to view all examples of extending selenium ide using user extension files.

Run above example in selenium IDE. Before execution of "disableJavascript" command, "verifyConfirmation" command will pass but after execution of "disableJavascript" command, "verifyConfirmation" command will fail because selenium will not see any alert message due to the disabled JavaScript of browser. Once again, Last command "verifyConfirmation" will pass because selenium will enable JavaScript of browser using "enableJavascript" command.

Reference :  Thom Lawrence

No comments:

Post a Comment