views:

1236

answers:

2

Is it possible to use selenium to test whether a jQuery data() is set on an element?

In my app, the user enters information about several orders. Each order gets appended to an overview table so they can see their progress as they're going. In addition to the visible order information, we store some additional information that we need about each order using an array stored in jquery.data(), like this:

$('#table').data('orders').push(neworderdata)

I'd like to write a selenium test to assert that when the user presses 'Add order', my additional data gets added to $('#table').data('orders').

I think I need something like:

Command: assertEval
Target: $('#table').data('order')[1].cust_no
Value: 99999

But I think the issue I'm having is that Selenium IDE doesn't know about the jQuery namespace, and functions, so it doesn't know how to find the table. But even if I used getElementbyID('table'), how do I get selenium to know about the data()?

+1  A: 

Are you sure that Selenium IDE is having a problem with $? I was able to access it from Selenium IDE. Perhaps something else is broken in you jQuery expression? Can you first try "assertEval $ 0" etc. to see if the IDE can evaluate $ alone?

Ates Goral
You're right...I was able to assertEval $, and it gave me back the text of the jQuery object, so it definitely could 'see' jQuery...But that makes me extra curious as to what's happening. Why can't selenium evaluate that expression?
fitzgeraldsteele
+1  A: 

I find that selenium will only see the jquery function if you access it as:

window.$(...)

not as

$(...)

Perhaps that's (part of) the problem?

Paul Biggar