1

Our test-app runs on multiple Virtual Machines through Selenium Remote Control. The App sits on a test controller Server.

The test-app is used to test a third party online application.

How can I test to see if on certain VM Selenium-RC has read access to a file or folder.

Is there anything like file.canRead(filepath) kind of thing for selenium too?

Before you respond: File's canRead(filepath) will only test if the file is readable from a test controller server, not able to say anything if it is readable on VM where actual browsers are opening(testing) third-party-online-application.

Basically, I want to upload some file to the third-party-online-application through selenium.

Before doing an upload, I want to make sure that the file is available for upload (on VMs).

Watt
  • 3,118
  • 14
  • 54
  • 85

3 Answers3

1

A solution would be to create a download link in the application and then attempt to download the file via Selenium. That way, you get a user-representative experience.

If you want to be really fancy, have the Application create a file with the current date and then let the test download the file (simple text file) and check if the file contains the date. Then you test application writing a file and user reading the file, which covers access rights as well.

Ewald
  • 5,691
  • 2
  • 27
  • 31
1

Which scripting language you are using? If assuming that your file to upload resides under "./data" directory then in java you can check with following steps

File file = new File("./data/myfile.ext");
boolean canUpload = file.exists() && file.canRead();

String fileToUpload = file.getCanonicalPath(); //file name with full path
user861594
  • 5,733
  • 3
  • 29
  • 45
  • The browser are controllered by a selenium-java app (running on a server box). The browsers are running on some VMs. Browsers need to upload the file. So, browsers at partiular VM should have access to the file. I don't need to check access of the file by selenium-java app. Your code will check access of file by selenium-java application, not by selenium controller browsers on each VM. – Watt Oct 20 '11 at 18:06
0
File file = new File("Folder_Location"); // Folder path if file name not known

boolean canUpload = file.listFiles()[index].canRead(); 

Note : For latest downloaded file use

int size=file.listFiles().length-1;

boolean canUpload = file.listFiles()[size].canRead();
Dmitriy
  • 5,525
  • 12
  • 25
  • 38