Created
February 20, 2012 14:03
-
-
Save froop/1869370 to your computer and use it in GitHub Desktop.
[Java][WebDriver] ファイルダウンロードテスト例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.firefox.FirefoxProfile; | |
import org.apache.commons.io.FileUtils; | |
public class FileDownloadTest { | |
private static WebDriver driver; | |
private static final String DOWNLOAD_DIR = "C:\\work\\download"; | |
private static final String COMPARE_DIR = "C:\\work\\compare"; | |
@BeforeClass | |
public static void setUpBeforeClass() throws Exception { | |
FirefoxProfile prop = new FirefoxProfile(); | |
prop.setPreference("browser.download.folderList", 2); | |
prop.setPreference("browser.download.useDownloadDir", true); | |
prop.setPreference("browser.download.dir", DOWNLOAD_DIR); | |
prop.setPreference("browser.helperApps.neverAsk.saveToDisk", | |
"application/octet-stream"); | |
driver = new FirefoxDriver(prop); | |
} | |
@AfterClass | |
public static void tearDownAfterClass() throws Exception { | |
driver.quit(); | |
} | |
@Test | |
public void testFileDownload() throws Exception { | |
final String fileName = "example.zip"; | |
File expected = new File(COMPARE_DIR + "/" + fileName); | |
File actual = new File(DOWNLOAD_DIR + "/" + fileName); | |
actual.delete(); | |
driver.get("http://example.com/1/download"); | |
assertTrue("exists", actual.exists()); | |
assertTrue("content", FileUtils.contentEquals(expected, actual)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment