document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package experiment;
  2.  
  3. import java.io.IOException;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebDriver;
  8. import org.openqa.selenium.firefox.FirefoxDriver;
  9. import org.openqa.selenium.firefox.FirefoxProfile;
  10. import org.testng.annotations.AfterClass;
  11. import org.testng.annotations.BeforeClass;
  12. import org.testng.annotations.Test;
  13.  
  14. public class Download {
  15.  
  16.     public WebDriver driver;
  17.     @Test
  18.     public void testBing() throws Exception {
  19.  
  20.         driver.get("http://the-internet.herokuapp.com/");
  21.         driver.findElement(By.linkText("File Download")).click();
  22.         driver.findElement(By.linkText("avatar.jpg")).click();
  23.         Thread.sleep(5000);
  24.  
  25.     }
  26.  
  27.  
  28.     @BeforeClass
  29.     public void beforeClass() throws IOException {
  30.         //Create object of FirefoxProfile in built class to access Its properties.
  31.         FirefoxProfile fprofile = new FirefoxProfile();
  32.         //Set Location to store files after downloading.
  33.         fprofile.setPreference("browser.download.dir", "C:\\\\Naga\\\\Flex");
  34.         // 2 tells it to use a custom download path whereas a 1 is the browser\'s default path and a 0 is the Desktop
  35.         fprofile.setPreference("browser.download.folderList", 2);
  36.         //Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
  37.         //Full lsit of MIME types "http://www.webmaster-toolkit.com/mime-types.shtml"
  38.         fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/jpeg");
  39.         //fprofile.setPreference( "browser.download.manager.showWhenStarting", false );
  40.         //if usign PDFs then use it
  41.         //fprofile.setPreference( "pdfjs.disabled", true );
  42.         //Pass firefox profile parameter In webdriver to use preferences to download file.
  43.         driver = new FirefoxDriver(fprofile);  
  44.         //maximize browser
  45.         driver.manage().window().maximize();
  46.         //global declaration of wait
  47.         driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  48.  
  49.     }
  50.  
  51.     @AfterClass
  52.     public void afterClass() {
  53.         driver.quit();
  54.     }
  55.  
  56. }
');