我在Eclipse中使用Selenium Web Driver和JUnit。我需要創建簡單的檢查,如果頁面上存在一些文本 - 如果是,比我需要生成錯誤。我想要在JUnit失敗追蹤中顯示此錯誤。這是我的代碼:JUnit故障跟蹤中的顯示錯誤
public class Check {
@Rule
public ErrorCollector errCollector = new ErrorCollector();
@FindBy(tagName="body")
@CacheLookup
private WebElement titl;
@FindBy(partialLinkText="Exception")
@CacheLookup
private WebElement excep;
public void check_false(String t, String r) {
try {
String bodyText = titl.getText();
Assert.assertFalse("Exception found", bodyText.contains(t)); }
catch (AssertionError e) {
System.err.println(r + ": " + e.getMessage());
System.out.println(excep.getText());
errCollector.addError(e);
}
}
如果我得到的錯誤,它會顯示在Eclipse康壽,但如果測試JUnit中顯示爲無錯,並且不顯示異常消息。我如何正確檢查?
我在此視頻培訓中發現了這種方式 - http://www.youtube.com/watch?v=KAmII54wpAY&feature=player_embedded。 – khris 2012-07-23 09:35:15