question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Modifying the `Cypress.SelectorPlayground.defaults - selectorPriority` breaks the Selector Playground

See original GitHub issue

Current behavior:

Modifying the Cypress.SelectorPlayground.defaults in the support/index.js file breaks the Selector Playground in the GUI.

Desired behavior:

To be able to modify/add to the selectorPriority list and still use the Selector Playground.

Test code to reproduce

If you modify the cypress/support/index.js file with this:

Cypress.SelectorPlayground.defaults({
  selectorPriority: [
    "data-qa",
    "data-test",
    "data-cy",
    "id",
    "class",
    "name",
    "tag",
    "attributes",
    "nth-child",
  ],
});

The selector playground is broken and doesn’t work at all.

When I comment this block of code out, the Selector Playground works normally.

This issue helped me figure out where to modify the selectorPriority: 7606

Versions

Cypress 4.7.0 and 4.8.0, MacOS, Chrome

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
dwilchescommented, Oct 15, 2021

I found a workaround, instead of using selectorPriority use onElement.

So instead of:

Cypress.SelectorPlayground.defaults({
  selectorPriority: [
    "my-attribute-1",
    "my-attribute-2",
    ...
  ]
})

Use this:

Cypress.SelectorPlayground.defaults({
    onElement: ($el) => {
        const attr1 = $el.attr("my-attribute-1");
        if (attr1) {
            return `[my-attribute-1="${attr1}"]`;
        }
        const attr2 = $el.attr("my-attribute-2");
        if (attr2) {
            return `[my-attribute-2="${attr2}"]`;
        }
        // Default behaviour
        return false;
    },
});
1reaction
madbreenacommented, Dec 3, 2020

I am facing the same issue. Will this be resolved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress.SelectorPlayground
The Selector Playground exposes APIs that enable you to: Change the default selector strategy; Override the selectors that are returned per element. Syntax....
Read more >
Cypress Selector Playground - YouTube
Today the video is on Cypress Selector Playground Cypress selector ... Once your test case is launch in your default or preferred browser ......
Read more >
cli/types/cypress.d.ts - Fossies
Selector ): boolean 703 /** 704 * Returns a boolean indicating whether an element ... 760 */ 761 SelectorPlayground: { 762 defaults(options: ...
Read more >
How To Find HTML Elements Using Cypress Locators
Cypress supports only CSS selectors out of the box for locating elements in the DOM. So in case you intend to use other...
Read more >
cypress: Versions - Openbase
An error now throws when invalid options are passed to the selectorPriority configuration option of Cypress.SelectorPlayground.defaults .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found