Highlighted
Frequent Contributor.
Frequent Contributor.
1329 views

How to save the datatable with UFT API Testing

Hello,

I can use input values from an excel file with the datable but I would like to save the excel file with new values in it and the OK, KO results.

Do I have to create an GUI Test in  my API test to add VB code ? 

I hope there is something easier.

Regards

0 Likes
6 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

Hi,

When you add new excel data source, choose the option => Link to the Excel file in its original location. (Refer to snapshot_1)

If you have any modification in excel, save the API test and the excel will be auto saved.

Regards,

Angel

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

Thank you. But do you know how to write values automatically in the datatable ?

Regards. 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

AFAIK, UFT API test don't have such activities to support write values in datatable.

However, you could write C# code in event handler if you are familiar with C#.

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

Hi,

I just tried this code in C#:

GetDataSource("Data-Set!Sheet1").SetValue(2,"Results","OK");

The test is OK but I can't see the new value in the datatable at the end of the test.

Would you know why ?

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

Actually, I tried this:

var msg = GetDataSource("Data-Set!Sheet1").GetValue(2,"Results");

MessageBox.Show(msg.ToString());

 

So I can get a message box with the new value but nothing in the datatable.

 

 

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

hi,

If you have a datatable linked to the test, when it starts running, the datatable is copied to memory datatable as a runtime datasource. So what you read or write in the code here is only doing things to the runtime datatable, not the actual file you want to update. 

If you want to change the file itself, you need to code to work with the Excel file insteady of the DataSource API working on the Sheet.

I hope this helps.

James

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.