cheezy / page-object

Gem to implement PageObject pattern in watir-webdriver and selenium-webdriver
MIT License
653 stars 220 forks source link

Can page-object handle tags under SVG? #364

Closed lgould closed 8 years ago

lgould commented 8 years ago

I tried to use element(:custom_name, :g, css: 'css_selector') to interact with a "g" element, but got an error: undefined method `g'

A main feature of the app that I'm automating are mostly Scalable Vector Graphics, which means, I'll need to interact with "g, rect, circle, text" etc. I know that page-object has a ready to use svg( ) method, I don't see others in rubydoc.info site. Can anyone advise?

Cohen-Carlisle commented 8 years ago

Can you double check your code? It sounds like you left off the : and ruby is trying to find a method named g. I,e, you wrote:

element(:custom_name, g, css: 'css_selector')
lgould commented 8 years ago

Good observation. I typed it out wrong , I actually did use ":" in front of the g, like this: element(:custom_name, :g, css: 'css_selector')

Cohen-Carlisle commented 8 years ago

I'm not able to reproduce this. I can interact with g elements in the manner in which you described. For example, if I create this class:

class Foo
  include PageObject
  element(:foo, :g, css: 'body > svg:nth-child(1) > g:nth-child(1)')  
end

It can locate the g element in this HTML:

<svg viewBox="0 0 95 50"
     xmlns="http://www.w3.org/2000/svg">
   <g stroke="green" fill="white" stroke-width="5">
     <circle cx="25" cy="25" r="15"/>
     <circle cx="40" cy="25" r="15"/>
     <circle cx="55" cy="25" r="15"/>
     <circle cx="70" cy="25" r="15"/>
   </g>
</svg>

Like this:

on(Foo).foo_element.visible?

This is using page object 1.1.1, I'm not sure what old versions are doing.

lgould commented 8 years ago

That's what I suspected. I have page-object (1.0.3) and watir-webdriver (0.6.11). May I ask what version of watir-webdriver do you have, or do you use selenium-webdriver? If you use watir, can you check if you have the following code in this file: [USER_PATH]/.rvm/gems/ruby-2.1.4/gems/watir-webdriver-0.6.11/lib/watir-webdriver/elements/generated.rb (need to replace with your ruby version and watir version accordingly in the path)

def g(*args) G.new(self, extract_selector(args).merge(:tag_name => "g")) end

def gs(*args) GCollection.new(self, extract_selector(args).merge(:tag_name => "g")) end

jkotests commented 8 years ago

Sounds like the problem is that you are using an old version of Watir-Webdriver. Support for SVG elements was not added until version 0.8.0.

lgould commented 8 years ago

I see. OK, I'll try to upgrade it to version 0.8.0 and see.

lgould commented 8 years ago

Upgrading watir webdriver to v0.8.0 solved the tags recognition issue. Except the "text" tag under the SVG group was still not defined in svg_element.rb. Has anybody used this tag successfully using the watir/page-object framework? I can monkey patch it in, but would like to hear any good suggestions from others first. Thanks.

cheezy commented 8 years ago

You can access the text method on the element itself. For example, given the code in the examples above you could call the custom_name_element method which would return a generic Element object that has a text method. This should work.

cheezy commented 8 years ago

A new release is coming out very soon that adds support for all of the missing svg elements. Take a look at git to see what is coming. g is supported as well a circle. I'm going to close this issue but reopen if you feel it needs more attention.