Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Perform iteration as per the number of files available in a folder
#1
Hi All,

I am a newbie in QTP. I am trying to automate some part of my test.

Please have a look on the following code.

Code:
Function readTextFromFile(pathToFile) Set fso = createObject("Scripting.FileSystemObject") If fso.FileExists(pathToFile) = True Then Set f = fso.OpenTextFile(pathToFile, 1) readTextFromFile = f.ReadAll f.Close End If End Function text = readTextFromFile("Path of file") Set clipboard = createobject("mercury.clipboard") //Thanks to inborntester clipboard.Clear clipboard.SetText(text) SwfWindow("MyApplication").SwfEditor("xmlTextBox").Type micCtrlDwn + "v" + micCtrlUp

In the above code, am reading a file and writing this to a variable "text".
Then copying this to my application text area and submits.
Similarly i want to read other files from this folder util the last file.
Like this i have five folders. If i select option 1 in my application i have to read files from 1st folder, after that i have to select option 2 in my application and then folder has to changed to 2nd folder. Will i be able to include all these 5 otpions within a program or i have to write 5 different pgm.

Do i have to use vb script or any QTP logic is there to iterate. I have aware of some terminologies like parameterization.

Your time and advices are much appreciated. Thanks in advance all..

If am posting in the wrong thread, kindly pardon.

Regards
Reply
#2
Code:
' assume that folder1, folder2, folder3, folder4, folder5 are the five folders located in the root folder c:\folder ' option1, option2, option3, option4, option5 are the corresponding options for above folders ' replace your root folder rootfolder="c:\Folder" set oFS = CreateObject("Scripting.FileSystemObject") ' replace the below code with your application specific code from you get option selectedoption=inputbox("enter option as option1 or option2 or option3 or option4 or option5") Set folderoption = CreateObject("Scripting.Dictionary") ' replace options and folder name as per your need folderoption.Add "option1", "folder1" folderoption.Add "option2", "folder2" folderoption.Add "option3", "folder3" folderoption.Add "option4", "folder4" folderoption.Add "option5", "folder5" set oFolder = oFS.GetFolder(rootfolder&"\"&folderoption.item(selectedoption)) msgbox(oFolder) Set oFiles = oFolder.Files For each folderIdx In OFiles msgbox(oFolder&"\"&folderIdx.Name) text = readTextFromFile(oFolder&"\"&folderIdx.Name) Set clipboard = createobject("mercury.clipboard") clipboard.Clear clipboard.SetText(text) msgbox(text) SwfWindow("MyApplication").SwfEditor("xmlTextBox").Type micCtrlDwn + "v" + micCtrlUp Next Function readTextFromFile(pathToFile) Set fso = createObject("Scripting.FileSystemObject") If fso.FileExists(pathToFile) = True Then Set f = fso.OpenTextFile(pathToFile, 1) readTextFromFile = f.ReadAll f.Close End If End Function

i attached the folder i used. remove all the msgbox codes, i have used for tracking purpose.
Reply
#3
Hey thanks yaar...i used d above code with some modification...working fine now..Smile

Best Regards
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Object not found during the 2nd iteration of an Action call in a For loop BGunay 0 1,391 04-23-2020, 07:08 PM
Last Post: BGunay
  Executing via create "RES"xx folder? nishitd 0 1,691 03-07-2018, 01:09 AM
Last Post: nishitd
  UFT Tool runs more than one iteration always cthossain 2 4,609 02-12-2017, 01:25 PM
Last Post: cthossain
  code for validation to create a sub folder smiley 0 1,886 10-19-2016, 10:08 PM
Last Post: smiley
  [UFT] Close opened folder robertosalemi 1 3,878 02-10-2016, 07:06 PM
Last Post: robertosalemi

Forum Jump:


Users browsing this thread: 1 Guest(s)