js0823
js0823

Reputation: 1873

How do I use Selenium IDE on Firefox to test JavaScript generated codes?

I am trying to test a website which contains alot of javascript. Javascript does alot of opening new dialog to let user choose "yes" or "no". It also has a function to upon right clicking, it opens up a right click menu which contains many functions such as zip, delete etc.

In Selenium, I can use the Selenium IDE to login, click, and others, but I don't know how to test those functions.

I've read there are codes I can write such as in Java to run the test, but I'm hoping to make it work by using the simple Selenium IDE if possible. If not, then can someone post a simple testing code which works to run java scripts? Such as click button -> javascript menu pops up -> click ok on the pop up.

Thank you very much.

Upvotes: 0

Views: 4322

Answers (2)

JustBeingHelpful
JustBeingHelpful

Reputation: 18980

Right context menus can be a little tricky. I'd suggest making custom commands for the right click context menu. Add the code from this article to your custom user-extensions.js file.

http://old.nabble.com/How-to-recognise-right-click-of-the-mouse-in-IDE-td14913052.html

The parameters for these functions in these commands become the expected arguments of your Selenium IDE commands. If you really want to make it simple, you can just call your javascript functions in these custom user-extension commands. :-) That might be a bit lazy and isn't truely testing what your right click is doing, but it would work.

Option #1 - if using IDE:

Specify the user-extensions.js file under Selenium IDE > Options (menu) > Options (menu option) > General Tab, then browse to your file under "Selenium Core Extensions".

Option #2 - if using Selenium RC Server:

If you're not using the IDE and using Selenium RC server with a client driver (like JUnit for example), you must specify the path of the *.js file with the -userExtensions parameter when you start the Selenium RC Server on the command line. But you said you just wanted to use the IDE, so I'd ignore this. It takes quite a bit of other setup to use the Selenium RC server.

java -jar selenium-server.jar -userExtensions user-extensions.js

=======================

I've never done this before, so I made the following custom command (JavaScript function) in my custom user-extensions.js file, and it worked well for me. I had to exit and restart the IDE before it found it. For some reason, you type everything after the "do" in the "Command" field in the IDE. It looks like it also added a "customAlertAndWait" to the IDE as well.

Code in user-extensions.js file:

Selenium.prototype.doCustomAlert = function(sTarget, sValue) { alert('Target: ' + sTarget + ' ... Value: ' + sValue); };

Selenium IDE command details:

Command: customAlert
Target: custom alert target
Value: custom alert value

Upvotes: 1

Brian Hoover
Brian Hoover

Reputation: 7991

The selenium IDE has a lot of tools to verify that specific elements are present and that the value is correct.

To set something up, you would create a test case, and start to record it. When you get to a page where you have to verify that something exists, right click on that element, and you will see a lot of Selenium commands tagged at the bottom of the click menu, such as "VerifyTextPresent" or "verifyValue" or "verifyElementPresent" When you select those commands, they will appear in your test case, and will fail if the verification fails.

Upvotes: 0

Related Questions