rubywatirwatir-webdriverpage-object-gemrspec-expectations

Check is option selected in drop down list?


I try to check is selected option realy selected in drop down list (select):

expect(page.sltMembers_element.options).to eql('John Doe')

But I get an error that expected: 'John Doe' and got: list of all options from drop down list.


Solution

  • Assuming that the sltMembers_element method is the one generated by the select_list accessor, then the page-object will have 5 methods:

    1. sltMembers returns the currently selected item text.
    2. sltMembers= selects an item.
    3. sltMembers_element returns the page-object element.
    4. sltMembers? checks if the element is present.
    5. sltMembers_options gets an array of all available options.

    As you want to check the selected option, you want to call the page's sltMembers method:

    expect(page.sltMembers).to eql('John Doe')