-
-
Save ruyaoyao/8e9a4b499b7d7f4a94d53b3b9746cc5b to your computer and use it in GitHub Desktop.
Example of custom helper to perform conditional click (without throwing an error)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const outputFolder = './output'; | |
exports.config = { | |
output: outputFolder, | |
helpers: { | |
Puppeteer: { | |
url: 'http://google.com', | |
show: true, | |
chrome: {} | |
}, | |
Mochawesome: { | |
uniqueScreenshotNames: true, | |
}, | |
customHelper: { | |
require: '../helpers/customHelper.js', | |
}, | |
}, | |
include: {}, | |
mocha: {}, | |
bootstrap: false, | |
teardown: null, | |
hooks: [], | |
tests: '../tests_puppeteer/*_test.js', | |
timeout: 10000, | |
name: 'doler-js', | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature('Example') | |
Scenario('Example of conditional click', (I) => { | |
I.amOnPage('https://google.com'); | |
I.clickIfVisible('.SomethingThatDoesNotExist'); // Function is declared in MyCustomHelper.js | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment