views:

851

answers:

5

Hi

I am wondering how do I disable javascript when using selenium so I can test server side validation.

I found this article but I don't know what to really do. Like I make this javascript file then what?

http://thom.org.uk/2006/03/12/disabling-javascript-from-selenium/

A: 

It looks like creating this file will give you the functions that you need to disable javascript for your test. You will call the "doDisableJavascript" function before you begin the test and the "doEnableJavascript" function when you want to enable it again.

shambleh
how do I call it though? Like where am I calling it from?
chobo2
with Selenium calling functions that you created would be the name of the function without the do e.g doDisableJavascript would be called from selenium with the command DisableJavascript
AutomatedTester
A: 

The steps to use the script referenced above aren't to bad:

  1. Create the selenium "user-extensions.js" file as mentioned in the article you link.
  2. Select your "user-extensions.js" file in the Selenium preferences in Options->Options.
  3. Use the script by selecting the command "DisableJavascript" or "EnableJavascript" from the command list (or just type it manually).

For screen shot examples of steps 2 and 3 see: http://i32.tinypic.com/161mgcm.jpg

Update: For information about using user-extensions.js with Selenium RC try the following URL: http://seleniumhq.org/docs/08%5Fuser%5Fextensions.html

coderjoe
Will this command show up in nunit. I write all my tests in nunit.
chobo2
I believe so? I have not tried it so I can't be sure. Try the documentation I've added to my answer for information about using user-extensions.js with Selenium RC (which I assume you're using).
coderjoe
+1  A: 

Other possibilities would be:

  • Write your application to support disabling JavaScript (yes, the web application).
    Sounds crazy? Isn't. In our development process we're doing exactly this, implementing features without JS until all are there, then spice up with JS. We usually provide a hook within all templates which can control from a single point to basically witch JS off/on from the web application itself. And, yes, the application is hardly recognizable without JS enabled, but it's the best way to ensure things work properly. We even write Selenium tests for it, for both versions; NOJS and JS. The NOJS are so quickly implemented that they don't matter compared to what it takes to write sophisticated JS tests ...
  • Modify the appropriate browser profile to have JS disabled. I.e. for FF you can tell Selenium which profile to use; you can load this profile normally, disable JS in about:config and feed this profile as default profile to Selenium RC.
mark
A: 

I followed the steps exactly as above. Created user-extensions.js file Selected the file through Selenium Preferences Typed the command manually as I was not able to see the command in the dropdown.

Please suggest.

Tom
A: 

Get the Web Developer toolbar for Firefox from http://chrispederick.com/work/web-developer/ Disable->Disable Javascript

andrem