Home > Net >  Using Robot Framework, I am unable to get some elemnts in XML
Using Robot Framework, I am unable to get some elemnts in XML

Time:11-17

Below is the XML file contents:

   <?xml version="1.0" encoding="UTF-8"?>
<reports>

<!--
    ===================
          Title
    ===================
-->

    <report landingPageWidgetType="SECTION_CONTROLLER"
            width="3"
            title="Marketing"
            showTimespanFilter="true"
            backgroundColor="#0F8287">
    </report>

<!--
    ===================
          1st row
    ===================
-->

    <report reportQueryType="GENERAL_COUNTS"
            landingPageWidgetType="COUNTER_REPORT"
            generalCountsCounters="TOTAL_USERS,ACTIVE_USERS,NEW_USERS,SESSIONS"
            timeType="LAST_MONTH"
            width="3"
            title="Users"
            reportType="STATIC"
            chartType="COUNTERS">
        <Parameters>
            <Conditions>
                <Condition type="USERS_REPORTED">true</Condition>
            </Conditions>
        </Parameters>
    </report>

    <report reportQueryType="GENERAL_COUNTS"
            landingPageWidgetType="COUNTER_REPORT"
            generalCountsCounters="TOTAL_ENDPOINTS,ACTIVE_ENDPOINTS,NEW_ENDPOINTS,SESSIONS"
            timeType="LAST_MONTH"
            width="3"
            title="Endpoints"
            reportType="STATIC"
            chartType="COUNTERS">
        <Parameters>
            <Conditions>
                <Condition type="USERS_REPORTED">false</Condition>
                <Condition type="SINGLE_ENDPOINT">false</Condition>
            </Conditions>
        </Parameters>
    </report>

<!--
    ===================
          2nd row
    ===================
-->

    <report reportQueryType="GEOGRAPHIC_USERS"
            landingPageWidgetType="STANDARD_REPORT"
            timeType="LAST_12_MONTHS"
            width="2"
            title="Usage Map: Users"
            reportType="MAP"
            xAxisTitle="Country"
            yAxisTitle="# of Users">
        <Parameters>
            <Conditions>
                <Condition type="USERS_REPORTED">true</Condition>
                <Condition type="CUSTOMERS_REPORTED">true</Condition>
            </Conditions>
        </Parameters>
    </report>

    <report reportQueryType="GEOGRAPHIC_USERS"
            landingPageWidgetType="STANDARD_REPORT"
            timeType="LAST_12_MONTHS"
            width="3"
            title="Usage Map: Users"
            reportType="MAP"
            xAxisTitle="Country"
            yAxisTitle="# of Users">
        <Parameters>
            <Conditions>
                <Condition type="USERS_REPORTED">true</Condition>
                <Condition type="CUSTOMERS_REPORTED">false</Condition>
            </Conditions>
        </Parameters>
    </report>

I'm trying to get the title under each report and to check if there's a condition, display the type of the condition and its value.

I tried the following:

${xml_obj}= Parse XML   ${xmlFile}          
${title}=   Get Element Text    ${xml_obj}  @title      
Log To Console  ${title}                

//nothing was shown and RIDE didn't recognize the @ sign.

Also, created a for loop to look for Conditions:

    @{reports}= Get Elements    ${xml_obj}  .//report//Conditions       
${elemList}=    Get elements    ${reports}[0]   *       
@{elemList}=    Convert To List ${elemList}     
Log To Console  ${elemList}             // also it was shown empty. 

FOR ${var}  IN  @{elemList}     
    @{report_title}=    Get Elements Texts  ${var}  title   
    Log To Console  ${report_title}         
END                 

I'm new at RFW and I am asked to create a test suite which extracts data from XML then compares it to a webpage's data.

Anyone can direct me to a better approach?

Thanks,

CodePudding user response:

You cannot use Get Element text to get title, because title is an attribute. This code parses title from reports and should get you started:

*** Settings ***
Library    XML

*** Variables ***
${xmlFile}    MyXMLFile.xml

*** Test Cases ***
Parse title
    ${xml_obj}=     Parse XML       ${xmlFile}
    @{elements}=    Get Elements    ${xml_obj}   report
    FOR             ${element}   IN    @{elements}
        ${title}=         Get Element Attribute    ${element}    title
        Log To Console    ${title}
    END
  • Related