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.

Backwards compatibility break v0.9.8 -> master: selectors passed into custom commands

See original GitHub issue

When a custom command (non-page command) is used from a page object using a @-named element reference, the v0.9.8 behavior will pass in the selector string when the new (current master) behavior passes in the element object.

// custom-commands/customCommand.js
exports.command = function (selector) {
  this.perform(function () {
    console.log('Selector:', selector); // see outputs below...
  });
};
// page-objects/myPageObject.js
module.exports = {
    elements: {
        simple: '.simple'
    },
    commands: []
};
// tests/test.js
module.exports = {
  test: function (browser) {
    browser.page.myPageObject().customCommand('@simple');
  },

  'after': function (browser) {
    browser.end();
  }
}

Current release (v0.9.8) output:

Selector: '.simple'

Current master output:

Selector: { name: 'simple',
  selector: '.simple',
  locateStrategy: 'css selector',
  parent:   { ...
}

If you’re just passing this value along to native commands, its fine. But if you’re doing more, for example expecting this to be a string for some other usage, then you’re going to have problems.

We had a custom command which passed this value along to an execute() which produced an Error while running execute command: Converting circular structure to JSON error because it was no longer passing a simple string, instead passing the entire element object which was causing some havoc.

While a compatibility break, this behavior is a necessary evil to allow the element’s own locateStrategy to be passed along with the selector without affecting the global locateStrategy which is part of the encapsulation capabilities of the feature.

Workaround:

// custom-commands/customCommand.js
exports.command = function (selector) {
  // for old behavior:
  selector = typeof selector === 'object' ? selector.selector : selector;
  // ... and maybe call useCss() or useXpath() if going between those strategies based on selector
  // ...
};

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
beatfactorcommented, Jan 3, 2019

@qooban could you open a separate issue please regarding this? Make sure to post the verbose log as well, thanks.

1reaction
aberonnicommented, Nov 25, 2018

With the latest v1.0.14 this original error is not encountered anymore:

We had a custom command which passed this value along to an execute() which produced an Error while running execute command: Converting circular structure to JSON error

Now the behaviour has been changed with this new release, and I have documented this breaking change here: https://github.com/nightwatchjs/nightwatch/wiki/Migrating-to-Nightwatch-1.0#custom-commands

I think we can now close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Backward Compatible (Backward Compatibility)?
Backward compatible (also known as downward compatible or backward compatibility) refers to a hardware or software system that can successfully use interfaces ...
Read more >
node_modules/mongodb/HISTORY.md · master · nateg98 / Blabber ...
cursor: allow $meta based sort when passing an array to sort() (f93a8c3) ... GridStore issue caused by Node 8.0.0 breaking backward compatible fs.read...
Read more >
Changelog — documentación de Python - 3.7.14 - Python Docs
bpo-47138: Pin Jinja to a version compatible with Sphinx version 2.3.1. ... bpo-37627: Initialize the Customize Run dialog with the command line arguments ......
Read more >
The biblatex Package - CTAN
fully backwards compatible with the standard biblatex package but is ... The types in this section are similar to the custom types @custom[a--f],...
Read more >
1.1.7 (core) / 0.17.7 (libraries) - Dagster Docs
New documentation for dagster-airflow on how to start writing dagster code from an airflow background. 1.1.6 (core) / 0.17.6 (libraries)#. New#. [dagit] ...
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