Skip to content

Instantly share code, notes, and snippets.

@froop
Created February 1, 2012 13:00
Show Gist options
  • Save froop/1716888 to your computer and use it in GitHub Desktop.
Save froop/1716888 to your computer and use it in GitHub Desktop.
[Java][WebDriver] ファイルアップロードテスト例
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FileUploadTest {
private static WebDriver driver;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
driver = new FirefoxDriver();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
// driver.quit();
}
@Test
public void testGoogleImageSearch() throws Exception {
driver.get("http://www.google.co.jp/imghp");
driver.findElement(By.id("qbi")).click();
driver.findElement(By.id("qbug")).findElement(By.tagName("a")).click();
driver.findElement(By.id("qbfile")).sendKeys("C:\\work\\test.png");
assertEquals("一致した画像を含むページ",
driver.findElement(By.xpath("//ol[@id='rso']/li/h3")).getText());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment