I want to write test on Visual Studio Code/Codeceptjs. My code is here in short :
let amazonWebKeys=require('./amazonKeys/amazonwebkeys.json');
module.exports = function() {
return actor({
buttons:{
acceptcookie : '//input[@id="sp-cc-accept"]' //accept cookie button
},
getParemeters : function(keys){
return amazonWebKeys[keys];
},
WebTest:function(){
this.amOnPage(this.getParemeters("url")); //go to website
this.click(this.buttons.acceptcookie); //accept cookie
}
});
}
But error message. Why selector needs to be typeof 'string' or 'function. What can I do for this problem :
1) WebTest
test something:
selector needs to be typeof `string` or `function`
at Browser.findElements (node_modules\webdriverio\build\utils\index.js:176:11)
at Browser.$$ (node_modules\webdriverio\build\commands\browser\$$.js:6:44)
at Browser.wrapCommandFn (node_modules\@wdio\utils\build\shim.js:63:38)
And you can see at Scenario Steps that in click() is empty.
Scenario Steps:
- I.click() at Actor.WebTest (.\steps_file.js:21:12)
- I.amOnPage("https://www.amazon.com.tr/") at Actor.WebTest (.\steps_file.js:20:12)
Thanks in advance
I also faced the same error. I solved it with the following code:
module.exports = function () {
let parameters = require('./Parameters/parameters.json');
username = '//input[@id="username"]';
password = '//input[@id="password"]';
submitButton = '//button[@class="btn btn-primary"]';
administration = '//li[@id="admin-menu"]';
return actor({
getEnviromentParameters: function (key) {
return parameters[key];
},
login: function () {
this.amOnPage(this.getEnviromentParameters('loginUrl'));
this.fillField(`${username}`,
this.getEnviromentParameters('userName')
);
this.fillField(`${password}`,
this.getEnviromentParameters('password')
);
this.click(`${submitButton}`);
this.waitForElement(`${submitButton}`, 5)
this.seeElement(`${submitButton}`);
}
});
}