несколько утверждений в одном выражении в кипарисе - PullRequest
0 голосов
/ 26 ноября 2018

Я пытаюсь установить видимость дочерних элементов в родительском элементе.

Я проверяю, видны ли div внутри метки c-cost-with.

Вот HTML-коддля него:

HTML Content

Я пытаюсь получить элементы на основе родительского элемента:

    Given(/^I should see the following charge amounts and charge labels in offer:$/, (dataTable) => {
    dataTable.rawTable.slice(1).forEach((row) => {
        let [optionName, pricingPlanName, chargeAmount, ChargeLabel] = row;
        let costWithLabelElement = costWithLabelUtil.getCostWithLabelElement(optionsCardCostListElement);
        costWithLabelUtil.getCostWithLabelCostElementContainingText(chargeAmount, costWithLabelElement).should('be.visible');
        costWithLabelUtil.getCostWithLabelLabelElementContainingText(ChargeLabel, costWithLabelElement).should('be.visible');

    });
});

здесь код вcostWithLabelUtil:

    export function getCostWithLabelElement (ancestorElement = null) {
    return ElementFinders.getElementFromAncestorIfProvided('.c-cost-with-label', ancestorElement);
}


export function getCostWithLabelMainElement (ancestorElement = null) {
    return ElementFinders.getElementFromAncestorIfProvided('.c-cost-with-label__main', ancestorElement);
}


export function getCostWithLabelCostElement (ancestorElement = null) {
    return ElementFinders.getElementFromAncestorIfProvided('.c-cost-with-label__cost', ancestorElement);
}

export function getCostWithLabelCostElementContainingText (text, ancestorElement = null) {
    return ElementFinders.getElementContainingTextFromAncestorIfProvided('.c-cost-with-label__cost', text, ancestorElement);
}

export function getCostWithLabelLabelElement (ancestorElement = null) {
    return ElementFinders.getElementFromAncestorIfProvided('.c-cost-with-label__label', ancestorElement);
}

export function getCostWithLabelLabelElementContainingText (text, ancestorElement = null) {
    cy.log(ancestorElement);
    return ElementFinders.getElementContainingTextFromAncestorIfProvided('.c-cost-with-label__label', text, ancestorElement);
}

Вот страница поиска элементов:

    export function getElementFromAncestorIfProvided (elementLocator, ancestorElement = null) {
    if (ancestorElement) {
        return ancestorElement.find(elementLocator);
    }

    return cy.get(elementLocator);
}


export function getElementContainingTextFromAncestorIfProvided (elementLocator, text, ancestorElement = null) {
    if (ancestorElement) {
        return ancestorElement.find(elementLocator).contains(text);
    }

    return cy.get(elementLocator).contains(text);
}

Сначала я выбираю родительский элемент, а затем пытаюсь извлечь дочерние элементы и проверить их видимость.

когда я выполняю шаги, первый шаг выполняется правильно, но второй шаг терпит неудачу !!!

Fail

он пытается получить элементиз '.c-cost-with-label__cost', хотя в функции я передаю родительский элемент.

как решить эту проблему, как выполнить утверждения [проверить видимость] для разных элементов одновременно

...