如何从 RemoteWebDriver 服务器而不是本地 FirefoxDriver 获取屏幕截图?

2022-01-16 00:00:00 selenium webdriver java

我正在使用 RemoteWebDriver 从我的笔记本电脑(java 客户端)在远程 PC 上运行 Selenium WebDriver 测试.但是 RemoteWebDriver 没有提供截图 API 来直接获取远程 PC 的截图.谷歌搜索了很多,但发现似乎需要使用 Json API 直接从 remoteWebDriver 服务器获取它.任何人都可以给我一些关于如何做到这一点的指导吗?谢谢.

I am running Selenium WebDriver test on a remote PC from my laptop(java client), by using RemoteWebDriver. But RemoteWebDriver haven't provided screenshot API to directly get a screenshot of remote PC. Googled a lot but found seems need use to Json API to get it from remoteWebDriver server directly. Anyone can give me some instruction about how to do that? Thanks.

推荐答案

必须先扩充 RemoteWebDriver,然后才能使用屏幕截图功能.毫无疑问,您已经发现,尝试在不增加的情况下进行投射会导致异常.

The RemoteWebDriver must be augmented before you can use the screenshot capability. As you have no doubt already found, attempting to cast without augmenting results in an exception.

WebDriver driver = new RemoteWebDriver( ... );
driver           = new Augmenter().augment( driver );
( (TakesScreenshot)driver ).getScreenshotAs( ... );

相关文章