cancel
Showing results for 
Search instead for 
Did you mean: 

aqFile.Exists() path containing a space

SOLVED
Highlighted
Occasional Contributor

aqFile.Exists() path containing a space

Hello!

 

I am tring to use the aqFile functions to test for the exsistance of a file... When I send a file that contains a path with an embedded space, the return value is always FALSE.

 

Python : 

 

file_path_name = "C:\Path has Space\Reports\Report.pdf"

 

file_status = aqFile.Exists(file_path_name)  # check to see if file exists
file_status = aqFileSystem.Exists(file_path_name)

 

BOTH the above return FALSE

 

I have tried to put quotes around the "Path has Space" part without any luck...

 

Any suggestions would be greatly appreciated!!

 

Steve

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: aqFile.Exists() path containing a space


@K_Sathish_Kumar wrote:

Can you please share the text which is retrieved from the hi object please

 

Regards,

Sathish


Yeah, at his point, if hardcoding the string is working just fine, then the problem must be in what you're getting from the AUT.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

8 REPLIES 8
Highlighted
Community Hero

Re: aqFile.Exists() path containing a space

I don't know if Python is the same as JavaScript... but backslashes may need to be doubled up.

 

file_path_name = "C:\\Path has Space\\Reports\\Report.pdf"

 

file_status = aqFile.Exists(file_path_name)  # check to see if file exists
file_status = aqFileSystem.Exists(file_path_name)


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
Occasional Contributor

Re: aqFile.Exists() path containing a space

Thanks for your reply!

 

I have tried performing a search & replace on the path backslashes and that still is returning a False value.  If I hard code a string and try the aqFile.exists() on it - it works... 😞       (see examples below)

 

The problem arises when getting the path & filename from my info dialog.  Here is what is in the error log:

 

Check_File_Status :: File Status NOT Correct : |C:\Users\username\Documents\Compass for SW\Jess-js3003_2019-09-27_11-07.pdf| : False : should be True

 

Here is my function : 

 

def Check_File_Exists(file_path_name, expected_status=True):
# params : file_path_name : string = the file|path|drive to check
# expected_status : boolean = the status the file should be

file_status = aqFile.Exists(file_path_name) # check to see if file exists
# file_status = aqFileSystem.Exists(file_path_name)

retVal = file_status == expected_status # return the comparison status

if not retVal:
Log.Warning("Check_File_Status :: File Status NOT Correct : |%s| : %s : should be %s" % (file_path_name, file_status, expected_status))

return retVal

 

Running the hard-coded value works : 

 

def Test1():
the_file = 'C:\\Users\\username\\Documents\\Compass for SW\\Instrument_Reports\\Jess-js3003_2019-09-27_11-07.pdf'
status = CommonUnit.Check_File_Exists(the_file, True)
Log.Message("file status = %s" % status)

 

Anything else you can suggest??

 

Steve

Highlighted
Community Hero

Re: aqFile.Exists() path containing a space

Highlighted
Contributor

Re: aqFile.Exists() path containing a space

Hi @stevereissps ,

 

just make use of raw-string to over come for your problem.

please find the below code snippet for your refernece and

please let me know if that solved your problem or not.

def testFileinFolder():
  file_path_name = r'C:\Users\sathishkumark\Desktop\Folder with space\report.pdf'
  file_status = aqFile.Exists(file_path_name)
  if file_status is True:
    Log.Checkpoint('File is present usder the path specified')
  else:
    Log.Error('File is Not present usder the path specified')

Kind Regards,

Sathish Kumar K

Regards,
Sathish Kumar K
Highlighted
Occasional Contributor

Re: aqFile.Exists() path containing a space

Thank you for your suggestions... I have tried a number of things to get this to work.

 

If the file path is hard coded, it appears to work correctly.  If my script grabs the text from onscreen elements and puts them together (path + filename), it fails.  

 

Here are the test cases that I have using : 

 

Path text from on screen text elements (from JAVA GUI App) - Fails.  Using Python Raw string. : 

 

1) Check_File_Status :: File Status NOT Correct : |C:\\Users\\steven.reiss\\Documents\\"Compass for SW"\\Instrument_Reports\\Jess-js3019_2019-10-01_13-10.pdf| : False : should be True

 

2) Check_File_Status :: File Status NOT Correct : |C:\Users\steven.reiss\Documents\Compass for SW\Instrument_Reports\Jess-js3019_2019-10-01_13-11.pdf| : False : should be True

 

 

Hard-Coded path - Works correctly

 

1) 

 

def Test1():
the_file = 'C:\\Users\\steven.reiss\\Documents\\Compass for SW\\Instrument_Reports\\Jess-js3003_2019-10-01_11-24.pdf'
val = aqObject.GetVarType(the_file)

status = CommonUnit.Check_File_Exists(the_file, True)
Log.Message("file status = %s %s" % (status, val))


Result : file status = True    8  (varOleStr)

 

2) 


def testFileinFolder():
# file_path_name = r'C:\Users\sathishkumark\Desktop\Folder with space\report.pdf'
file_path_name = r'C:\Users\steven.reiss\Documents\Compass for SW\Instrument_Reports\Jess-js3003_2019-10-01_11-24.pdf'
file_status = aqFile.Exists(file_path_name)
Log.Message(aqObject.GetVarType(file_path_name))

if file_status is True:
Log.Checkpoint('File is present under the path specified')
else:
Log.Error('File is Not present under the path specified')

status = CommonUnit.Check_File_Exists(file_path_name, True)
Log.Message("Status = %s" % status)


Result : Status = True

 

Are there any other things you can suggest??

Highlighted
Contributor

Re: aqFile.Exists() path containing a space

Can you please share the text which is retrieved from the hi object please

 

Regards,

Sathish

Regards,
Sathish Kumar K
Highlighted
Community Hero

Re: aqFile.Exists() path containing a space


@K_Sathish_Kumar wrote:

Can you please share the text which is retrieved from the hi object please

 

Regards,

Sathish


Yeah, at his point, if hardcoding the string is working just fine, then the problem must be in what you're getting from the AUT.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Highlighted
Occasional Contributor

Re: aqFile.Exists() path containing a space

All,

 

Looking A LOT closer at that the entire report process generation, I found a weird timing issue that was the cause of the report .pdf file not being written until a certain condition in the application...

 

Thanks for all of your suggestions and assistance!

 

Steve

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!

Retrieve Data from a Web Page

Participate!