如果代码在服务器上执行,截图速度非常快localhost
,不到一秒(大约 400-500 毫秒):
private RemoteWebDriver driver;
private DesiredCapabilities dc = new DesiredCapabilities();
@Before
public void setUp() throws MalformedURLException {
....
....
dc.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
}
@Test
public void test() throws InterruptedException, IOException {
driver.get("https://google.com");
driver.findElement(By.name("q")).sendKeys("automation test");
long before = System.currentTimeMillis();
//here is the problem
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
long after = System.currentTimeMillis();
System.out.println(after-before);
FileUtils.copyFile(srcFile, new File("/Users/name/localpath/test.png"));
}
但是如果将目标服务器更改为public ip
安装了 Selenium 服务器的服务器,则截屏会更慢(大约 5 秒)。也许这可能是由于客户端和服务器之间的距离,所以一定有区别。
是否可以减少截屏时间?我正在考虑降低图像分辨率,但如何调整呢?