Sha256: 87c8830de0f65669682c5b4b6391410946f13cb890a7544b753fe0558ecd996b

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))

describe 'Watir' do
  describe '#always_locate?' do

    before do
      browser.goto WatirSpec.url_for('removed_element.html', needs_server: true)
    end

    it 'determines whether #exist? returns false for stale element' do
      element = browser.div(id: "text")
      expect(element.exists?).to be true

      browser.refresh

      expect(element.exists?).to be Watir.always_locate?
    end

    it 'allows using cached elements regardless of setting, when element is not stale' do
      element = browser.div(id: "text")
      expect(element.exists?).to be true

      # exception raised if element is re-looked up
      allow(browser.driver).to receive(:find_element).with(:id, 'text') { raise }

      expect { element.exists? }.to_not raise_error
    end

    it 'determines whether an exception is raised when taking an action on a stale element' do
      element = browser.div(id: "text")
      expect(element.exists?).to be true

      browser.refresh

      if Watir.always_locate?
        expect { element.text }.to_not raise_error
      else
        expect { element.text }.to raise_error
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watir-webdriver-0.9.0 spec/always_locate_spec.rb
watir-webdriver-0.8.0 spec/always_locate_spec.rb