在下面的html标记,我想首先检查是否“数据索引= 1”,如果是,那么我就要检查一下,cardbox必须包含健康,那么产品和策略#。
我应该怎么做这个硒的webdriver利用量子框架。
提前致谢。下面我粘贴HTML标签:
<div _ngcontent-c23="" class="col-xs-12 col-sm-6 col-md-6 col-lg-4 space-column ng-star-inserted" data-index="0">
<cws-cardbox _ngcontent-c23="" _nghost-c28="" class="Investment0" ng-reflect-ng-class="Investment0" ng-reflect-status="A"><div _ngcontent-c28="" class="card-status active" ng-reflect-klass="card-status" ng-reflect-ng-class="[object Object]">
</div>
<div _ngcontent-c28="" class="card-box">
<div _ngcontent-c23="" class="policy">
<span _ngcontent-c23="" class="planType">Investment</span>
<span _ngcontent-c23="" class="product">
Inheritance
</span>
<div _ngcontent-c23="" class="policy-no">
<label _ngcontent-c23="" class="policy-label">
Policy No.:
</label>
<span _ngcontent-c23="" class="policy-value">8000000001</span>
</div>
</div>
<div _ngcontent-c23="" class="divider"></div>
<!--bindings={
"ng-reflect-ng-if": "false"
}-->
<!--bindings={
"ng-reflect-ng-if": "true"
}--><div _ngcontent-c23="" class="policy-content ng-star-inserted">
</div>
</div>
</cws-cardbox>
</div>
下面是我的代码:
如何确保验证只会循环到div标签data_index0?
@QAFTestStepProvider
public class cwsPolicyCardStepDef{
@QAFTestStep(description = "validate data index")
public void dataIndexValidation() {
QAFExtendedWebElement dataIndex0 = new QAFExtendedWebElement("xpath_of_data_index_0");
QAFExtendedWebElement planType = new QAFExtendedWebElement("xpath_of_plan_type");
dataIndex0.verifyPresent("data index 0 is present...");
planType.verifyPresent("plan type 'Investment' is inside data index 0... ");
}
}
我也试图找到一个元素中的属性,但我不知道,虽然这是如何工作。下面是该函数:
public boolean isAttribtuePresent(WebElement element, String attribute) {
Boolean result = false;
try {
String value = element.getAttribute(attribute);
if (value != null){
result = true;
}
} catch (Exception e) {}
return result;
}
我已经解决了的问题和方式...
下面是我做的代码...
@QAFTestStep(description = "user validate that policy card in desktop {0} contains plan type {1}, policy product {2}, policy value {3}, policy label {4} and status is {5} highlighted in {6}")
public void userValidateEachPolicyCards(String dataIndex, String planType, String policyProduct, String policyValue, String policyLabel, String policyStatus, String policyStatusColor) {
String sGetCardBoxStatus;
String sGetCardBoxColor;
String sGetCardBoxPlanTypeValue;
String sGetCardBoxProduct;
String sGetCardBoxLabel;
String sGetPolicyNumber;
sGetCardBoxColor = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::div[contains(@class, 'card-status')]")).getCssValue("background-color"); //.getAttribute("background-color");
if((Color.fromString(sGetCardBoxColor).asHex()).equals(policyStatusColor)) {
Reporter.log("Passed: Policy Status Color: "+ policyStatusColor, MessageTypes.Pass);
}else {
Reporter.log("Failed: Policy Status Color is not "+ policyStatusColor, MessageTypes.Fail);
}
sGetCardBoxStatus = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::div[contains(@class, 'card-status')]")).getAttribute("class");
if(sGetCardBoxStatus.equals(policyStatus)) {
Reporter.log("Passed: Policy Status: "+ policyStatus, MessageTypes.Pass);
}else {
Reporter.log("Failed: Policy Status is not "+ policyStatus, MessageTypes.Fail);
}
sGetCardBoxPlanTypeValue = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::span[contains(@class, 'planType')]")).getText();
if(sGetCardBoxPlanTypeValue.equals(planType)) {
Reporter.log("Passed: Plan Type: "+ planType, MessageTypes.Pass);
}else {
Reporter.log("Failed: Plan Type is not "+ planType, MessageTypes.Fail);
}
sGetCardBoxProduct = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::span[contains(@class, 'product')]")).getText();
if(sGetCardBoxProduct.equals(policyProduct)) {
Reporter.log("Passed: Policy Product: "+ policyProduct, MessageTypes.Pass);
}else {
Reporter.log("Failed: Policy Product is not "+ policyProduct, MessageTypes.Fail);
}
sGetCardBoxLabel = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::label[contains(@class, 'policy-label')]")).getText();
if(sGetCardBoxLabel.equals(policyLabel)) {
Reporter.log("Passed: Policy Label: "+ policyLabel, MessageTypes.Pass);
sGetPolicyNumber = DriverUtils.getDriver().findElement(By.xpath("*//div[@data-index = '"+ dataIndex +"']/descendant::span[contains(@class, 'policy-value')]")).getText();
if(sGetPolicyNumber.equals(policyValue)) {
Reporter.log("Passed: Policy Number: "+ sGetPolicyNumber, MessageTypes.Pass);
}
else {
Reporter.log("Failed: Either Policy Label or Policy Number is not found...", MessageTypes.Fail);
}
}
}
}