- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将失败的 methodName 添加到使用 java 运行 selenium 时发生故障时拍摄的屏幕截图中。我在网上尝试了多种解决方案,但它们最终都返回规则类的方法名称或方法名称。我不知道如何制作它,以便屏幕截图文件名返回“shouldFail_date.png”。
package test;
import org.apache.commons.io.FileUtils;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ScreenShotRule extends TestWatcher {
private WebDriver browser;
public ScreenShotRule(WebDriver browser) {
this.browser = browser;
}
@Override
protected void failed(Throwable e, Description description) {
TakesScreenshot takesScreenshot = (TakesScreenshot) browser;
File scrFile = takesScreenshot.getScreenshotAs(OutputType.FILE);
File destFile = getDestinationFile();
try {
FileUtils.copyFile(scrFile, destFile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
@Override
protected void finished(Description description) {
browser.close();
}
private File getDestinationFile() {
Throwable t = new Throwable();
String callerMethodName = t.getStackTrace()[1].getMethodName();
DateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy");
String userDirectory = "screenshots/" + dateFormat.format(new Date()) + "/";
new File(userDirectory).mkdirs();
String absoluteFileName = userDirectory callerMethodName + dateFormat.format(new Date()) + ".png";
return new File(absoluteFileName);
}
}
package test;
import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ScreenShotTest {
private WebDriver browser = new FirefoxDriver();
@Rule
public ScreenShotRule screenShootRule = new ScreenShotRule(browser);
@Test
public void shouldFail() {
browser.get("http://www.google.com");
By link = By.partialLinkText("I do not expect to find a link with this text");
browser.findElement(link);
}
}
最佳答案
您可以使用高效的 selenium testing-frameworks 之一-ISFW它基于 testng,并根据您的需要提供描述性报告。这是一些快照 Overview Detail Report
关于java - 使用Java将methodName添加到selenium失败的屏幕截图名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18841145/
大多数 ruby 开发人员都知道如何通过执行以下操作来节省几次击键: array.map(&:methodname) 而不是 array.map {|x| x.methodname } 有什么方法
这个问题在这里已经有了答案: Difference between this and base (9 个回答) 关闭 9 年前。 如果您正在从基类继承的类中编写代码,并且您想要在该基类上调用 pro
我想知道这两者之间的区别(对不起,我不知道这个主题的名称)。 我来自 C#,在那里我习惯于编写 System.data 以及 classA.MethodA。我已经发现在 Cpp 中,我需要使用::和类
我在 Blazor 中有一个组件,它接受方法作为参数。 @code { async Task> LoadS() => (await ModelServiceS.GetAllAsync()).
当做 tab 时,那个让我感到惊讶。对于断点的自动完成,它出现了相同方法的两个选项。 test::TestFoo::SendFoo(short) test::TestFoo::SendFoo(shor
我见过很多实现,其中一个类 (C1) 和这个类中的一个私有(private)方法 (M1)。我已经看到使用 this.M1 或从此类的其他方法中简单地使用 M1 来使用此方法 M1。 public c
我是Java的新手。 我在此行收到错误ABC.methodname();作为 token “方法名称”的语法错误,此 token 后应有标识符。 你们能告诉我如何解决它。 在下面提供了我的整个代码。
当我创建节点时,我试图在报告中记录我调用的方法名称。 我在ITestresult中使用getname()、Method.GetMethodName进行了尝试,但没有找到正确的方法来找出答案。 publ
因此,我正在通过为我的 native C++ 代码使用包装器类来实现一些 C++/cli 和 C# 互操作。 我似乎无法解决错误 'GetSharedData' 不受语言支持。我在网上搜索了解决方案并
在此question有一行, findViewById(R.id.go_to_play_store).setOnClickListener(this::goToPlayStore); 这一行是如何处理
我无法理解此编译器错误消息的要点“无法使用类型为‘(value: T)’的参数列表调用‘getValueType’对于行“if (CMFStream.getValueType(value: test)
我在看有关image_picker和video_player库的this文章,并且看到了下面的代码: _videoPlayerController = VideoPlayerController.fi
我看到了以下代码: mActionMode = OverviewActivity.this .startActionMode(mActionModeCallback); 我在这里看到
从 javascript 调用 WebService/C# 时出现奇怪的错误。 服务器方法“GetGoogleToken”失败。没有细节,没有堆栈跟踪。在服务器上,我设置了断点 - 一切顺利,我正在返
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visi
我正在尝试扩展 js 应用程序中的 Object 类。 方法如下: Object.prototype.safeGet = function(props, defaultValue) { conso
在研究这个问题时,大多数 SO 问题都是关于作为修复的 static 方法。 因为它不能与真正的(并且有点复杂)WebMethod 一起工作,我只是创建了一个简单的 WebMethod 来检查是否可以
我收到这个错误 Controller “classname”没有事件槽“methodname” 如果我在 fx:controller="application.MainController"> 中的应
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Advantages of using prototype, vs defining methods str
在 loadComplete 方法的以下代码中,它给了我这个错误: this.getColumnIndexByName is not a function dataGrid.prototype = {
我是一名优秀的程序员,十分优秀!