1

I am using Robot Framework with Python and Selenium. I need to verify that files have the correct format: specifically that they are image files (e.g.: .jpg, .jpeg, etc).

How do I use validations or assertions to verify that the files contain one of a list of allowed suffixes? This is not as simple as verifying that the files contain a single suffix - I have to check that the file is one of the allowed types.

2
def checkFileExtension():
 for file in os.listdir("/imagesDirectory"):
   if file.endswith(".gif",".jpg"):
      continue
   else 
     return false
 return true

assert(checkFileExtension() == true)

The syntax may be a little off but you get the idea. The function checks the entire directory. If any file/files are not gif/jpg then it returns false. Depending on your goal you may need to modify.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.