Ask a Question

Find a specific file when the folder get created during run time.

SOLVED
nedbacan
Frequent Contributor

Find a specific file when the folder get created during run time.

Please need help, I am testing this web application that creates a dynamic folder every time an image is displayed within the software, Here are my test steps.

1) select the customer.

2) select the image to display in the IMAGE view screen. 

(note:  I can get the image number (i.e 001) within this window)

3) The software creates a folder (i.e 001) using the number assigned for that image in the following path C:\Storage\cache\. (example: C:\Storage\cache\001

4) Within the cache folder, it will create a file called "imagesnap.jpg"

3) My test result is to make sure the "imagesnap.jpg file exists in the dynamic folder that got created when the image got displayed within the software being tested.

4)  The imagesnap.jpg file must exist in every cache folder that is created when an image is displayed in the window.

 

Before I was using the script below to find the file but now I need to check the cache folder gets created on run time and the file imagesnap.jpg exist in the created cache folder.

 

Can the script be modified to do this?

 

  1. If someone can give an example of how to store the image name (i.e 001) taken from the window display screen and use it in the script.  
  2. Then, compare the stored image name (i.e 001) to the cache folder (i.e ...\001) created in the C:\Storage folder.
  3. Next, verify the imagesnap.jpg file exist in the cache folder for that image name (i.e C:\Storage folder\001\imagesnap.jpg)  and log message "File imagesnap.jpg file exist in cache folder " 001 "
  4. if not,  get a log message "File does not exist".    Help is really appreciated.

 

function FileJPGFinder()

{

  var foundFiles, aFile;

  foundFiles = aqFileSystem.FindFiles("C:\\Storage\\", "imagesnap.jpg");

  if (foundFiles != null)

    while (foundFiles.HasNext())

    {

      aFile = foundFiles.Next();

      Log.Message(aFile.Name);

    }

  else

    Log.Message("No JPG files were found.");

 

 

11 REPLIES 11
Marsha_R
Champion Level 2

store the image number in a variable

if image number is not a string, you may need to convert it using aqConvert

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/inttostr.html

MyImageNumber =  (value found in window)

 

now create the folder name 

MyFolderName = "C:\Storage\cache\" + MyImageNumber

 

now use that name in your file search

aqFileSystem.FindFiles(MyFolderName, "imagesnap.jpg")

 

 

nedbacan
Frequent Contributor

Hi Marsha_R

 

I do appreciate the help you have given me, I am somewhat new to this so please excuse the questions.

 

The MyImageNumber is a string.

 

The value captured from the window adds the file extension (.jpg) to the ImageNumber (001.jpg).

The folder name that gets dynamically created will be "001".  (example: C:\Storage\cache\001).  

I don't know how to capture it from the property to exclude the "jpg". 

So It takes the whole string and adds it to the variable MyImageNumber  = "001.jpg"

 

My question is how can I omit the jpg from the variable that it can be "001" and not "001.jpg"

 

I need "001" in MyImageNumber  variable so I can find the Folder name (001) that was just created.

 

If you can show an example, it will be hugely appreciated.   Or have other suggestions. 

 

 

Thank you

 

 

 

 

first you look for the period in the file name

var MyPeriodLocation= aqString.Find(MyImageNumber,".",0)

 

now you get the first part of the file name, up to the period

var NoMoreJPG= aqString.Substring(MyImageNumber,0,MyPeriodLocation)

 

so your folder name is 

MyFolderName = "C:\Storage\cache\" + NoMoreJPG

 

Here's a good reference for operations that you can do with strings.  When you get more experience with it, you can combine some of the steps but it's good to do them one step at a time if you aren't sure of the answers.  Sometimes I will also add a log message after each step to print out the answer and make sure it's doing what I meant it to do.  

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/methods.html

 

nedbacan
Frequent Contributor

Great, I was able to get the filename without the file extension.  Kudos to you !!!!

 

Thank you very much. 

 

nedbacan
Frequent Contributor

One more step to complete the script, now that I have the folder name stored, how should the Find Folder method be put together with the Find File.  I guess first find the folder name stored in MyFolderName and then the find the file "imagesnap.jpg" in the folder name stored in MyFolderName.   Can this be put in the same function or separating it is best?

 

Can you give example?   

 

The following is how you showed me howw to get the folder name.

 

function whatIsVariable(){
var MyImageNumber = Aliases.browser.pageImagenet.panelOctfilename0.contentText  //captures 001.jpg text
Log.Message(MyImageNumber)  //shows text 001.jpg
var MyPeriodLocation= aqString.Find(MyImageNumber,".",0)
var NoMoreJPG = aqString.Substring(MyImageNumber,0,MyPeriodLocation)
Log.Message(NoMoreJPG)   //shows just 001
MyFolderName = "C:/Storage/octCache/" + NoMoreJPG;
Log.Message(MyFolderName)   //shows just 001
}

 

Hi,

 

MyFolderName = "C:/Storage/octCache/" + NoMoreJPG;

Try

var MyFolderName = "C:\\Storage\\octCache\\" + NoMoreJPG;

Does it help?

 

P.S. BTW, your initial code works fine for me using JScript. Is your code on JScript or JavaScript?

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] 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. Posts made by [Community Champions]
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.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nedbacan
Frequent Contributor

The script is in JAVA script and it works fine. 

 

It will capture what the folder name will be, my question is one step further; how to find the file "imagesnap.jpg" file after the var MyFolderName is known

 

The statement  MyFolderName = "C:\\Storage\\Cache\\" + NoMoreJPG;
Log.Message(MyFolderName) // shows C:\Storage\Cache\1341 

 

When the folder gets created, I need to verify imagesnap.jpg exist within the folder MyFolderName.

 

Thank you

 

 

 

 

Hi,

 

I need to verify imagesnap.jpg exist within the folder MyFolderName.

Use aqFile.Exists() method.

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] 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. Posts made by [Community Champions]
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.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
nedbacan
Frequent Contributor

What I am trying to understand is how to add the variable MyFolderName in the method to search for the folder stored in the variable and then my next step is find the file imagesnap.jpg.

 

The folder name will be different on every run so the pathname cannot be hardcoded.

 

Sorry, I am just learning.

cancel
Showing results for 
Search instead for 
Did you mean: