Highlighted
Respected Contributor.
Respected Contributor.
641 views

How to write to data file in API test

Hi,

I am learning the api test using UFT. I have done the following.

1. added concatenated strings to canvas. Prefix is pointing to a column which has 3 rows. Suffix is pointing to another column which has 3 rows. That means I have a local table with two columns prefix and suffix with 3 rows of data.
Properties tab > Prefix and suffix value pointing to corresponding column in data source.

2. Added "file created" to canvas.
Overwrite = true

3. "Write to file" added to canvas.
Content = pointed to data source.

{DataSource.Concatenated Strings..Prefix}
{DataSource.Concatenated Strings..Suffix}

File path = same as step 2.

mode = append to existing file

encoding = ASCII

Apprend new line = true


When I run my test, I expect 3 rows of data to be inserted into the file. But I only get the last row data from data source. How can I have 3 rows of data in the file?

0 Likes
1 Reply
Highlighted
Trusted Contributor.
Trusted Contributor.

HelloI am preatty sure how to solve your problem, 

What is happening is that you have an two step on your canvas the first is  concatenating tyour 3 rows as expected, and after that your are writing the result to the file, and that result would be the result of the last iteration, 

what you need to do is go to your test flow an use the 'For Each' Loop and Loop for each item in : DataSource.Concatenated Strings

thay way the API will concatanate the string, write to file and then the new iteration will begin and so on...

I hope this helps, 

I attach some screnshots to show you how I did it

Best Regards,

Arturo

 

 

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.