kmancusi kmancusi - 9 months ago 30
Ruby Question

Rspec; verifying an element state when the attribute that doesn't have a value

I am doing some automation testing using Rspec and Watir.

What I currently would like to do is verify the presence of a button element's attribute titled

. So in pseudo-code I would like to do this:

Find button element; press click
Verify button element now has another attribute titled "hidden"
perform further actions

Is it possible to find attributes of this nature, or do they always need to say something like


You can use the built-in hidden? method:

<input type="submit" value="button">
#=> false

<input type="submit" value="button" hidden>
#=> true

Then, you can create an rspec example that uses an expectation to validate:

describe "Button" do
  it "should be hidden" do
    expect(browser.button.hidden?).to be true

And expect(browser.button.hidden?).to be true is clunky. As Justin Ko astutely points out, rspec provides some syntactic sugar in the form of predicate matchers to make it cleaner: expect(browser.button).to be_hidden.