I am trying to test a Google Maps application with Rails3. I use capybara and selenium cucumber to test JavaScript. I have a map where I wait for Google maps to load, and then send an ajax request to my server, where I get the locations that I insert into the map. I am wondering if it is possible, when selenium will wait for Google maps to load, the ajax call to my server will be completed and the marker will be placed inside the map. Another problem is how to select this marker on google maps. Are there any selectors?
Or I need to go the other way and use JS testing like Jasmine to test the loading of my classes, etc. I have no experience with Jasmine, so can I check Google maps?
Perhaps someone knows a solution or a hint if this is not possible, or a workaround or ...;)
[UPDATE 1]
I learned how to select markers on Google maps. If you look at the tests for searching googles selenium , you can check what they do. For example, selecting a marker:
waitForElementPresent xpath=//img[contains(@src,'marker')]
But here is the next problem. How to choose a specific marker? Is there a way in the google javascript API to assign it an ID so that I can use #marker_1 , #marker_2 ...?
And one more strange thing is that functions like wait_for_element or wait_for_condition are not available inside my definitions of cucumber steps. Are selenium google tests native functions like waitForElementPresent ? Or are these standard selenium features? I found many posts where they always use something like
selenium.wait_for_condition selenium.wait_for_element or @selenium.wait_for_condition ...
Inside my step definitions are selenium and @selenium var a nil. How can I access these methods? I also found this post , but it has been since October 2008, so I think there should be a better solution (by the way. This solution works at a glance).
As on this page , they give an overview of several selenium methods, how to wait for a condition or element. Is it still present? How can I use these features?
[UPDATE 2]
Heck, I found out that the selenium tests mentioned above are for Googleβs V2 maps, not V3. I tried it with
wait_until { page.has_xpath?("//img[contains(@src,'marker')]") }
But that will not work. The marker is displayed on the map, but I get a timeout error because it was not found with this XPath selector. I am wondering if it is even possible to select a marker from the DOM.
I also tried to assign an additional attribute to the marker when creating it:
// marker is the marker returned by google maps after adding it to the map $(marker).attr('id', "marker_1");
But when I try to access it using the jQuery $("#marker_1") selector $("#marker_1") , it does not find it. So, there is no solution yet.