According to @beatfactor ask from #1237 I'm reporting an issue. It looks for me that in v1.0.18 there's a problem with passing element selectors from page sections into custom commands.
I have such Page Object - page:
module.exports = {
url: function () {
return this.api.launch_url + '/page/0';
},
sections: {
(...truncated...)
userMenu: {
selector : '.usersMenu',
elements: {
userName: 'span:first-child',
userDropdownMenu : '.menu',
editModeMenuItem : '#editModeMenuItem',
resetMenuItem : '#resetMenuItem',
logoutMenuItem: '#logoutMenuItem'
},
props: {
editModeLabel: 'Edit Mode',
exitModeLabel: 'Exit Edit Mode'
}
},
and using such custom command - clickElement:
exports.command = function(selector) {
return this
.waitForElementVisible(selector)
.click(selector, (result) => this.log('Clicked element', result.status === 0 ? 'successfully.' : 'with no success. error - '+result.value.message));
};
from such test file:
var Config = require('../config');
module.exports = {
'Admin user menu': function (client) {
client.login()
.page.page().section.userMenu
.assert.containsText('@userName', Config.admin)
.clickElement('@userName')
.waitForElementVisible('@userDropdownMenu')
.assert.containsText('#resetMenuItem span','Reset Templates')
.assert.containsText('#editModeMenuItem span','Edit Mode')
.assert.containsText('#logoutMenuItem span','Logout');
client.end();
},
and it looks like .clickElement('@userName') is called on span:first-child and not on <Section[name=userMenu],Element[name=@userName]> which should be converted to .usersMenu span:first-child. It was working properly (selector was calculated according to section's selector) in v0.9.21.
โ Running command: containsText ({name, __index, selector, locateStrategy, parent, 'admin')
โ Running command: getText ({name, __index, selector, locateStrategy, parent, [Function])
Request POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element
{ using: 'css selector', value: '.usersMenu' }
Response 200 POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element (23ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: { ELEMENT: '0.1677717170188382-6' } }
Request POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-6/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-6/elements (28ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: [ { ELEMENT: '0.1677717170188382-7' } ] }
Request GET /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-7/text
Response 200 GET /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-7/text (25ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: 'admin' }
โ Testing if element <Section [name=userMenu],Element [name=@userName]> contains text: "admin" - 81 ms.
โ Completed command getText ({name, __index, selector, locateStrategy, parent, [Function]) (79ms)
โ Completed command containsText ({name, __index, selector, locateStrategy, parent, 'admin') (84ms)
โ Running command: clickElement ({name, __index, selector, locateStrategy, parent)
Request POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element
{ using: 'css selector', value: '.usersMenu' }
Response 200 POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element (14ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: { ELEMENT: '0.1677717170188382-6' } }
Request POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-6/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-6/elements (13ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: [ { ELEMENT: '0.1677717170188382-7' } ] }
โ Running command: waitForElementVisible ({selector, locateStrategy, name, response)
Request POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/elements (20ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value:
[ { ELEMENT: '0.1677717170188382-8' },
{ ELEMENT: '0.1677717170188382-9' },
{ ELEMENT: '0.1677717170188382-7' },
{ ELEMENT: '0.1677717170188382-10' },
{ ELEMENT: '0.1677717170188382-11' },
{ ELEMENT: '0.1677717170188382-12' },
{ ELEMENT: '0.1677717170188382-13' },
{ ELEMENT: '0.1677717170188382-14' },
{ ELEMENT: '0.1677717170188382-15' },
{ ELEMENT: '0.1677717170188382-16' },
{ ELEMENT: '0.1677717170188382-17' },
{ ELEMENT: '0.1677717170188382-18' },
{ ELEMENT: '0.1677717170188382-19' },
{ ELEMENT: '0.1677717170188382-20' },
{ ELEMENT: '0.1677717170188382-21' },
{ ELEMENT: '0.1677717170188382-22' },
{ ELEMENT: '0.1677717170188382-23' },
{ ELEMENT: '0.1677717170188382-24' } ] }
Warning: More than one element (18) found for <span:first-child> with selector: "span:first-child". Only the first one will be used.
Request GET /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-8/displayed
Response 200 GET /wd/hub/session/2faa9b53692e73f5e6e41882027b1560/element/0.1677717170188382-8/displayed (20ms)
{ sessionId: '2faa9b53692e73f5e6e41882027b1560',
status: 0,
value: true }
โ Element <span:first-child> was visible after 42 milliseconds.
All my work of migrating to new version of nightwatch.js is here:
https://github.com/cloudify-cosmo/cloudify-stage/tree/CY-896/e2e
Nightwatch version: 1.0.18
Node.js version: 8.11.3
OS version: Windows 10
Selenium Server version: selenium-server-standalone-jar v3.12.0
Browser: Google Chrome 71.0.3578.98 (Official Build) (64-bit) & chrome-driver-standalone v2.37.0
@qooban which browser/driver version?
You should also post your config. It looks like there is a problem with resolving the @userName element for the .clickElement() command but it does seem like it's working fine for assert.containsText().
It might also be the way how clickElement is called, because it looks like you are calling it on the main client instance, instead of the section. Can you try this instead:
const userMenuSection = client.page.page().section.userMenu;
userMenuSection.clickElement('@userName');
// ...
@beatfactor Updated Environment section description with browser/driver version and added more specific link to config in Configuration section.
Regarding your ask for test - I have just tried calling clickElement the way you suggested, but got the same result:
โ Testing if element <Section [name=userMenu],Element [name=@userName]> contains text: "admin" - 213 ms.
Warning: More than one element (18) found for <span:first-child> with selector: "span:first-child". Only the first one will be used.
โ Element <span:first-child> was visible after 40 milliseconds.
-- Clicked element successfully.
ร Timed out while waiting for element <Section [name=userMenu],Element [name=@userDropdownMenu]> to be visible for 20000 milliseconds. - expected "visible" but got: "not
visible"
at Object.Admin user menu ((...)\cloudify-stage\e2e\tests\userMenu.js:16:14)
And can you post the verbose output log of the updated call?
Sure. Here it is:
userMenu-test-verbose-output.log
> [email protected] deve2e (...)\cloudify-stage
> nightwatch -c ./e2e/nightwatch.conf.js --env dev "--test" "./e2e/tests/userMenu.js" "--verbose"
me.json found. Updating nightwatch settings.
Running nightwatch on win32 platform.
Starting Selenium Server on port 4444...
Selenium Server up and running on port 4444 with pid: 11924 (1165ms).
[User Menu] Test Suite
======================
Request POST /wd/hub/session
{ desiredCapabilities:
{ browserName: 'chrome',
acceptSslCerts: true,
platform: 'ANY',
marionette: true,
chromeOptions: { args: [ 'window-size=1600,1600' ] },
name: 'User Menu' } }
Response 200 POST /wd/hub/session (3145ms)
{ status: 0,
sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
value:
{ acceptInsecureCerts: false,
acceptSslCerts: false,
applicationCacheEnabled: false,
browserConnectionEnabled: false,
browserName: 'chrome',
chrome:
{ chromedriverVersion: '2.37.543627 (63642262d9fb93fb4ab52398be4286d844092a5e)',
userDataDir: '(...)\\AppData\\Local\\Temp\\scoped_dir15796_25869' },
cssSelectorsEnabled: true,
databaseEnabled: false,
handlesAlerts: true,
hasTouchScreen: false,
javascriptEnabled: true,
locationContextEnabled: true,
mobileEmulationEnabled: false,
nativeEvents: true,
networkConnectionEnabled: false,
pageLoadStrategy: 'normal',
platform: 'Windows NT',
rotatable: false,
setWindowRect: true,
takesHeapSnapshot: true,
takesScreenshot: true,
unexpectedAlertBehaviour: '',
version: '71.0.3578.98',
webStorageEnabled: true,
'webdriver.remote.sessionid': 'a50dcec2696dfeff543aa8645f2b3a64' } }
Received session with ID: a50dcec2696dfeff543aa8645f2b3a64
โ Running [before]:
โ Completed [before].
Running: Admin user menu
โ Running [beforeEach]:
โ Completed [beforeEach].
โ Running command: login ()
โ Running command: url ('http://localhost:4000/login', )
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/url
{ url: 'http://localhost:4000/login' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/url (1904ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command url ('http://localhost:4000/login', ) (1905ms)
โ Running command: waitForSplashPageNotVisible ()
โ Running command: waitForElementNotVisible ('div.splashPage')
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'div.splashPage' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (30ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-1' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed (25ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed (14ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed (12ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: false }
โ Element <div.splashPage> was not visible after 687 milliseconds.
โ Completed command waitForElementNotVisible ('div.splashPage') (689ms)
โ Completed command waitForSplashPageNotVisible () (692ms)
โ Running command: waitForElementVisible ({name, __index, selector, locateStrategy, parent)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'input[name="username"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (20ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-2' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/displayed (20ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
โ Element <input[name="username"]> was visible after 40 milliseconds.
โ Completed command waitForElementVisible ({name, __index, selector, locateStrategy, parent) (42ms)
โ Running command: resetValue ({name, __index, selector, locateStrategy, parent)
โ Running command: setValue ({selector, locateStrategy, name, {0, 1, 2)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'input[name="username"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (22ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-2' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/value
{ value: [ '๎', 'a', '๎' ] }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/value (48ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command setValue ({selector, locateStrategy, name, {0, 1, 2) (71ms)
โ Completed command resetValue ({name, __index, selector, locateStrategy, parent) (74ms)
โ Running command: setElementValue ({name, __index, selector, locateStrategy, parent, 'admin')
โ Running command: waitForElementPresent ({selector, locateStrategy, name)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'input[name="username"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (14ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-2' } ] }
โ Element <input[name="username"]> was present after 14 milliseconds.
โ Completed command waitForElementPresent ({selector, locateStrategy, name) (14ms)
โ Running command: log ('Setting value 'admin' on '[object Object]'.')
โ Running command: perform ([Function])
-- Setting value 'admin' on '[object Object]'.
โ Completed command perform ([Function]) (0ms)
โ Completed command log ('Setting value 'admin' on '[object Object]'.') (4ms)
โ Running command: setValue ({selector, locateStrategy, name, 'admin', [Function])
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'input[name="username"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (13ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-2' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/value
{ value: [ 'a', 'd', 'm', 'i', 'n' ] }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-2/value (75ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command setValue ({selector, locateStrategy, name, 'admin', [Function]) (89ms)
โ Running command: assert.equal ()
โ Passed [equal]: Value set.
โ Completed command assert.equal () (0ms)
โ Completed command setElementValue ({name, __index, selector, locateStrategy, parent, 'admin') (109ms)
โ Running command: resetValue ({name, __index, selector, locateStrategy, parent)
โ Running command: setValue ({selector, locateStrategy, name, {0, 1, 2)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'input[name="password"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (20ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-3' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-3/value
{ value: [ '๎', 'a', '๎' ] }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-3/value (44ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command setValue ({selector, locateStrategy, name, {0, 1, 2) (64ms)
โ Completed command resetValue ({name, __index, selector, locateStrategy, parent) (67ms)
โ Running command: setElementValue ({name, __index, selector, locateStrategy, parent, 'admin')
โ Running command: waitForElementPresent ({selector, locateStrategy, name)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'input[name="password"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (21ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-3' } ] }
โ Element <input[name="password"]> was present after 21 milliseconds.
โ Completed command waitForElementPresent ({selector, locateStrategy, name) (22ms)
โ Running command: log ('Setting value 'admin' on '[object Object]'.')
โ Running command: perform ([Function])
-- Setting value 'admin' on '[object Object]'.
โ Completed command perform ([Function]) (0ms)
โ Completed command log ('Setting value 'admin' on '[object Object]'.') (1ms)
โ Running command: setValue ({selector, locateStrategy, name, 'admin', [Function])
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'input[name="password"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (23ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-3' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-3/value
{ value: [ 'a', 'd', 'm', 'i', 'n' ] }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-3/value (68ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command setValue ({selector, locateStrategy, name, 'admin', [Function]) (91ms)
โ Running command: assert.equal ()
โ Passed [equal]: Value set.
โ Completed command assert.equal () (0ms)
โ Completed command setElementValue ({name, __index, selector, locateStrategy, parent, 'admin') (117ms)
โ Running command: clickElement ({name, __index, selector, locateStrategy, parent)
โ Running command: waitForElementVisible ({selector, locateStrategy, name)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'button[type="submit"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (21ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-4' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-4/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-4/displayed (21ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
โ Element <button[type="submit"]> was visible after 42 milliseconds.
โ Completed command waitForElementVisible ({selector, locateStrategy, name) (42ms)
โ Running command: click ({selector, locateStrategy, name, [Function])
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'button[type="submit"]' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (21ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-4' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-4/click
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-4/click (68ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command click ({selector, locateStrategy, name, [Function]) (90ms)
โ Running command: log ('Clicked element', 'successfully.')
โ Running command: perform ([Function])
-- Clicked element successfully.
โ Completed command perform ([Function]) (0ms)
โ Completed command log ('Clicked element', 'successfully.') (2ms)
โ Completed command clickElement ({name, __index, selector, locateStrategy, parent) (138ms)
โ Running command: waitForSplashPageNotVisible ()
โ Running command: waitForElementNotVisible ('div.splashPage')
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'div.splashPage' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (13ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-1' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-1/displayed (12ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: false }
โ Element <div.splashPage> was not visible after 26 milliseconds.
โ Completed command waitForElementNotVisible ('div.splashPage') (26ms)
โ Completed command waitForSplashPageNotVisible () (30ms)
โ Running command: waitForElementVisible ({name, __index, selector, locateStrategy, parent)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: '.managerMenu' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (20ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [] }
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-5/displayed (514ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
โ Element <.managerMenu> was visible after 5513 milliseconds.
โ Completed command waitForElementVisible ({name, __index, selector, locateStrategy, parent) (5513ms)
โ Completed command login () (8702ms)
โ Running command: containsText ({name, __index, selector, locateStrategy, parent, 'admin')
โ Running command: getText ({name, __index, selector, locateStrategy, parent, [Function])
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: '.usersMenu' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (120ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-6' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements (28ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-7' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-7/text
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-7/text (24ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: 'admin' }
โ Testing if element <Section [name=userMenu],Element [name=@userName]> contains text: "admin" - 177 ms.
โ Completed command getText ({name, __index, selector, locateStrategy, parent, [Function]) (176ms)
โ Completed command containsText ({name, __index, selector, locateStrategy, parent, 'admin') (180ms)
โ Running command: clickElement ({name, __index, selector, locateStrategy, parent)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: '.usersMenu' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (15ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-6' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements (14ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-7' } ] }
โ Running command: waitForElementVisible ({selector, locateStrategy, name, response)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (21ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value:
[ { ELEMENT: '0.7545075189197148-8' },
{ ELEMENT: '0.7545075189197148-9' },
{ ELEMENT: '0.7545075189197148-7' },
{ ELEMENT: '0.7545075189197148-10' },
{ ELEMENT: '0.7545075189197148-11' },
{ ELEMENT: '0.7545075189197148-12' },
{ ELEMENT: '0.7545075189197148-13' },
{ ELEMENT: '0.7545075189197148-14' },
{ ELEMENT: '0.7545075189197148-15' },
{ ELEMENT: '0.7545075189197148-16' },
{ ELEMENT: '0.7545075189197148-17' },
{ ELEMENT: '0.7545075189197148-18' },
{ ELEMENT: '0.7545075189197148-19' },
{ ELEMENT: '0.7545075189197148-20' },
{ ELEMENT: '0.7545075189197148-21' },
{ ELEMENT: '0.7545075189197148-22' },
{ ELEMENT: '0.7545075189197148-23' },
{ ELEMENT: '0.7545075189197148-24' } ] }
Warning: More than one element (18) found for <span:first-child> with selector: "span:first-child". Only the first one will be used.
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-8/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-8/displayed (23ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: true }
โ Element <span:first-child> was visible after 45 milliseconds.
โ Completed command waitForElementVisible ({selector, locateStrategy, name, response) (45ms)
โ Running command: click ({selector, locateStrategy, name, response, [Function])
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element
{ using: 'css selector', value: 'span:first-child' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element (19ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: { ELEMENT: '0.7545075189197148-8' } }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-8/click
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-8/click (146ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command click ({selector, locateStrategy, name, response, [Function]) (166ms)
โ Running command: log ('Clicked element', 'successfully.')
โ Running command: perform ([Function])
-- Clicked element successfully.
โ Completed command perform ([Function]) (0ms)
โ Completed command log ('Clicked element', 'successfully.') (0ms)
โ Completed command clickElement ({name, __index, selector, locateStrategy, parent) (242ms)
โ Running command: waitForElementVisible ({name, __index, selector, locateStrategy, parent)
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements
{ using: 'css selector', value: '.usersMenu' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/elements (19ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-6' } ] }
Request POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements
{ using: 'css selector', value: '.menu' }
Response 200 POST /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-6/elements (20ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: [ { ELEMENT: '0.7545075189197148-25' } ] }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-25/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-25/displayed (18ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: false }
Request GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-25/displayed
Response 200 GET /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64/element/0.7545075189197148-25/displayed (12ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: false }
ร Timed out while waiting for element <Section [name=userMenu],Element [name=@userDropdownMenu]> to be visible for 20000 milliseconds. - expected "visible" but got: "not visible"
at Object.Admin user menu ((...)cloudify-stage\e2e\tests\userMenu.js:16:14)
โ Completed command waitForElementVisible ({name, __index, selector, locateStrategy, parent) (20248ms)
โ Running [afterEach]:
โ Completed [afterEach].
FAILED: 1 assertions failed and 11 passed (29.688s)
Error while running "waitForElementVisible" command: Timed out while waiting for element <Section [name=userMenu],Element [name=@userDropdownMenu]> to be visible for 20000 milliseconds. - expected "visible" but got: "not visible"
โ Running [after]:
โ Completed [after].
โ Running command: end ([Function])
โ Running command: session ('delete', [Function])
Request DELETE /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64
Response 200 DELETE /wd/hub/session/a50dcec2696dfeff543aa8645f2b3a64 (74ms)
{ sessionId: 'a50dcec2696dfeff543aa8645f2b3a64',
status: 0,
value: null }
โ Completed command end ([Function]) (77ms)
โ Completed command session ('delete', [Function]) (75ms)
_________________________________________________
TEST FAILURE: 1 assertions failed, 11 passed. 34.218s
ร userMenu
โ Admin user menu (29.688s)
Timed out while waiting for element <Section [name=userMenu],Element [name=@userDropdownMenu]> to be visible for 20000 milliseconds. - expected "visible" but got: "not visible"
at Object.Admin user menu ((...)cloudify-stage\e2e\tests\userMenu.js:16:14)
SKIPPED:
- Regular user menu
Wrote report file to: reports\CHROME_71.0.3578.98_Windows_NT_userMenu.xml.
Wrote log file to: (...)cloudify-stage\selenium-server.log.
Selenium Server process closed.
npm ERR! code ELIFECYCLE
npm ERR! errno 5
npm ERR! [email protected] deve2e: `nightwatch -c ./e2e/nightwatch.conf.js --env dev "--test" "./e2e/tests/userMenu.js" "--verbose"`
npm ERR! Exit status 5
npm ERR!
npm ERR! Failed at the [email protected] deve2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! (...)\AppData\Roaming\npm-cache\_logs\2019-01-04T10_23_58_577Z-debug.log
UPDATE: I have set disable_colors to remove unnecessary characters from the log.
UPDATE 2: Per request I have inlined verbose output log. It's pretty big, though. That's why I didn't wanted to do so, but if that's OK for you, I'm OK, too :-)
Can you post it inline please? You can just update your previous comment with the more detailed output.
As a side note to this particular issue. Maybe implementing a built-in command that would waitAndClick is a good improvement? Seems like many developers are implementing such command.
We will add support for taking into account the global waitForConditionTimeout variable when performing basic commands such as .click() or .getText() so that these commands will wait for the element before performing the action.
@qooban I had another look at your custom command and it looks like the same problem from my previous comment applies.
Even if you are calling the .clickElement() on the page object section, inside the custom command you are calling waitForElementVisible and click() commands on this and it looks like the context is not pointing to the section object, but rather to the main client object. Was this working as expected in v0.9?
@beatfactor Yes, it was working as expected in v0.9. I have just tested on v0.9.21.
Whole test verbose output:
userMenu-test-verbose-output-0.9.log
The most relevant part:
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element
- data: {"using":"css selector","value":".usersMenu"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element (191ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: { ELEMENT: '0.043844685116021465-6' } }
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/element
- data: {"using":"css selector","value":"span:first-child"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":51}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/element (25ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: { ELEMENT: '0.043844685116021465-7' } }
INFO Request: GET /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/text
- data:
- headers: {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/text (27ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: 'admin' }
โ Testing if element <Section[name=userMenu],Element[name=@userName]> contains text: "admin".
LOG โ Completed command getText (245 ms)
LOG โ Completed command useCss (0 ms)
LOG โ Completed command useRecursion (0 ms)
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/elements
- data: {"using":"css selector","value":".usersMenu"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/elements (21ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: [ { ELEMENT: '0.043844685116021465-6' } ] }
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/elements
- data: {"using":"css selector","value":"span:first-child"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":51}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/elements (20ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: [ { ELEMENT: '0.043844685116021465-7' } ] }
INFO Request: GET /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/displayed
- data:
- headers: {"Accept":"application/json"}
INFO Response 200 GET /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/displayed (27ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: true }
โ Element <Section[name=userMenu],Element[name=@userName]> was visible after 70 milliseconds.
LOG โ Completed command waitForElementVisible (71 ms)
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element
- data: {"using":"css selector","value":".usersMenu"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":45}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element (16ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: { ELEMENT: '0.043844685116021465-6' } }
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/element
- data: {"using":"css selector","value":"span:first-child"}
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":51}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-6/element (14ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: { ELEMENT: '0.043844685116021465-7' } }
INFO Request: POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/click
- data:
- headers: {"Content-Length":0}
INFO Response 200 POST /wd/hub/session/d47ce7a01c3e7d3c67f5c96f8228e01f/element/0.043844685116021465-7/click (96ms) { sessionId: 'd47ce7a01c3e7d3c67f5c96f8228e01f',
status: 0,
value: null }
LOG โ Completed command click (126 ms)
-- Clicked element successfully.
Alright then, we'll get to the bottom of it.
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
Could you all please check if this issue still persists in the latest version (1.1.3)?
Tested on 1.1.6. Yes, the issue still persists.
@qooban I'm afraid I kind of lost track to what is happening here. Would it be possible for you to create a PR with an example test in this repo, using our nightwatchjs.org website as the target? It would be much easier for me to fix this bug. Thanks.
@beatfactor I opened #2018 which is highly similar to this Issue. I created a sample test in this repo: yarn test:2018 which replicates the bug. I have not tested against latest -- I will do so shortly, just wanted to go ahead and share those details. Seems like it may be better to move this sample test over to the nightwatch-website-tests repo, I can setup a PR there.
Thanks @thaddeusreid .
@beatfactor I hope it will help solving the problem.
Sorry for the delay, the weekend got the best of me.
@beatfactor I added a PR to the nightwatch-website-tests repo which adds a test to recreate the bug. You can npm run test:2018 to see the results.
I have continued to reference the #2018 issue since I'm more familiar with it (compared to this ticket) and I still have the impression that the errors are slightly different. Hopefully they share the same root cause! Please let me know how else I can help.
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
Is this issue solved?
i get the similar issue when i use nightwatch and selenium-grid
nightwatch version is :v1.2.4
selenium-standalone: selenium-server-standalone-3.141.59.jar
from the verbose log, it finds the element, but still get: "not found" error
Response 200 POST http://172.20.10.167:4444/wd/hub/session/17d9ddd6457a620f1ff160a6ff095e24/elements (11ms)
{ value:
[ { 'element-6066-11e4-a52e-4f735466cecf': 'fefbb458-08fc-428d-b82f-99165f1f1904' } ] }
Request POST http://172.20.10.167:4444 /wd/hub/session/17d9ddd6457a620f1ff160a6ff095e24/elements
{ using: 'css selector', value: '#doxMainLogin' }
Response 200 POST http://172.20.10.167:4444/wd/hub/session/17d9ddd6457a620f1ff160a6ff095e24/elements (9ms)
{ value:
[ { 'element-6066-11e4-a52e-4f735466cecf': 'fefbb458-08fc-428d-b82f-99165f1f1904' } ] }
โ Timed out while waiting for element <#doxMainLogin> to be present for 60000 milliseconds. - expected "visible" but got: "not found"
I see it is still valid in latest version - v1.3.4. Basically dynamic selectors are not working with custom commands since v1.x. That's why we still have to use the latest from v0.9.x branch.
I think my issue is the same as https://github.com/nightwatchjs/nightwatch/issues/2089
@beatfactor Do you think it will be possible to solve it or at least workaround it somehow?
To simplify the problem I created very simple example showing what is not working fine in >v0.9.21.
nightwatch.js - Page Object describing nightwatchjs.org web-page
module.exports = {
url: 'https://nightwatchjs.org/',
sections: {
footerLinks: {
selector: 'section[id="index-container"] footer div.row div.col-md-2',
elements: {
aboutLink: 'li:nth-child(1) a'
}
}
}
};
clickElement.js - Custom command
exports.command = function(selector) {
return this.click(selector);
};
test.js - Simple test showing that API works fine, but custom command doing the same is not respecting sections
module.exports = {
'API command': function(client) {
const page = client.page.nightwatch();
const section = page.section.footerLinks;
page.navigate();
section.click('@aboutLink');
client.assert.urlEquals('https://nightwatchjs.org/about/');
},
'Custom command': function(client) {
const page = client.page.nightwatch();
const section = page.section.footerLinks;
page.navigate();
section.clickElement('@aboutLink');
client.assert.urlEquals('https://nightwatchjs.org/about/');
}
};
Testing environment:
"nightwatch": "^1.3.4",
"chromedriver": "^81.0.0",
"selenium-server": "^3.141.59",
@beatfactor I would really appreciate if you could take a look on that. We are struggling with NightwatchJS upgrade almost 1,5 year because of that issue.
I digged into NightwatchJS core code, but as I'm not very familiar with it I couldn't solve it on my own. What I've found is that when you pass context as an argument (in my example it can be a section) to custom command and run the API command on that context instead of this it finds the proper element. But I don't think it should be the solution here.
Hi,
FYI, we have the same issue with firefox.
nightwatch: 1.3.4
geckodriver: 1.19.1
firefox: 68.7.0
It's very annoying and make page objects not usable.
Version 1.3.4 still has this problem. I have tried a work around in my project's local nightwatch. By adding the parent to the locator result. Doing so brings in the context to all consumers such as commands and assertions.
I'm not sure about other's thoughts. But to me this seems to be an acceptable solution. It brings minimum amount of change to the code base. Processing logic doesn't seem to change from the library's stand point.
Hope I haven't missed out anything in the whole process chain. I have created a fork for a PR. If you think it's an acceptable solution.
This issue has been automatically marked as stale because it has not had any recent activity.
If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.
It is still an issue in 1.4.2. I am upgrading a project that is extensively using custom commands and page objects with sections. Upgrading all tests to manually build selector for custom commands is a deal breaker and would be very painful to keep doing it for new tests.
@beatfactor any chance to fix it in the near future?
Unfortunately it is still an issue in version 1.5.1. When you have a section and call a custom command parent selector is omitted and the command is executed in a wrong context.
Still an issue in 1.5.1
Nice, they closed an ongoing issue without adding any information about it.
Nice, they closed an ongoing issue without adding any information about it.
To be honest after few months of using Nightwatch I figured out sections are messy and unappealing.
I don't like the fact I need to initiate a page and a section of this page in my tests, I recommend just using new POM if needed
Sorry to hear that you're still having issues with this. Are you sure it is the same issue? Since the original is quite old and a fix was released, would it be possible for someone to open a new issue regarding this?