如何使用 Krypton 使用 Selenium 捕获屏幕截图 Java
How to capture a screenshot using Krypton using Selenium Java
在使用JAVAselenium的氪星平台下,有没有可能的截图方法/代码求助。我在标准化方面遇到了麻烦。谢谢!
var driver = new ChromeDriver()
driver.get("https://login.bws.birst.com/login.html/")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("c:\tmp\screenshot.png"))
根据屏幕截图,似乎与 imports/Classes 存在一些差异。进一步为了让事情更简单,在 Project Scope 中创建目标文件夹,例如下面的 Screenshots 目录:
要使用 Java 捕获屏幕截图,您可以使用以下解决方案:
代码块:
package screenShot;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class takesScreenshot {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("disable-infobars");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://login.bws.birst.com/login.html/");
new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Birst"));
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(".\Screenshots\Mads_Cruz_screenshot.png"));
}
}
捕获的图像:
var driver = new ChromeDriver()
driver.get("https://login.bws.birst.com/login.html/")
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File("c:\tmp\screenshot.png"))
根据屏幕截图,似乎与 imports/Classes 存在一些差异。进一步为了让事情更简单,在 Project Scope 中创建目标文件夹,例如下面的 Screenshots 目录:
要使用 Java 捕获屏幕截图,您可以使用以下解决方案:
代码块:
package screenShot; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class takesScreenshot { public static void main(String[] args) throws IOException { System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.addArguments("disable-infobars"); options.addArguments("--disable-extensions"); WebDriver driver = new ChromeDriver(options); driver.get("https://login.bws.birst.com/login.html/"); new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("Birst")); File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(".\Screenshots\Mads_Cruz_screenshot.png")); } }
捕获的图像: