java.lang.AssertionError 在org.junit.Assert.fail(Assert.java:86) at org.junit.Assert.assertTrue(Assert.java:41) at org.junit.Assert.assertTrue(Assert.java:52) 在com.bt.panorama.ip.widgets.trading.OrderStatus.verifyOrdersRange(OrderStatus.java:64) 在com.bt.panorama.ip.widgets.trading.OrderStatus.searchByDateRange(OrderStatus.java:49)
> org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//div[@class='mvc-orderstatuses']//tr[@class='no-results-row']"}
命令持续时间或超时:10.11秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'2.45.0',修订版:'5017cb8e7ca8e37638dc3091b2440b90a1d8686f',时间:'2015-02-27 09:10:26' 系统信息:主机:'WV001768',ip:'10 .13.12.184',os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.7.0_09 “ ***元素信息:{Using = xpath,value =。// div [@ class ='mvc-orderstatuses'] // tr [@ class ='no-results-row']} 会议ID:e3ea478d-1150-44c9-81aa-ce73573ed864 驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver
在调试时,我能够看到发生了异常,并且错误收集器捕获了它。 因此,错误收集器应该在junit选项卡中打印它,因为printStackTrace()函数正在控制台选项卡中打印。
try
{
errList.add(error);
File scrFile = ((TakesScreenshot)InstantiateDriver.getDriver()).getScreenshotAs(OutputType.FILE);
String folder = System.getProperty("browserType");
if (folder == null)
{
folder = "firefox";
}
String dt = new SimpleDateFormat("yyyy-MMM-dd").format(new Date()).trim();
String envpath = System.getProperty("envpath");
String imageFileDir;
if (null == envpath)
{
imageFileDir = ".\\HTMLreport\\" + dt + "\\" + "html\\screenshots\\" + folder; // System.getProperty("selenium.screenshot.dir");
}
else
{
imageFileDir = ".\\HTMLreport\\" + dt + "\\" + envpath + "\\" + "html\\screenshots\\" + folder;
}
File fle = new File(imageFileDir);
if (!fle.exists())
{
fle.mkdirs();
}
if (imageFileDir == null)
imageFileDir = System.getProperty("java.io.tmpdir");
try
{
String str = "";
if (error.getMessage() != null)
if (error.getMessage().length() > 10)
str = error.getMessage().substring(0, 10);
else
str = error.getMessage().substring(0, error.getMessage().length() - 1);
String methodname = error.getStackTrace()[0].getMethodName();
String className = error.getStackTrace()[0].getClassName();
StackTraceElement[] el = error.getStackTrace();
for (int i = 0; i < el.length; i++)
{
if (el[i].getMethodName().startsWith("test"))
{
methodname = el[i].getMethodName();
className = el[i].getClassName();
break;
}
}
str = methodname + "_" + str;
//eleminate '/' and spaces in the file name
str = str.trim().replace("/", "-").replace(" ", "_").replace("'", "_").replace(":", "_");
String fileName = str + "_" + (count++) + ".png";
File file = new File(imageFileDir, fileName);
FileUtils.copyFile(scrFile, file);
String scRelativePath = "screenshots\\\\" + folder + "\\\\" + fileName;
String errorString = error.getMessage();
if (null != getExecMethod())
{
errorString = getExecMethod() + " : " + errorString;
}
String linkScreenShot = " - " + className + " # "
+ "<a escape=\"true\" href=\"javascript:displayScreenshotLink(\'" + scRelativePath
+ "\');\">Click here for screenshot</a>";
errorString = errorString + " " + linkScreenShot;
if (error instanceof AssertionError)
error = new AssertionError(errorString, error);
else
error = new Throwable(errorString, error);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
super.addError(error);
显示java.lang.NullPointerException at helpers.ErrorCollectorImpl.addError(ErrorCollectorImpl.java:85) 在com.bt.panorama.ip.tests.Trading.BusinessScenarios.ValidateOrder.testDuplicateOrderErrorMessage(ValidateOrder.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
这是关于ErrorCollector的异常,它给出了错误,我传递了error.getMessage()的子字符串.substring(0,10)
答案 0 :(得分:0)
嘿,我刚才发现我必须在@Rule注释下使用我自己现有的ErrorCollector类,而我所做的是我在类的顶部创建了另一个java Errorcollector类的对象,它正在被覆盖。