使用 Robot Framework,我无法在 XML 中获取某些元素
Using Robot Framework, I am unable to get some elemnts in XML
下面是 XML 文件内容:
<?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>
我正在尝试获取每个报告下的标题并检查是否有条件,显示条件的类型及其值。
我尝试了以下方法:
${xml_obj}= Parse XML ${xmlFile}
${title}= Get Element Text ${xml_obj} @title
Log To Console ${title}
//没有显示任何内容,RIDE 无法识别 @ 符号。
此外,创建了一个 for 循环来查找条件:
@{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
我是 RFW 的新手,我被要求创建一个测试套件,从 XML 中提取数据,然后将其与网页数据进行比较。
谁能告诉我更好的方法?
谢谢,
您不能使用获取元素文本来获取标题,因为标题是一个属性。此代码解析报告中的标题,应该可以帮助您入门:
*** 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
下面是 XML 文件内容:
<?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>
我正在尝试获取每个报告下的标题并检查是否有条件,显示条件的类型及其值。
我尝试了以下方法:
${xml_obj}= Parse XML ${xmlFile}
${title}= Get Element Text ${xml_obj} @title
Log To Console ${title}
//没有显示任何内容,RIDE 无法识别 @ 符号。
此外,创建了一个 for 循环来查找条件:
@{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
我是 RFW 的新手,我被要求创建一个测试套件,从 XML 中提取数据,然后将其与网页数据进行比较。
谁能告诉我更好的方法?
谢谢,
您不能使用获取元素文本来获取标题,因为标题是一个属性。此代码解析报告中的标题,应该可以帮助您入门:
*** 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