aqFile.Exists() path containing a space
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See if any of this helps:
https://stackoverflow.com/questions/14852140/whitespaces-in-the-path-of-windows-filepath
Marsha_R
[Community Hero]
____
[Community Heroes] 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 Heroes]
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 Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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??
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please share the text which is retrieved from the hi object please
Regards,
Sathish
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Mr_Bro 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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
