Как проверить текст внутри каждого индекса в селеновом веб-драйвере с помощью Quantum frawework - PullRequest
0 голосов
/ 31 января 2019

В приведенном ниже теге html я хотел бы сначала проверить, если «data index = 1», а затем, если да, тогда я проверю, должна ли эта картонная коробка содержать здоровье, а затем продукт и политика #.

Как я должен сделать это в селен вебдрайвер с использованием квантовой рамки.

Заранее спасибо.Ниже я вставляю тег 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;
}   

1 Ответ

0 голосов
/ 08 февраля 2019

Я уже решил проблему и подхожу ...

Ниже приведен код, который я сделал ...

    @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);
            }
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...