课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Taking screenshots

Taking screenshots

- [Instructor] Selenium WebDriver provides functionality to take screenshots within a browsing context, meaning the window, tab or frame where content is rendered. But before we can use this feature, we must enable WebDriver to create a bidirectional connection between our test script and the browser. This is done when instantiating our driver. So we can add a new option here, which is enableBiDi. Next, we'll set the browsing context to the window that we're on. So we'll say var BrowsingContext = new BrowsingContext and we'll pass in our driver instance and the context we want to set. In our case, let's set the context to the current window and we can do so by saying driver.getWindowsHandle. To capture a screenshot of the entire page, we say browsingContext.captureScreenshot. This returns a base 64 encoded string of the binary image data. So let's store this in a variable. Its type will be string and we can call this fullScreenshot. To view the screenshot as an image, we need to…

内容