我收到 UI : Exception in clickNewPurchase(): [Ljava.lang.StackTraceElement;@52e6b75 异常。
但问题是它能够导航下一页。您可以在下面找到代码。如何避免出现此异常?如何确定出现此问题的具体位置以及导致此问题的原因?有什么帮助吗?
private void clickNewPurchase() throws Throwable {
try {
List<WebElement> listOfbuttons = createElements(newPurchase);
for (WebElement element : listOfbuttons) {
String value = element.getAttribute("value");
if (value.equals("New Purchase") || value.equals("RePurchase")) {
JavascriptExecutor executor = (JavascriptExecutor)driver.get();
executor.executeScript("arguments[0].click();", element);
baseClass.logInfo("Clicked on New Purchase / RePurchase button on Start a Purchase page");
waitforVisibilityOfElement(currentPage);
break;
}else if (value.equals("Retrieve")) {
masterData.get().put("IncompletePurchase", "True");
JavascriptExecutor executor = (JavascriptExecutor)driver.get();
executor.executeScript("arguments[0].click();", element);
baseClass.logInfo("Clicked on Retrieve button on Start a Purchase page");
waitforVisibilityOfElement(currentPage);
break;
}
}
} catch (Exception e) {
softAssertFail("Exception in clickNewQuote(): " + Arrays.toString(e.getStackTrace()), ValidationType.UI);
e.printStackTrace();
}
}
java.lang.AssertionError: The following asserts failed:
<br> <b>>></b> UI : Exception in clickNewPurchase(): [Ljava.lang.StackTraceElement;@3bea26bc
at org.testng.asserts.SoftAssert.assertAll(SoftAssert.java:43)
at tests.P2Test.p2Test(P2Test.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
P2测试线167
try {
if (sam.getSoftAssert() != null)
sam.getSoftAssert().assertAll();
} catch (Exception e) {
Assert.fail("Problem in Soft assert: " + e.getCause());
}
你问了几个问题-
softAssertFail
不抛出异常)Arrays.toString(e.getStackTrace())
- 我想不出任何这样做的好理由 - 意图是什么这背后?我认为,如果您退后一步并且不处理异常(即删除
try..catch
),然后从那里开始处理,您可能会更好地了解正在发生的情况。