java - 如何使用 Selenium Hub、Node 和 Remote Webdriver 捕获图像并将它们附加到 Cucumber Reports (Jenkins)?
问题描述
目前我正在使用 Ubuntu 实例在云中触发我的自动化测试。
Ubuntu 实例有一个 Jenkins 实例正在运行,还有 Selenium Hub 和 Node。似乎截图图像没有保存在 ubuntu 系统上的 builds\3\cucumber-html-reports\embeddings 中,但是在 Windows 系统上这个问题不存在。
我目前添加了以下逻辑来捕获图像并将其附加到 Jenkins Cucumber 报告中,但是目前图像没有附加到报告中:
@After
public void after(Scenario scenario) {
if (scenario.isFailed()) {
try {
WebDriver augmentedDriver = new Augmenter().augment(getDriver());
byte[] s = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.BYTES);
scenario.embed(s, "image/png");
解决方案
我没有直接回答 ubuntu 问题。但是,尝试将捕获图像的路径作为 html 链接添加到您的黄瓜报告中。
@After
public void after(Scenario scenario){
if (scenario.isFailed()) {
try {
WebDriver augmentedDriver = new Augmenter().augment(getDriver());
File path = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(path,new File(localRepoPath));
String html = "<html><body><a href=\">" + localRepoPath + "\"> screenshot </a></body></html>";
scenario.embed(html.getBytes(), "text/html");
}catch(Exception e){
// Do Something
}
}
}
推荐阅读
- unreal-engine4 - 虚幻引擎编译系统如何工作?
- react-native - FlatList TouchableOpacity 项目看起来被按下
- stored-procedures - 在 UDF 或存储过程中使用参数返回表
- css - CSS Grid - 跨列和行?
- visual-studio-code - Visual Studio Code Live Share 扩展错误
- python - 为什么 numpy.asarray() 不适用于大量数组?
- c# - WCF - GetCallbackChannel 可靠吗?
- node.js - 使用 NodeJS 在 MongoDB 上存储用户点击信息
- json - TypeScript:在 JSON 中查找某些键的值
- html-table - 赛普拉斯,读出表格的所有元素,但只有一个精确值-标签