Reputation: 113
This code, i am running in my page class
I.fillField ("input[@class='test']", "name");
}
catch(error){
console.log("Error is occured");
I.refreshPage();
}
If script is unable to fill the text in textbox. instead of failing the case,.. it go to catch section.. refresh the page
This code is working .. but problem it after execution of catch block .. test got failed instead of continue the execution
I have also tried some solutions present on some forms like mentioned below. but facing same issue
I.fillField ("input[@class='test']", "name").catch((error)=>{
I.say("Error is occured");
I.say(error);
I.refreshPage();
});
Can anyone help me to implement try catch block in codeceptjs
Upvotes: 0
Views: 599
Reputation: 11
I believe you can use tryto
for this. https://codecept.io/plugins/#tryto
const hasBeenFilled = await tryTo(() => I.fillField ("input[@class='test']", "name"));
if (!hasBeenFilled) {
I.refreshPage();
}
Make sure you have in codecept.conf.js
plugin turn to true:
plugins: {
tryTo: {
enabled: true
}
}
Upvotes: 1