-
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
Page object command callbacks using element references do not use API context #1048
Comments
…ent page callback wrapping
Hi @senocular , I think I got a problem related to this, could you have a look and verify if it is the problem you are going to fix. When I use When I test This really blocked me, to work around, I just write code directly in test.js instead of using page object commands. |
Hi @weixiaobo88, What you're describing doesn't quite sound like what I'm fixing with this. This fix is specifically for callback functions. Though the example under Writing Commands did need some tweaking for it to work for me in In page commands, the context ( Currently, the value of I'm not sure what has changed since 0.8.18. If you want to provide me with your complete google page object and test code, I can check it out on my end. |
Hi @senocular , Thanks for your reply. I will list my codes and expect your help to figure out what's wrong. Environment
Folder Structure
Files |
Hey @weixiaobo88, Thanks for being thorough with your information 😸 ! Your problem is in your nightwatch call. In your last argument you specify the test location of In your nightwatch.json file, you specify a correct
|
Hi @senocular, Thanks for your patience, and correctly point out my error 😄 O(∩_∩)O~ Thanks for your help to drag me out. I didn't find it out and I think I didn't understand all stuff. It's a hard way for me to improve (;′⌒`) |
So what is the solution for this? Why can I not use @photos inside certain callbacks? I notice It doesn't work with /page/photos_page.js
|
Note: this was originally mentioned in #1043 but I figured it deserved its own, independent issue.
Callbacks in page object element commands (those referencing an '@'-prefixed element):
https://github.com/nightwatchjs/nightwatch/blob/v0.9.5/lib/page-object/command-wrapper.js#L74
have their callbacks wrapped and re-called with a different context (the Nightwatch object) than normal callbacks:
https://github.com/nightwatchjs/nightwatch/blob/v0.9.5/lib/page-object/command-wrapper.js#L97
Example (using sample from http://nightwatchjs.org/guide#defining-elements ):
Output:
Expected:
a) Context of element command to be consistent and be client/api.
or
b) However, I think it would be more appropriate for the context to be the page instance in the case where the commands are being called from a page object ((1), (2)). That context would allow it to retain access to page-specific commands while also having access to client/api through the
api
property:Compatibility:
Changing the context like this is a breaking change that could affect existing projects if they're already depending on the Nightwatch context now. You might need a compatibility flag or whatever it is you do to handle this kind of situation to allow for backwards compatibility.
The text was updated successfully, but these errors were encountered: