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

Feature request: XPath support

Open matisnape opened this issue 8 years ago • 5 comments

I'm currently looking for a framework for ember e2e tests that handles promises without waits and sleeps, but I need XPath support to be able to define more complicated page elements in page objects. For the tests not to be flaky, I can't use selectors like nth child - I rely very much on extracting the text from elements by using helpers like contains, following, logic operators and node functions - I use a lot of items from this cheatsheet http://ricostacruz.com/cheatsheets/xpath.html.

Examples of my elements: //td//*[contains (text(), '" + field_name + "')]/../.. (field_name is passed as a param in function) //td//*[contains (text(), 'name')]/../../following::td//option[@value='response." + el_name + "'] (el_name passed as a param in function) //div[contains(@class, 'wysiwyg-creator-column') and not(contains(@class, 'ng-hide'))]//button[@ng-click='createNewElement()']/..

Overall, XPath is more versatile than CSS. It would be awesome if it could be supported. Thanks!

matisnape avatar Sep 05 '16 17:09 matisnape

You could try my test recorder which will generate the paths.

quantuminformation avatar Aug 29 '17 15:08 quantuminformation

@QuantumInformation thanks, but I know how to find paths, I'd just like to make them less brittle and no recorder will help me with this if xPath is not supported :)

matisnape avatar Aug 31 '17 07:08 matisnape

Whats the attraction with XPath, first time I've heard that css selectors weren't up to the task.)

quantuminformation avatar Aug 31 '17 08:08 quantuminformation

Finding elements by the visible text allows us to write tests that find the elements in the same way that the user does. This is one of the guiding principles of testing library. It would be nice to be able to do this with ember-cli-page-objects. XPath is a way to do this.

This way the test depends less on the implementation of the component/thing/whatever and more on what the user sees/uses.

One way to solve this could be to allow us to send in an element rather than a selector so we can use whichever selecting method we want :)

emattias avatar Nov 30 '21 14:11 emattias

I think this can help https://github.com/san650/ember-cli-page-object/issues/567

ro0gr avatar Jan 30 '22 16:01 ro0gr