qape
Version:
Monkey testing library
70 lines (56 loc) • 1.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _AbstractAction = _interopRequireDefault(require("./AbstractAction"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Click action, which will click on random
* or specific (if actionConfig is passed) page element
* @extends AbstractAction
*/
class ClickAction extends _AbstractAction.default {
/**
* @returns {string} 'click'
*/
static get id() {
return 'click';
}
/**
* Click action should be always possible
* @returns {boolean} true
*/
static isActionAvailable() {
return true;
}
/**
* Performs the click action with following wrappers:
* - Hover over the element
* (So that in preview mode, you will see the element before click)
* - Signal click on the element (Only in headfull mode)
* - Click on the element
* @param {puppeteer.Page} page
* @param {puppeteer.ElementHandle} element
* @returns {Promise} Resolves when click is done
*/
async action(element, page) {
await element.hover();
if (this._config.headlessModeDisabled) {
await this._actionsHelper.highlightElement(element);
await page.waitForTimeout(this._config.previewModePauseTime);
}
await element.click();
}
/**
* Adds clicked element info to the action results
* @param {Object} results
* @returns {Object}
*/
async updateResults(results) {
return Object.assign({}, results, {
message: `Click on ${results.html} [selector:"${results.config.selector}"]`
});
}
}
exports.default = ClickAction;