Skip to content

Instantly share code, notes, and snippets.

@ruyaoyao
Forked from reubenmiller/codecept.conf.js
Created July 13, 2018 06:34
Show Gist options
  • Save ruyaoyao/8e9a4b499b7d7f4a94d53b3b9746cc5b to your computer and use it in GitHub Desktop.
Save ruyaoyao/8e9a4b499b7d7f4a94d53b3b9746cc5b to your computer and use it in GitHub Desktop.
Example of custom helper to perform conditional click (without throwing an error)
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',
};
'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;
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