{"action":"created","issue":{"url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/1048","repository_url":"https://api.github.com/repos/nightwatchjs/nightwatch","labels_url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/1048/labels{/name}","comments_url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/1048/comments","events_url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/1048/events","html_url":"https://github.com/nightwatchjs/nightwatch/issues/1048","id":163078463,"number":1048,"title":"Page object command callbacks using element references do not use API context","user":{"login":"senocular","id":3536716,"avatar_url":"https://avatars.githubusercontent.com/u/3536716?v=3","gravatar_id":"","url":"https://api.github.com/users/senocular","html_url":"https://github.com/senocular","followers_url":"https://api.github.com/users/senocular/followers","following_url":"https://api.github.com/users/senocular/following{/other_user}","gists_url":"https://api.github.com/users/senocular/gists{/gist_id}","starred_url":"https://api.github.com/users/senocular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/senocular/subscriptions","organizations_url":"https://api.github.com/users/senocular/orgs","repos_url":"https://api.github.com/users/senocular/repos","events_url":"https://api.github.com/users/senocular/events{/privacy}","received_events_url":"https://api.github.com/users/senocular/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-06-30T04:24:56Z","updated_at":"2016-07-17T12:09:20Z","closed_at":null,"body":"_Note: this was originally mentioned in #1043 but I figured it deserved its own, independent issue._\r\n\r\nCallbacks in page object element commands (those referencing an '@'-prefixed element):\r\n\r\nhttps://github.com/nightwatchjs/nightwatch/blob/v0.9.5/lib/page-object/command-wrapper.js#L74\r\n\r\nhave their callbacks wrapped and re-called with a different context (the Nightwatch object) than normal callbacks:\r\n\r\nhttps://github.com/nightwatchjs/nightwatch/blob/v0.9.5/lib/page-object/command-wrapper.js#L97\r\n\r\nExample (using sample from http://nightwatchjs.org/guide#defining-elements ):\r\n\r\n```javascript\r\nmodule.exports = {\r\n  'Test': function (client) {\r\n\r\n    function callback () {\r\n      console.log('is client: ' + (this === client) + '; ctor: ' + this.constructor.name);\r\n    }\r\n\r\n    var google = client.page.google();\r\n\r\n    google.navigate()\r\n      .click('@searchBar', callback) // (1) page element\r\n      .click('input[type=text]', callback) // (2) page selector\r\n      .api.click('input[type=text]', callback) // (3) client/api selector\r\n\r\n    client.end();\r\n  }\r\n};\r\n```\r\n\r\nOutput:\r\n\r\n```\r\nis client: false; ctor: Nightwatch // (1)\r\nis client: true; ctor: Object // (2)\r\nis client: true; ctor: Object // (3)\r\n```\r\n\r\nExpected:\r\n\r\na) Context of element command to be consistent and be client/api.\r\n\r\nor\r\n\r\nb) 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:\r\n\r\n```javascript\r\n    function callback () {\r\n      console.log(this === google); // true\r\n      console.log(this.api === client); // true\r\n    }\r\n```\r\n\r\nCompatibility:\r\n\r\nChanging 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.\r\n"},"comment":{"url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/comments/233178972","html_url":"https://github.com/nightwatchjs/nightwatch/issues/1048#issuecomment-233178972","issue_url":"https://api.github.com/repos/nightwatchjs/nightwatch/issues/1048","id":233178972,"user":{"login":"senocular","id":3536716,"avatar_url":"https://avatars.githubusercontent.com/u/3536716?v=3","gravatar_id":"","url":"https://api.github.com/users/senocular","html_url":"https://github.com/senocular","followers_url":"https://api.github.com/users/senocular/followers","following_url":"https://api.github.com/users/senocular/following{/other_user}","gists_url":"https://api.github.com/users/senocular/gists{/gist_id}","starred_url":"https://api.github.com/users/senocular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/senocular/subscriptions","organizations_url":"https://api.github.com/users/senocular/orgs","repos_url":"https://api.github.com/users/senocular/repos","events_url":"https://api.github.com/users/senocular/events{/privacy}","received_events_url":"https://api.github.com/users/senocular/received_events","type":"User","site_admin":false},"created_at":"2016-07-17T12:09:20Z","updated_at":"2016-07-17T12:09:20Z","body":"Hey @weixiaobo88,\r\n\r\nThanks for being thorough with your information 😸 ! \r\n\r\nYour problem is in your nightwatch call.  In your last argument you specify the test location of `./test/e2e` which also includes the folder where your page object is defined.  Because the page object is defined in a JS file, its being picked up by the test loader and run as a test. This is where your error is coming from, not the actual `google.test.js` test.\r\n\r\nIn your nightwatch.json file, you specify a correct `src_folders` value of `\"test/e2e/tests/\"`.  This will correctly point to just your test, ignore the page object JS in the run.  Ditching the `./test/e2e` from your call to nightwatch should fix the problem for you."}}
{"actor":{"display_login":"senocular"}}