In the page I\'m testing, two buttons may be displayed: BASIC or ADVANCED.
I want to be able to tell if the ADVANCED button is showing -- and if so, click it.
<
My team uses a single function to authenticate with a few different signin forms, and we utilize a custom command called ifElementExists
to accomplish the branching logic for understanding which form we're on. We also use this on a few other pages that don't have a better method for determining current state.
import { CustomCommandShorthand } from './customCommands';
import { isFunction } from 'lodash';
exports.command = function ifElementExists(this: CustomCommandShorthand, selector: string, ifTrue: Function, ifFalse?: Function) {
this.perform(() => {
if (!isFunction(ifTrue)) {
throw new Error(`The second argument must be callable. You passed a ${typeof ifTrue} instead of a function.`);
}
this.element('css selector', selector, function ifElementExistsCallback({ status }) {
if (status !== -1) {
return ifTrue();
}
if (isFunction(ifFalse)) {
ifFalse();
}
});
})
}