packagecom.brower.demo;importorg.openqa.selenium.By;org.openqa.selenium.WebDriver;org.openqa.selenium.chrome.ChromeDriver;org.testng.annotations.AfterClass;org.testng.annotations.BeforeClass;org.testng.annotations.Test;import java.awt.*;java.awt.datatransfer.StringSelection;java.awt.event.KeyEvent;java.io.IOException;/***@authorrongrong*/
classTestUploadByRobot {
WebDriver driver;
@BeforeClassbeforeClass() {
System.setProperty("webdriver.chrome.driver","driver/chromedriver.exe");
driver= ChromeDriver();
}
@Testvoid testUploadByRobot() throwsAWTException {
driver.get("file:///C:/Users/Administrator/Desktop/upload.html");
driver.manage().window().maximize();//选择文件
driver.findElement(By.id("upload")).click();
setClipboardData("F:\\robotium-solo-5.6.1.jar");
Robot robot= Robot();
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_ENTER);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(100);
robot.keyRelease(KeyEvent.VK_ENTER);
});
}
@AfterClassafterClass() {driver.quit();
}
}