-4

I am running some automation scripts which will save the files downloaded from the server and copy my files from downloads folder to a user specific folder and after saving, the "SAVE" button will turn to color:RED (previously,Blue). Is there a way to test it using selenium +Java.? I currently use WebdriverBackedSelenium for developing my scripts.

   //Current Sample Code Snippet:
     if(selenium.isElementPresent("css=Submit_Button"))
 {
      selenium.click("css=submit_Button");
 }

 //Expected Code Snippet:

 if(selenium.isElementPresent("css=Submit_Button"))
 {
      if( /* something like colorof("css=Submit_Button")=="RED"*/ )
          selenium.click("css=submit_Button");
      else
          System.out.print("\n Already Processed:");
 }
user7470
  • 29
  • 1
  • 2

4 Answers4

0

If you've Java 7, then you could use the Files#copy to directly copy the file from source to target!

If you do not have Java 7, you can take help from Apache Commons which provides the FileUtils#copyFile for file copying!

Rahul
  • 44,383
  • 11
  • 84
  • 103
0

You can try this:

File source = new File("H:\\work-temp\\file");
File desc = new File("H:\\work-temp\\file2");
try {
    FileUtils.copyDirectory(source, desc);
} catch (IOException e) {
    e.printStackTrace();
}
Shreyos Adikari
  • 12,348
  • 19
  • 73
  • 82
0

http://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/IOUtils.html
copy method !

I think you do this thing can use other method 。for ex: python or shell!

iamct
  • 394
  • 5
  • 9
0

I understand the you use selenium? If not, then ignore this answer.

You could maybe alternatively set the browser preferences to the folder you want to have your files in the end anyway. Depending on the browser you automate with selenium you must set the preferences slightly differently. For Firefox you do

FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("browser.download.dir", "c:\\YOUR\\PATH"); 
profile.setPreference("browser.download.folderList", 2); 
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
  "application/pdf,text/csv"); 
WebDriver driver = new FirefoxDriver(profile); 

Or you use something like powder-monkey with selenium to get your downloads...

luksch
  • 11,497
  • 6
  • 38
  • 53