Rails3 Google Maps测试与硒 [英] Rails3 Google Maps testing with selenium

查看:199
本文介绍了Rails3 Google Maps测试与硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Rails3测试Google地图应用程式。我使用黄瓜与水豚和硒进行JavaScript测试。
我有一个地图,我等待google地图加载,然后发送一个ajax请求到我的服务器,在那里我得到的位置,我插入到地图。
我想知道是否可能与硒等待,直到谷歌地图加载,对我的服务器的ajax调用完成,标记放置在地图内。另一个问题是,如何在谷歌地图中选择这个标记。是否有任何选择器?

I'm trying to test a google maps app with Rails3. I'm using cucumber with capybara and selenium for javascript testing. I have a map where I wait for google maps to be loaded, and then send an ajax request to my server, where I get locations that I'm inserting into the map. I'm wondering if it's possible with selenium to wait until google maps is loaded, the ajax call to my server is finished and the marker are placed inside the map. The other issue is, how to select this marker within google maps. Are there any selectors?

或者我应该使用其他方式,并使用一个JS测试框架,如Jasmine来测试我的类是否加载等。我没有Jasmine的过期日期,所以可以测试一个google地图吗?

Or should I go the other way, and use a JS testing framework like Jasmine to test if my classes are loaded and so on. I don't have any expirience with Jasmine, so is it possible to test a google maps?

也许有人知道一个解决方案,或者如果它不可能的提示,一个解决方法或...;)

Maybe someone knows a solution, or a hint if it's not possible, or a workaround or... ;)

thx这么多,对这个伟大的社区;)
tux

thx so much, to this great community ;) tux

[UPDATE 1]


我找到了如何在Google地图中选择标记。如果您查看 googles硒测试,你可以看看他们在做什么。例如选择标记:

I've found out how to select markers in google maps. If you look at googles selenium tests you can check out what they are doing. For example selecting a marker:

waitForElementPresent   xpath=//img[contains(@src,'marker')]

但这里有下一个问题。如何选择特定标记?在javascript google maps API中有一种方法来为它分配一个ID,以便我可以使用#marker_1 #marker_2 ...?

But here comes the next problem. How do I select a specific marker? Is there a way inside the javascript google maps API to assign an ID to it, so that I can use #marker_1, #marker_2...?

另一个奇怪的事情是,函数 wait_for_element wait_for_condition 在我的黄瓜步骤定义中不可用。是谷歌selenium测试使用自己的函数像 waitForElementPresent ?还是这个标准的硒功能?我发现很多帖子,他们总是使用像

And another strange thing is, that function like wait_for_element or wait_for_condition aren't available inside my cucumber step definitions. Are the google selenium tests using own function like that waitForElementPresent? Or are this standard selenium functions? I've found a lots of posts, where they always use something like

selenium.wait_for_condition
selenium.wait_for_element

or

@selenium.wait_for_condition
...


b $ b

在我的步骤中定义 selenium @selenium var a nil。如何访问此方法?我还发现这 post < a> ,但它是从08年10月,所以我认为必须有一个更好的解决方案(btw。这个解决方案工作的一见钟情)。

Inside my step definitions the selenium and the @selenium var a nil. How can I access this methods? I've also found this post, but it is from Oct. '08, so I think there must be a better solution (btw. this solution works on the first sight).

像这样 ,它们概述了几个selenium方法如何等待条件或元素。这是否仍然存在?如何使用此功能?

Like on this page, they give an overview of a few selenium methods how to wait for a condition or element. Is this still present? How can I use this functions?

问候,
tux

regards, tux

[UPDATE 2 ]

我发现,我上面提到的硒测试是针对谷歌地图的V2,而不是针对V3。我尝试过

Damn it, I've found out, that the selenium tests I mentioned above are for V2 of google maps, not for V3. I have tried it with

wait_until { page.has_xpath?("//img[contains(@src,'marker')]") }

但它不工作。标记在地图上可见,但我得到超时错误,因为使用这个XPath选择器它没有找到。我想知道是否通常可以从DOM中选择一个标记。

But it doesn't work. The marker is visible on the map, but I get a timeout error, because with this XPath selector it is not found. I'm wondering if it is generally possible to select a marker out of the DOM.

当我创建标记时,我还试图为它添加一个额外的属性: / p>

I also tried to assign an additonal attribute to the marker when I create it:

// marker is the marker returned by google maps after adding it to the map
$(marker).attr('id', "marker_1");

但是当我尝试使用jQuery选择器访问它 $(# marker_1),它找不到它。因此,仍然没有解决方案。

But when I try to access it with the jQuery selector $("#marker_1"), it doesn't find it. So, still no solution, yet.

推荐答案

我用我的做法是执行你的步骤定义中的调用,

What I do with mine is to execute the calls in your step definitions like so:

page.execute_script(launchmap())

page.execute_script("launchmap()")

然后检查其是否存在于页面中。然后做你正常的ajax检查capybara。标记将包含在div中吗?那么如果你调用launchmap和创建标记,capybara应该能找到你的标记

then check for their existence in the page..then do your normal ajax check in capybara. the marker will be contained in a div right? then if you call launchmap and create the markers, capybara SHOULD be able find your markers

UPDATE

找到了有关此插件的信息: http://vigetlabs.github.com/jmapping/examples /

found out about this plugin: http://vigetlabs.github.com/jmapping/examples/

它会为您的Google地图(适度降级)提供语义标记,允许您使用capybara实际检查标记是否存在。希望它有帮助(没有时间测试,但它看起来很有前途)

it gives you semantic markup for your google maps(for graceful degradation) allowing you to actually check if a marker exists using capybara. hope it helps(dont have time to test it but it looks promising)

这篇关于Rails3 Google Maps测试与硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆