如何导入数据文件以进行UFT API测试? [英] How to import data file for UFT API testing?
问题描述
我正在从事一个项目,该项目需要在运行时动态导入测试数据并运行与测试数据相对应的API测试.
I am working on a project which requires to dynamically import the test data on run time and run the API test corresponding to the test data.
我尝试使用直接从xml请求加载的XMLload.这似乎工作正常.
I tried using XMLload which I directly load from the xml request. This seems to be working fine.
但是,就像GUI测试(我们在其中导入测试数据)一样,我也希望API测试也是如此-在这里我可以动态地从外部源导入excel并将值提供给请求.
But like GUI testing, where we import the test data, I want the same for API testing - where I can import a excel from an external source dynamically and give the values to the request.
我该怎么做?
推荐答案
据我所知,您想从Excel文件中加载测试数据.这就是我在上一个项目中所做的,但没有什么不同,所以我希望这对您有用.
As far as I understand your question, you want to load test data from Excel file. And that is what I have done in my previous project but little differently, so I hope this will be some what useful to you.
这些步骤将帮助您从Excel文件驱动测试,在其中您将提供请求XML文件和其他测试数据的位置,例如:
These steps will help you drive your test from Excel file where you will provide the location of request XML files and other test data, for example:
- 执行标志
- WSDL
- 终点地址
- 环境
- 依此类推...
================================================ ========================
从Excel文件导入数据的步骤:
=========================================================================
Steps to import data from Excel file:
打开 Data
窗格(查看->数据)
点击 on New Data Source
Open Data
pane (View -> Data)
Click on New Data Source
选择 Database
(不用担心,我们会将Excel用作数据库)
新窗口将出现在 Set Database Connection
点击 Build Connection String
图标
Select Database
(Don't worry we'll be using Excel as Database)
New window will appear to Set Database Connection
Click on Build Connection String
icon
如果未选中,请单击 Provider
标签.
选择 Microsoft Office 12.0 Access Database Engine OLE DB Provider
点击 Next
在 Data Source
部分中,提供Excel( .XLSX
)文件的路径,并将所有内容保留在此(连接")选项卡上为默认值
点击 Advanced
标签
从 Access permissions
部分中选择 Read Write
转到 All
标签
选择 Extended Properties
,然后单击 Edit Value
在 Property Value
字段中键入 Excel 12.0 Xml
,然后点击 OK
现在返回 Connection
标签,然后点击 Test Connection
按钮
如果没有,它应该显示 Test connection succeeded
消息,然后返回并再次执行所有步骤.
点击 OK
点击 Next
在 Data Source name
字段
中提供工作表名称(要导入).
例如: [TEST_DATA$]
,其中 TEST_DATA
是工作表名称
在 Check SQL Statement
按钮
上方的大框中键入您的SQL查询.
例如:
我想从TEST_DATA工作表中Execution_Flag列具有Y值的所有行导入.以及我使用过的SQL语句:
Click on Provider
tab if not selected
Select Microsoft Office 12.0 Access Database Engine OLE DB Provider
Click Next
In Data Source
section, provide the path to your Excel (.XLSX
) file and leave everything to default on this (Connection) tab
Click on Advanced
tab
Select Read Write
from Access permissions
section
Go to All
tab
Select Extended Properties
and click on Edit Value
Type Excel 12.0 Xml
in Property Value
field and hit OK
Now go back to Connection
tab and click on Test Connection
button
It should show Test connection succeeded
message, if NOT than go back and follow all the steps again
Click on OK
Click Next
Provide the sheet name (that you want to import) in Data Source name
field
For example: [TEST_DATA$]
where TEST_DATA
is a sheet name
Type in your SQL query in big box just above Check SQL Statement
button
For example:
I want to import all the rows from TEST_DATA sheet where Execution_Flag column is having Y value. And SQL statement for that I've used:
SELECT * FROM [TEST_DATA$] WHERE Execution_Flag = 'Y'
单击 Check SQL Statement
按钮,它应该在新的 Query Preview
窗口中显示结果行
关闭 Query Preview
窗口,然后在 Set SQL Statement
窗口上单击完成"
现在,您应该在数据"窗格中看到结果行.
*我喜欢这种方法,如果您将在Excel文件中进行更改并刷新数据"窗格,它将自动更新 Data
窗格
Click on Check SQL Statement
button and it should to show the resulted rows in new Query Preview
window
Close Query Preview
window and click on Finish on Set SQL Statement
window
Now you should see resulted rows in Data pane
* What I like about this approach is if you'll make changes in Excel file and refresh the Data pane, it will automatically update the data in Data
pane
================================================ ========================
现在从Excel文件中读取数据:
假设我要从Excel文件(我们已导入)中指定的位置读取我的请求XML文件.
我正在使用 Read From File activity
注意:这只是一个给出想法的示例
=========================================================================
Now to read the data from Excel file:
Let's say I want to read my request XML file from location specified in Excel file (which we have imported)
I am using Read From File activity
Note: This is just an example to give an idea
将 Read From File activity
拖放到您的工作区域中
这将抱怨在错误窗格
中未指定要读取文件的路径.
双击此消息,它将在 Properties
窗格
中为您突出显示该字段.
将鼠标悬停在文件路径"旁边的值"字段上,然后单击最后一个图标 Link to data source
,这将打开 Select Link Source for 'File path'
窗口
单击 Data source column
单选按钮,然后从 Select a data source
部分
中单击 TEST_DATA
从 Select data
部分中选择相应的列名称,然后单击 OK
,如图
Drag and drop Read From File activity
in your work area
This will complain that path is not specified for the file from which to read in Errors pane
Double click this message and it will highlight the field for you in Properties
pane
Hover your mouse on Value field next to File path and click on last icon Link to data source
and this will open Select Link Source for 'File path'
window
Click on Data source column
radio button and then click on TEST_DATA
from Select a data source
section
Select the corresponding column name from Select data
section and click OK
, like shown in image
================================================ ========================
同样,您可以通过链接数据源并将其作为输入传递,通过数据窗格将值从Excel文件传递到自定义代码",在自定义代码中,您可以通过以下方式检索值:
=========================================================================
Similarly you can pass value/s to Custom Code from Excel file through Data pane by linking data source and passing it as input and in custom code you can retrieve the value this way:
string environmentName = CodeActivity18.Input.Environment_Name;
使用相同的方法可以将Excel代码作为自定义代码的输出写入Excel文件:
And same way you can write to Excel file as an output from custom code:
string finalResponseXMLPath = "some path";
CodeActivity18.Output.ResponseXML_FinalPath = finalResponseXMLPath;
这篇关于如何导入数据文件以进行UFT API测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!