mattrock
mattrock

Reputation: 47

Watir Check Text exists

I get it not the Watir in conjunction with rspec find my text. The following code leads to this error.

  1. Code:browser.text.include?("Coverberechnung").should == true
  2. Error1: expected: true got: false (using ==)
  3. Error2: Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead. Called from

Maybe I can have a help

URL for the Site: enter link description here

Upvotes: 3

Views: 10134

Answers (4)

orde
orde

Reputation: 5283

You're looking for an initially-capitalized string (i.e. Coverberechnung), but that string is all-capitalized on the test site (i.e. COVERBERECHNUNG).

Try:

browser.text.include?("COVERBERECHNUNG").should == true

or (using expect syntax)

expect(browser.text.include?("COVERBERECHNUNG")).to be true

Upvotes: 5

Christopher Chant
Christopher Chant

Reputation: 11

I prefer to use expect(browser.text).to include('coverberechnung')

Upvotes: 1

R Hope
R Hope

Reputation: 26

Or you can just do the following:

fail unless @browser.text.include? 'COVERBERECHNUNG'

Or if you want to target that exact string, you could do the following instead:

@browser.h1(text: 'COVERBERECHNUNG').wait_until_present

This code will raise an exception after 30 seconds (thus, failing your test in the process) if it can't find a header element with the text: 'COVERBERECHNUNG'. You can also override the waiting or polling process by doing the following:

@browser.h1(text: 'COVERBERECHNUNG').wait_until_present(10)

That code will check that h1 element within 10 seconds.

Upvotes: 0

EBooker
EBooker

Reputation: 374

If I wanted to be indifferent about case I would do something like this:

browser.text.upcase.include?("COVERBERECHNUNG").should == true

or

browser.text.downcase.include?("coverberechnung").should == true

this way you can avoid text comparison that may have varying cases.

also for you last problem #3: use

expect(browser.text.downcase.include?("coverberechnung")).to be true

they deprecated that version some time ago. so you can give this one a try with no issue.

NOTE: only one caveat is that this will ignore case. As described above.

Upvotes: 0

Related Questions