我试图断言父元素中子元素的可见性。
我正在检查天气,可见带有c-cost-with标签的div。
这是它的HTML:
我正在尝试基于父级获取元素:
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);
}
我先获取父元素,然后尝试获取子元素并检查其中的可见性。
当我执行这些步骤时,第一步已正确执行,但第二步失败了!!!
它试图从'.c-cost-with-label__cost'获取元素,即使在函数中我传递了父元素。
如何解决此问题,如何在不同元素上同时执行断言[检查可见性]