Execute method does not return a value to callback
Closed this issue · 3 comments
Jav3k commented
Source Files
JS:
const url = 'http://local-folder.lambdatest.com/icu.html';
const url2 = 'https://google.com/ncr';
module.exports = {
'test1': (browser) => {
browser
.url(url)
.waitForElementVisible('body', 10000)
.assert.title('Page Title')
.execute(function(arg) {
document.getElementById("results").innerHTML = arg;
return arg;
}, [123], function(res) {
console.log(res);
browser.assert.equal(res.value, "123");
})
.end();
},
'test2': (browser) => {
browser
.url(url2)
.waitForElementVisible('body', 10000)
.execute(function(arg) {
document.querySelector('input[type=text]').value = arg;
return arg;
}, [123], function(res) {
console.log(res);
browser.assert.equal(res.value, "123");
})
.end();
},
afterEach: function(client, done) {
setTimeout(function() {
done();
}, 1000);
}
};
HTML for test1:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="background-color: aliceblue;">
<div>
<h1>T</h1>
</div>
<div id="results"></div>
</body>
</html>
Output
Nightwatch-cli output:
...
Running: test1
...
→ Running command: execute ([Function], {0, [Function])
Request POST http://hub.lambdatest.com /wd/hub/session/216a7f3eaeeb17ccf84a9c74aaa433e6/execute
{ script:
'var passedArgs = Array.prototype.slice.call(arguments,0); return function(arg) {\n document.getElementById("results").innerHTML = arg;\n return arg;\n }.apply(window, passedArgs);',
args: [ 123 ] }
Response 200 POST http://hub.lambdatest.com/wd/hub/session/216a7f3eaeeb17ccf84a9c74aaa433e6/execute (565ms)
{ status: -1,
value:
'{"sessionId":"216a7f3eaeeb17ccf84a9c74aaa433e6","status":0,"value":null}' }
Error while running .executeScript() protocol action: An unknown error has occurred.
{ status: -1,
state: '',
value:
'{"sessionId":"216a7f3eaeeb17ccf84a9c74aaa433e6","status":0,"value":null}',
errorStatus: -1,
error: 'An unknown error has occurred.',
httpStatusCode: 200 }
→ Completed command execute ([Function], {0, [Function]) (567ms)
→ Running command: assert.equal ()
✖ Failed [equal]: ('{"sessionId":"216a7f3eaeeb17ccf84a9c74aaa433e6","status":0,"value":null}' == '123') - expected "123" but got: "{"sessionId":"216a7f3eaeeb17ccf84a9c74aaa433e6","status":0,"value":null}"
...
But in LambdaTest Dashboard at Automation section i got expected result:
Same with 'test2
If i running nightwatch test with my local hub on selenium-server-standalone-3.141.5.jar - there is no errors.
I think your selenium hub does not return result value to my nightwatch, cuz i see right result value in dashboard (screenshot above).
Can you help me?
upd. I work with ssh tunnel. so i tried to run nightwatch with "tunnel: false" - same error
Jav3k commented
Fixed by dev team
Jav3k commented
Some another execute method errors
test.js (modified version of 'test2' testcase)
const url2 = 'https://google.com/ncr';
module.exports = {
'test2': (browser) => {
browser
.url(url2)
.assert.title('Google')
.execute(function(arg) {
document.querySelector('input[type=text]').value = arg;
return arg;
}, [123], function(res) {
console.log('response:\n', res);
browser.assert.equal(res.value, "123");
})
.end();
},
afterEach: function(client, done) {
setTimeout(function() {
done();
}, 1000);
}
};
nightwatch envs (without tunnel)
"firefox": {
"desiredCapabilities": {
"platform": "Windows 10",
"browserName": "Firefox",
"version": "64.0"
}
},
"edge": {
"desiredCapabilities": {
"platform": "Windows 10",
"browserName": "MicrosoftEdge",
"version": "18.0"
}
},
"ie10": {
"desiredCapabilities": {
"platform": "Windows 7",
"browserName": "Internet Explorer",
"version": "10.0"
}
}
works right with
"chrome": {
"desiredCapabilities": {
"platform": "Windows 10",
"browserName": "Chrome",
"version": "71.0"
}
},
"safari11": {
"desiredCapabilities": {
"platform": "macOS High Sierra",
"browserName": "Safari",
"version": "11.0"
}
},
"safari10": {
"desiredCapabilities": {
"platform" : "macOS Sierra",
"browserName" : "Safari",
"version" : "10.0"
}
},
"ie11": {
"desiredCapabilities": {
"platform" : "Windows 10",
"browserName" : "Internet Explorer",
"version" : "11.0"
}
},
Jav3k commented
fixed by dev team