Search code examples
xmlweb-servicesxpathbddqaf

QAF - Webservices testing not fetching Xpath value from XML


I'm trying to do Webservices Testing using QAF 3.0 Below is my BDD for the Test.

Scenario: [WS-2]_[222-xml]_Sample XML Webservices
    When I request api "get.mock.xml.menu"
    Then I check api response status code is "200"
    And I check api response status is "OK"
    And I check api response should have xpath '/breakfast_menu'

First three lines are executing without any issues. Internally I'm calling QAF WsStep.

Note: Json path verification is working perfectly without any issues.

StepDef:

@QAFTestStep(description = "I check api response should have xpath {xpath}")
public static void iCheckApiResponseShouldHaveXpath(String xpath) {
    WsStep.responseShouldHaveXpath(xpath);
}

Solution

  • In your case breakfast_menu is root node, so it will be consider as context (root) and will be accessible as .. You should be able to use following xpaths:

    .
    ./food
    //food
    ./food/name
    ./food[name='Belgian Waffles']
    //food[name='Belgian Waffles']
    //*[name='Belgian Waffles']