cheezy / page-object

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

Replace :text locator with RegExp values with :visible_text #480

Closed tburraston closed 5 years ago

tburraston commented 5 years ago

Small modification to a locator on the Table class to prevent Watir deprecation warnings.

jkotests commented 5 years ago

Thanks @tburraston for submitting this.

Would you be able to provide an example table that has this issue? I would like to understand if this is a Page Object problem or a Watir problem (eg throwing a deprecation warning when it shouldn't).

tburraston commented 5 years ago

Sure thing, @jkotests!

I have a quick example here:

require 'page-object'

class ExamplePage
  include PageObject
  page_url "https://codepen.io/tuberu/full/wOgPOy"

  in_iframe(id: 'result') do |table_frame|
    table(:example_table, xpath: "//table", frame: table_frame)
  end

  def student2_email
    example_table_element['Student 2'][1].text
  end
end

RSpec.describe 'example', :target => true do

  it 'gets students email' do
    visit ExamplePage do |example_page|
      sleep 5
      expect(example_page.student2_email).to eq('student2@example.com')
    end
  end
end

Run that spec against this (https://codepen.io/tuberu/pen/wOgPOy) codepen and you should see the deprecation warning appear. The codepen replicates our actual example that has hidden text for screenreader users.

Thanks for the help! 😄

jkotests commented 5 years ago

@tburraston what version of Watir are you using? I do not get a warning when using latest - v6.16.5.

I do get a warning when going back to v6.16.0. I have not quite figured out why the deprecation warning behaviour changed between these releases. However, I wouldn't expect a warning in this scenario (ie 6.16.5 seems right).

tburraston commented 5 years ago

@jkotests I see, thanks for the insight there. I'm on v6.10.0. Looks like there are even more deprecation warnings on v6.16.5 (looks like those can be resolved with your PR, though).

Sounds like the recommended path forward is to take v6.16.5, which I should be able to do provided the WARN Watir ["visible_element"] #visible? behavior will be changing slightly, consider switching to #present? messages are resolved.