-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backwards compatibility break v0.9.8 -> master: selectors passed into custom commands #1237
Comments
I'm not sure if this is a very common use case. I imagine that non-page custom commands aren't commonly used with @-named elements, instead I expect that page object custom commands are used like that. Are only non-page custom commands affected? Still, we shouldn't introduce breaking changes, unless it's a major release (1.0 release). Clearly this cannot be a major release, so we need to patch it to be backwards compatible. Isn't it possible to resolve the @-named string into the selector object only if it's needed (using EDIT: I can see this is not trivial, I'll look into it and see if it's worth the effort. |
I don't think its |
Page objects break custom assertions for me ( exports.assertion = function(selector, count) {
this.message = 'Testing if element <' + selector + '> has count: ' + count
this.expected = count
this.pass = function(val) {
return val === this.expected
}
this.value = function(res) {
return res.value
}
this.command = function(cb) {
var self = this
return this.api.execute(function(selector) {
return document.querySelectorAll(selector).length
}, [selector], function(res) {
cb.call(self, res)
})
}
} Is this expected behaviour? How do I rewrite that custom assertion to support page objects? |
I added this at the start of the method: exports.assertion = function(selector, count) {
if (Array.isArray(selector)) {
// combine page object CSS selectors
selector = selector.map(s => s.selector).join(' ')
}
...
} |
Hi all, seems this issue is back with Still I don't get your fix @diachedelic? The type of |
@Akaryatrh can't remember - perhaps i meant to say Array instead of object? Edit: looks like I'm handling an array of objects |
Maybe. Anyway, I'm moving away from BTW, thx for your quick answer! |
With the latest v1.0.14 this original error is not encountered anymore:
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. |
@aberonni I have such Page Object -
and using such custom command -
from such test file:
and it looks like It was working properly (selector was calculated according to section's selector) in v0.9.21. |
@qooban could you open a separate issue please regarding this? Make sure to post the verbose log as well, thanks. |
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.
Current release (v0.9.8) output:
Current master output:
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 anError 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:
The text was updated successfully, but these errors were encountered: