Click overlay marker in Google Maps with capybara-webkit

大憨熊 提交于 2019-12-05 10:00:35

问题


Is there a way to click a Google Maps overlay with capybara-webkit? What about Capybara using Selenium? I want to test the content of the info window once the marker is selected. I also want to test that there are n markers on the page.


回答1:


To test that there are n markers on the page:

expect(find('.gmap_container')['data-markers'].split('},{').count).to eq(n)



回答2:


This can be done, but requires a change to how you create your markers. You must instruct them to render as images rather than canvas elements:

new google.maps.Marker({
  position:  latLng,
  animation: google.maps.Animation.DROP,
  name:      business.get('name'),
  id:        business.get('id'),
  optimized: false, // <-- this is the stuff
  title:     business.get('name')
});

Then in your test, you can find('div[title="Business\ Title"]').click

If possible, you might want to consider doing this just for a test environment, but that's up to you and your needs.

Credit: http://blog.mojotech.com/selecting-google-maps-v3-markers-with-selenium-or-jquery/

Hope this helps!



来源:https://stackoverflow.com/questions/15281200/click-overlay-marker-in-google-maps-with-capybara-webkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!