cancel
Showing results for 
Search instead for 
Did you mean: 

Downloading and looking at a file

SOLVED
Highlighted
Occasional Contributor

Downloading and looking at a file

I am having difficulties attempting to script running a report, then downloading the report from the test site in order to veridy a set of values is on the file. Does anyone have a best practice or an example they wouldnt mind sharing? The file can be of any real format, txt, csv, excel, etc... But im sure once I can do it with one, the others would not be too terrible.

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Manager

Re: Downloading and looking at a file

Hi @WillClarke,

 

The following article contains an example of how you can download a file from the Internet:

https://support.smartbear.com/viewarticle/8999/

 

As the formats of the file are different, you will need to create (or use existing) different approaches to read the files as there is no one common way. Just review the following articles demonstrating how you can work with txt, xml and excel file from TestComplete:

Working With Microsoft Excel Files

Working With XML Files From Scripts

Reading Text Files

 

The pseudocode will look like:

//download the file

//check its format and read
switch (<File_Format>){
  case "xml": 
    // read an xml file
  case "txt":
    // read a txt file
....
}

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Occasional Contributor

Re: Downloading and looking at a file

Thanks for the answers, just putting this code snippet here incase someone wants to not have to look through multiple links

 

This is the code I used to check to see if a csv file has a value for a specific column. Luckily with the update to TC 14, the CSVDriver was super easy to use, Also you will most likely need to download 

Microsoft Access Database Engine 2010 Redistributable here -> https://www.microsoft.com/en-us/download/details.aspx?id=13255

function GEN_FILE_TestCSV(FilePath, ColumnName, ColumnValue)
{
  var HasValue;
  HasValue = false;
  DDT.CSVDriver(FilePath);
  // Iterates through records
  while (! DDT.CurrentDriver.EOF()) {
    if (DDT.CurrentDriver.Value(ColumnName) == ColumnValue) {
      HasValue = true;
    }
    DDT.CurrentDriver.Next(); 
  }
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);
  if(HasValue == false) {
    //Posts an error to the test log. 
    Log.Error("The Expected Value looked for in the file is not there", ""); 
  } else {
    Log.Message("The Expected Value looked for in the file is there", ""); 
  }
}
4 REPLIES 4
Community Hero

Re: Downloading and looking at a file

When we were just verifying values and not format, we shoved all of the text from the report into a variable and just searched the string for the values.

 

If you're worried about format, you could use pictures to compare, but we didn't bother automating that step.  Get the report done right and tested manually once and the format's probably not going to change so why spend the time on it.  

Community Manager

Re: Downloading and looking at a file

Hi @WillClarke,

 

The following article contains an example of how you can download a file from the Internet:

https://support.smartbear.com/viewarticle/8999/

 

As the formats of the file are different, you will need to create (or use existing) different approaches to read the files as there is no one common way. Just review the following articles demonstrating how you can work with txt, xml and excel file from TestComplete:

Working With Microsoft Excel Files

Working With XML Files From Scripts

Reading Text Files

 

The pseudocode will look like:

//download the file

//check its format and read
switch (<File_Format>){
  case "xml": 
    // read an xml file
  case "txt":
    // read a txt file
....
}

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Occasional Contributor

Re: Downloading and looking at a file

Thanks for the answers, just putting this code snippet here incase someone wants to not have to look through multiple links

 

This is the code I used to check to see if a csv file has a value for a specific column. Luckily with the update to TC 14, the CSVDriver was super easy to use, Also you will most likely need to download 

Microsoft Access Database Engine 2010 Redistributable here -> https://www.microsoft.com/en-us/download/details.aspx?id=13255

function GEN_FILE_TestCSV(FilePath, ColumnName, ColumnValue)
{
  var HasValue;
  HasValue = false;
  DDT.CSVDriver(FilePath);
  // Iterates through records
  while (! DDT.CurrentDriver.EOF()) {
    if (DDT.CurrentDriver.Value(ColumnName) == ColumnValue) {
      HasValue = true;
    }
    DDT.CurrentDriver.Next(); 
  }
  // Closes the driver
  DDT.CloseDriver(DDT.CurrentDriver.Name);
  if(HasValue == false) {
    //Posts an error to the test log. 
    Log.Error("The Expected Value looked for in the file is not there", ""); 
  } else {
    Log.Message("The Expected Value looked for in the file is there", ""); 
  }
}
Community Hero

Re: Downloading and looking at a file

> if a csv file has a value for a specific column.

There is no need to continue iterating through the file if a value is found.

Thus I would break the loop in this case:

while (! DDT.CurrentDriver.EOF()) {
  if (DDT.CurrentDriver.Value(ColumnName) == ColumnValue) {
    HasValue = true;

    break;
  }
  DDT.CurrentDriver.Next();
}

 

Just my $0.02... Smiley Happy

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================