Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watir 6 and selector_string #4

Closed
titusfortner opened this issue Nov 17, 2016 · 6 comments
Closed

Watir 6 and selector_string #4

titusfortner opened this issue Nov 17, 2016 · 6 comments

Comments

@titusfortner
Copy link
Owner

Gem is not properly handling usage of selector string on page objects.
Referenced here:
watir/watir#495

@titusfortner
Copy link
Owner Author

@jrmartinez03 - Ok, I took a look at this and I can't repeat it.

        page = TestPage.visit
        page.wait_until do
          page.language.exists? && page.language.set?
        end

returns this:

NoMethodError: undefined methodwait_until' for #TestPage:0x007f9f489e1350`

What do you get when you use:

page.some_element.wait_until { |el| el.exists? && el.set? }

@jrmartinez03
Copy link

Apologies @titusfortner: my page includes Watir::Wait and Watir::Waitable

require 'watir_drops'

class MyPage < WatirDrops::PageObject
  include Watir::Wait
  include Watir::Waitable

  def loaded?
    true
  end
end

WatirDrops::PageObject.browser = Watir::Browser.new :phantomjs
page = MyPage.use
page.loaded? #happy
page.wait_until { page.loaded? } #not happy

Your alternative does work.

@titusfortner
Copy link
Owner Author

Ah, so Watir::Waitable assumes self is either a browser or an element. If we were to define PageObject#selector_string it would work, but wouldn't make sense, really.

You could do either:

@browser.wait_until { page.loaded? }

or I can add this to WatirDrops::PageObject

    def method_missing(method, *args, &block)
      if @browser.respond_to?(method)
        @browser.send(method, *args, &block)
      else
        super
      end
    end

    def respond_to_missing?(method, _include_all = false)
      @browser.respond_to?(method) || super
    end

Which would let you do:

page.wait_until(&:loaded?)

@jrmartinez03
Copy link

jrmartinez03 commented Nov 17, 2016

For now, my workaround is to implement selector_string in MyPage:

require 'watir_drops'

class MyPage < WatirDrops::PageObject
  include Watir::Wait
  include Watir::Waitable

  def selector_string
    self.class.to_s
  end

  def loaded?
    true
  end
end

WatirDrops::PageObject.browser = Watir::Browser.new :phantomjs
page = MyPage.use
page.loaded? #happy
page.wait_until { page.loaded? } #happy

@titusfortner
Copy link
Owner Author

The point of selector_string is to give additional details on what the problem is.

Adding the #method_missing would give:

waiting for true condition on #<Watir::Browser:0x..fe317396416a2fce4 url="https://google.com" title="Google">

vs.

waiting for true condition on MyPage

What information would be most useful?

Also, you likely won't use this for anything directly include Watir::Wait

@titusfortner
Copy link
Owner Author

titusfortner commented Jan 7, 2017

This issue should be addressed now by delegating method_missing to Watir::Browser where defined.

Additionally, I'm pushing for changing #selector_string to #inspect in Watir, which makes a lot more sense all the way around, and remove the need to add a separate method in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants