简体   繁体   English

如何根据应用程序屏幕上的标签使UFT脚本跳过excel中的单元格

[英]How do I make my UFT script skip a cell in excel based on the labels on the application screen

I have a very dynamic application to automate using UFT. 我有一个非常动态的应用程序可以自动使用UFT。 The labels on the application screen change based on the input provided by the user. 应用程序屏幕上的标签会根据用户提供的输入进行更改。 I have an excel where I have set the field value for all possible fields present in the application. 我有一个excel,可以为应用程序中存在的所有可能字段设置字段值。 The challenge is I want my UFT script to pick only those field values for which it finds the field name on screen. 挑战在于,我希望我的UFT脚本仅选择那些它在屏幕上找到字段名称的字段值。 Each time I run the script, based on the selection whatever fields apppear on the screen, I want it to pick only those corresponding values from the excel sheet and ignore the other values in that excel sheet. 每次运行脚本时,基于选择,屏幕上都会显示任何字段,我希望它仅从excel工作表中选择那些相应的值,而忽略该excel工作表中的其他值。

Eg 例如

Excel has the following vales Excel具有以下值

Name: Nancy Grade: 8 Hobby: Writing Friend: Veronica BFF: Karen 姓名:南希(Nancy)成绩:8业余爱好:写作朋友:维罗妮卡(Veronica)BFF:卡伦(Karen)

But in the application on screen only the following labels appear 但是在屏幕上的应用程序中,仅以下标签出现

Name: Hobby: BFF: 名称:爱好:BFF:

I want the UFT script to compare the field label on screen with that in excel and pick those values from excel (in this case Name, Hobby, BFF) and ignore the other fields (Grade and Friend) . 我希望UFT脚本将屏幕上的字段标签与excel中的标签进行比较,并从excel中选择这些值(在本例中为Name,Hobby,BFF),并忽略其他字段(Grade和Friend)。

Is this possible? 这可能吗?

Why not just using 为什么不只是使用

If Obj1.Exist(5) Then
    Obj1.Set ValueFromExcel1
End if

If Obj2.Exist(5) Then
   Obj2.Set ValueFromExcel2
End if

Let's assume your application presents various editboxes on a form for input, and you are using the DataTable object to store your Excel file. 假设您的应用程序在表单上显示各种编辑框供输入,并且您正在使用DataTable对象存储Excel文件。

Ok, here's what I would do. 好的,这就是我要做的。

First... I'd gather the objects into the Object Repository. 首先...我将对象收集到对象存储库中。 I would create/record each possible edit box as a separate object (within an object for the app itself), making sure that each object is uniquely identifyable by name... (if the edit box controls themselves aren't uniquely named behind the scenes, QTP offers the ability to link to the captions next to them...). 我会将每个可能的编辑框创建/记录为一个单独的对象(在应用程序本身的对象内),确保每个对象都可以通过名称唯一标识...(如果编辑框控件本身不是唯一地命名为场景,QTP可以链接到它们旁边的字幕...)。 Also, if the application merely HIDES the edit boxes, then make sure Visible=True is one of the idenfitying attributes, such that when Visible=False, they are not found. 另外,如果应用程序仅隐藏编辑框,则确保Visible = True是可识别的属性之一,以便在Visible = False时找不到它们。

Once every object is in the OR, then it's a simple matter of checking if they exist. 一旦每个对象都在“或”中,则只需检查它们是否存在即可。

'assuming your excel file is already imported as the global DataTable
if Window("My App").Editbox("Name").exist(0) then Window("My App").Editbox("Name").Set DataTable("Name")
if Window("My App").Editbox("Grade").exist(0) then Window("My App").Editbox("Grade").Set DataTable("Grade")
if Window("My App").Editbox("Hobby").exist(0) then Window("My App").Editbox("Hobby").Set DataTable("Hobby")
if Window("My App").Editbox("Writing Friend").exist(0) then Window("My App").Editbox("Writing Friend").Set DataTable("Writing Friend")
if Window("My App").Editbox("BFF").exist(0) then Window("My App").Editbox("BFF").Set DataTable("BFF")

Of course, this example is inefficient and can be easily rolled up (ie you could make a UDF, and call it from a loop reading field names from an array...) But, it should demonstrate this simple approach. 当然,此示例效率低下,并且可以轻松汇总(即,您可以创建UDF,然后从循环中调用它来从数组中读取字段名称...),但是,它应该演示此简单方法。

I agree with the @theblastone you should provide some code to help understand your situation better. 我同意@theblastone,您应该提供一些代码以帮助更好地了解您的情况。 Anyhow I will try to answer your question. 无论如何,我会尽力回答您的问题。 The following is an example and you can build your code around it. 以下是一个示例,您可以围绕它构建代码。 I am not sure how the labels are appearing in your application, I am going to assume each label can be identified separately. 我不确定标签在您的应用程序中如何显示,我假设每个标签都可以单独识别。

j = Datatable.localsheet.GetRowCount

For i = 1 to j
Datatable.LocalSheet.SetCurrentRow i

vout = trim(Datatable("Excel column name",dtlocalsheet))
'Not sure about the following line
vin = browser().page().Webtable().getcelldata(r,c)
If not trim(Ucase(vout))= trim(Ucase(vin)) Then
Datatable("Result",dtlocalsheet) = "Invalid Record"
Do Until trim(Ucase(vout))= trim(Ucase(vin))
i=i+1
If i > j Then
ExitAction  
End IF
Datatable.LocalSheet.SetCurrentRow I
Datatable("Result",dtlocalsheet) = "Invalid Record"
vout = trim(Datatable("Excel column name",dtlocalsheet))
Loop
End If  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM