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

The 'when_present' and 'present?' methods behave strangely when chained #432

Closed
pudlovich opened this issue Jul 19, 2016 · 5 comments
Closed

Comments

@pudlovich
Copy link

pudlovich commented Jul 19, 2016

In my test suite I managed to get an error:

Failure/Error: expect(b.div(class: 'fc-event').when_present.present?).to be true
       expected true
            got false

And this is not the kind of error that I expected to see, should something go wrong.
Is there some kind of timing issue between the methods, or do they somehow evaluate presence differently?
Using 'when_present.exists?' instead seems to do the trick.

@pudlovich pudlovich changed the title The 'when_present' and 'present?' methods seem to base their behaviour on different criteria The 'when_present' and 'present?' methods behave strangely when chained Jul 19, 2016
@titusfortner
Copy link
Member

This is because of this issue: https://github.com/watir/watir-webdriver/pull/216

It looks like @jarmo's suggestion essentially bypasses the when_present call when you are calling present? on the Decorator.

@jarmo
Copy link
Member

jarmo commented Jul 19, 2016

It's always nice to read things from 3 years ago and be surprised of what I've written :)

Anyway, I agree that this behavior seems strange, but so does the assertion/spec itself. Reading the spec it seems surprising that there's an assertion for element's present? after it has been waited for being present as if you don't trust the framework here (hehe).

@titusfortner seems to be right here because as I understand then method_missing is not called because delegator method is called directly, thus call to wait_until is skipped.

The really correct solution would be to destroy ActiveSupport in it's entirety, but we all know that this will not happen...

Having that in mind, maybe something like this would work:

class WhenPresentDecorator < BaseDecorator
    def present?
      Watir::Wait.until(@timeout, @message) { wait_until }
      true
    rescue Watir::Wait::TimeoutError
      false
    end

    private

    def wait_until
      @element.present?
    end
end

@titusfortner
Copy link
Member

I know exactly what my 3 year old comments often look like. :)

I think this code is right. I pushed it to a branch to make sure Travis likes it. @jarmo do you want to do a PR with that code, or would you rather I commit it?

@jarmo
Copy link
Member

jarmo commented Jul 19, 2016

Feel free to commit yourself :) Just don't forget to add spec as well ;)

@titusfortner
Copy link
Member

Merged: 9aa1ddd

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

3 participants