-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditionnal test based on element visibility #648
Comments
@adeleco did you find a way to do this? |
Conditionals are not allowed in test scenarios. If you really need them you should implment them inside helpers. You will need to implment them using promises inside helpers. But better don't do them at all in tests |
I haven't had time to do this yet. @1vanhelsing1 if you do this please post a sample. |
@1vanhelsing1 |
Here is an example showing a conditional action in a Helper. Custom Helper Example 'use strict';
import assert from 'assert';
let Helper = codecept_helper;
class MyHelper extends Helper {
async clickIfVisible(selector, ...options) {
const helper = this.helpers['Puppeteer'];
try {
const numVisible = await helper.grabNumberOfVisibleElements(selector);
if (numVisible) {
return helper.click(selector, ...options);
}
} catch (err) {
console.log('Skipping operation as element is not visible');
}
}
}
module.exports = MyHelper; |
Hey, how do we call this helper method from another class? I need to check Checkbox only if it is not checked already. How do I implement this in CodeceptJS with webDriverIO? Appreciate any help! |
What are you trying to achieve?
Conditionnal code in a scenario, based on the visibility of an element.
Questions
How to use a conditional testing (if / else)
If (I.seeElement) {
// code here
}
else {
// other code here
}
Is it possible to use exceptions management (try / catch / finally)
try{
// code here
I.seeElement(locator);
}catch(exception){
// other code here
}
best regards
adeleco
The text was updated successfully, but these errors were encountered: