我正在做一个项目,需要在运行时动态导入测试数据并运行与测试数据对应的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:
===========================================================================
从 Excel 文件导入数据的步骤:
=========================================================================
Steps to import data from Excel file:
打开 数据
窗格(查看 -> 数据)
点击新数据源
Open Data
pane (View -> Data)
Click on New Data Source
选择 Database
(别担心我们会使用 Excel 作为数据库)Set Database Connection
将出现新窗口点击建立连接字符串
图标
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
点击下一步
在 Data Source
部分,提供 Excel (.XLSX
) 文件的路径,并将所有内容保留为默认值此(连接)选项卡
点击高级
标签
从访问权限
部分
中选择Read Write
转到全部
标签
选择Extended Properties
并点击Edit Value
在 Property Value
字段中输入 Excel 12.0 Xml
并点击 OK
强>
现在返回 Connection
选项卡并点击 Test Connection
按钮
它应该显示 Test connection succeeded
消息,如果不是,请返回并再次执行所有步骤
点击确定
点击下一步
在 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
窗口上的 Finish
现在您应该在数据窗格中看到结果行
* 我喜欢这种方法的地方是,如果您在 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 活动
注意:这只是一个给出想法的例子
=========================================================================
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
将从文件读取活动
拖放到您的工作区
这将抱怨没有为在 Errors 窗格中读取的文件指定路径
双击此消息,它将在 Properties
窗格中为您突出显示该字段
将鼠标悬停在文件路径旁边的值字段上,然后单击最后一个图标 Link to data source
,这将打开 Select Link Source for 'File path'
窗口
点击 Data source column
单选按钮,然后点击 TEST_DATA
from Select a 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
===========================================================================
同样,您可以通过数据窗格将值/s 从 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 文件:
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 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!