ember-cli-page-object icon indicating copy to clipboard operation
ember-cli-page-object copied to clipboard

Provide a way of checking meta info of page object

Open yratanov opened this issue 4 years ago • 1 comments

While working on assert lib for page object I faced and issue described here.

There is no way to check if property is a property or a function without calling it, for example:

create({
  clickOnMe: clickable('a'),
  href: attribute('href', a),
});

So to check if property is a function I need to call it like this:

typeof page.clickOnMe === 'function' // true
typeof page.href=== 'function' // false

The problem with this is that we actually execute getter and if it raises an error, our check will fail.

typeof page.href === 'function' // Element not found!

Do you think it's possible to store it somehow?

yratanov avatar Feb 28 '20 02:02 yratanov

Yes, there is such a limitation currently. I believe a good way to do it would be go play around getPageObjectDefinition(. But:

  • that's private for now
  • even with that you don't have a way to distinct between props VS actions.

As a short term solution, we could mark all the current built-in action descriptors by smth like isAction: true. But that doesn't feel super optimal to me, cause on the assertions end you would need to use private getPageObjectDefinition( and private isAction, which can easily breake because of hard dependencies on private APIs.

I think we should solve it, when introducing a public way to declare a custom action. I expect it to be done in v2.

Meanwhile, I think your current approach to create assertions for actions is a good(in terms of reliability) solution for now.

ro0gr avatar Mar 02 '20 21:03 ro0gr