在下面的html标记中,我想首先检查“ data index = 1” 然后,如果是,我将检查该Cardbox是否必须包含健康状况,然后检查产品和策略编号。
我应该如何使用量子框架在Selenium Webdriver中做到这一点。
先谢谢了。在下面粘贴htm标签:
<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;
}
答案 0 :(得分:0)
我已经解决了问题和解决方法...
下面是我编写的代码...
@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);
}
}
}
}