Ask a Question

Updating string in XML File with current time+10 minutes

testcmpleteuser
Occasional Contributor

Updating string in XML File with current time+10 minutes

I have a scenario in my testing where I have to open a XML file in notepad , update the latest time + 10 minutes and save it. I am running into errors here for reading the file. I know the updating string part works as I already tested that in a separate sub (). Issue is how to get to the part of readiing the opened file and save the changes.

 

sub OpenFile
strFileName = "C:\mytestfile.xml"
Set oShell = CreateObject("WScript.Shell")

oShell.Run "notepad " & strFileName

While Not strFileName.IsEndOfFile()
s =  strFileName.ReadLine()
str = "cronExpression"" value=""0 18 28"
if instr(s,str)<>0 then

Set re = New RegExp
re.Pattern = "[0-9][0-9] [0-9][0-9]"
re.global = true
mh=hour(now)
mm = minute(now)+15
if mm>59 then
mh = mh+1
mm = 10
end if
a = cstr(mh)+" "+cstr(mm)
str = re.Replace(str, cstr(a) )
Log.Message( str)
else
log.Message xxx
end if
WEnd

end sub

 

Thanks

2 REPLIES 2
dmiscannon
Frequent Contributor

I tried your code and got an "Object Required" error.

 

The below code may help. I copied it from the IsEndOfFile Method page of TestComplete Help.

 

Sub ReadTextFromFile
  Dim sPath
  sPath = "D:\Files\MyFile.txt"

  ' Opens the specified file for reading
  Set myFile = aqFile.OpenTextFile(sPath, aqFile.faRead, aqFile.ctUnicode) ' I think this line will help you. Notepad will not display, but the file will open in the background.
  Log.Message("File by lines:")

  ' Reads text lines from the file and posts them to the test log
  While Not myFile.IsEndOfFile()
    s = myFile.ReadLine()
    Log.Message(s)
  WEnd

  ' Closes the file
  Call myFile.Close()
End Sub

testcmpleteuser
Occasional Contributor

hi dmiscannon:

 

The file that I need to update is XML file and not .txt and hence I have to refer oShell.Run "notepad "  & strFileName. But XML files I think dont support this - While Not strFileName.IsEndOfFile() - it being for .txt files. One being ascii and other binary.

 

Thanks

cancel
Showing results for 
Search instead for 
Did you mean: