@cuppet/core
Version:
Core testing framework components for Cuppet - BDD framework based on Cucumber and Puppeteer
60 lines (59 loc) • 2.95 kB
JavaScript
const { When, Then } = require('@cucumber/cucumber');
const utils = require('../../../src/elementInteraction');
const config = require('config');
const dataStorage = require('../../../src/dataStorage');
Then('I should see {string} if visible', async function (text) {
if (config.has('skipSteps') && config.get('skipSteps') === text) {
return true;
}
const resolvedText = this.mlStrings[text] ?? text;
await utils.seeTextByXpath(this.page, resolvedText);
});
When('I type {string} in {string} if visible', async function (text, cssSelector) {
const selector = this.commonFields[cssSelector] ?? cssSelector;
await utils.typeInField(this.page, selector, text, true);
});
When('I click on the element {string} if visible', async function (cssSelector) {
const selector = this.commonFields[cssSelector] ?? cssSelector;
await utils.click(this.page, selector, true);
});
Then('I select {string} from {string} if visible', async function (value, cssSelector) {
const selector = this.commonFields[cssSelector] ?? cssSelector;
await utils.selectOptionByValue(this.page, selector, value, true);
});
Then('I fill in {string} with {string} if visible', async function (cssSelector, text) {
const selector = this.commonFields[cssSelector] ?? cssSelector;
await utils.fillField(this.page, selector, text, true);
});
Then(
'I check if element with selector {string} has attribute {string} with {string} value from config if visible',
async function (selector, attribute, variable) {
const attrValue = await config.get(variable);
await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue, true);
}
);
Then(
'I check if element with selector {string} has attribute {string} with {string} value from json if visible',
async function (selector, attribute, variable) {
const attrValue = dataStorage.getVariable(variable);
await utils.validateElementWithSelectorHasAttributeWithValue(this.page, selector, attribute, attrValue, true);
}
);
Then(
'I check if link with href {string} has attribute {string} with {string} value from config if visible',
async function (href, attribute, value) {
const attrValue = await config.get(value);
await utils.validateValueOfLinkAttributeByHref(this.page, href, attribute, attrValue, true);
}
);
Then(
'I check if link with href {string} has attribute {string} with {string} value from json if visible',
async function (href, attribute, value) {
const attrValue = dataStorage.getVariable(value);
await utils.validateValueOfLinkAttributeByHref(this.page, href, attribute, attrValue, true);
}
);
Then('I {string} the checkbox {string} if visible', async function (action, cssSelector) {
const selector = this.commonFields[cssSelector] ?? cssSelector;
await utils.useCheckbox(this.page, selector, action, true);
});