san650 / ember-cli-page-object

This ember-cli addon eases the construction of page objects on your acceptance and integration tests
http://ember-cli-page-object.js.org/
MIT License
275 stars 90 forks source link

[Feature Request] Add a matchExactly flag to text based properties #272

Open sukima opened 7 years ago

sukima commented 7 years ago

contains and clickOnText both use text input to find elements and act on them. Currently that textual match will match any subset of the text to search for.

Discussed in the slack channel a possible solution is to add a modifier to say we want to match the exact text instead of a subset.

Example

<button>foo</button>
<button>foobar</button>
let page = PageObject.create({
  clickButton: clickOnText('button')
});
page.clickButton('foo');

The above will match both buttons.

Alternatively it could look like:

let page = PageObject.create({
  clickButton: clickOnText('button', {matchExact: true})
});
page.clickButton('foo');

Which will match only the first button.

juanazam commented 7 years ago

@sukima thanks for your request, I will try to work on this soon 😄

mum-never-proud commented 4 years ago

guys I was in need of this feature, thought of raising a pr

do let me know for any changes

tanks :)

cc: @san650

ro0gr commented 4 years ago

hm.. that's surprising to me. I believe that matchExact behavior should have been a default. But changing it now, would probably break some test suites..

ro0gr commented 4 years ago

just realized we could add support for this directly to the clickable(:

const p = create();

await p.click('Some button text');

fortunately, currently click( does not support any arguments, and I can't think of any other than a label to click on. Obviously, it would make clickOnText( action redundant.

It feels like matchExact=false behavior should not be allowed at all, cause it's non-deterministic and error prone. So I think we may not need an extra flag for that.

ro0gr commented 3 years ago

Curious, if there are any real use cases for matchExactly: false, which is the only possible behavior currently?

I'm considering a breaking change in v2, in order to make clickOnText to strictly click on exact text only.

san650 commented 3 years ago

I would guess that sometimes you get generated or random text e.g. an auto-generated id or current date so you want to match part of the label instead of the full text