tags:

views:

272

answers:

1

Hello.

I'm doing some drag and drop js testing with selenium-client. It works (taking screengrabs before and after clearly show the elements to switch places), but I'm having trouble programatically asserting the change happened.

Am I mental, or can I not do something like:

selenium.assert_equal("css locator", "expected id of element")

which, in this case, would look something like:

selenium.assert_equal("css=li:nth-child(1)", "li#list_item_2")

Any tips on how to implement this would be great.

Thanks,

Adam

Edit: if I had selenium.get_element that would take a selector and return what it was, I could then perform the assertion in the next step.

i.e.

element = selenium.get_element("css=li:nth-child(1)")

assert_equal(element, "li#list_item_2")

(I think).

+3  A: 

Your example won't work because you're comparing two strings that aren't equal. One way to assert that your element has moved would be to use isElementPreset as demonstrated below:

//before drag and drop
assertTrue(selenium.isElementPresent("css=#source li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#target li:nth-child(1)"));

//drag and drop code here
...

//after drag and drop
assertTrue(selenium.isElementPresent("css=#target li:nth-child(1)"));
assertFalse(selenium.isElementPresent("css=#source li:nth-child(1)"));

This example uses the Java client API, but it should be easy to work out how to do it in your preferred client API. It will also depend heavily on your application, as the above will check that the element with id of 'target' has one child li element before the drag and drop, and none afterwards. If you have a snippet of your HTML source I might be able to prove a more robust example.

Dave Hunt