fix:通用组件库

1.删除部分finally中将驱动的隐式等待去掉。
master
李杰应 2024-09-25 20:17:22 +08:00
parent a825aea600
commit fe61540e84
2 changed files with 18 additions and 65 deletions

View File

@ -70,8 +70,8 @@ public class IfTextThread implements Callable<Boolean> {
elements = ElementUtil.findElementsByText(context, driver, existValue);
} catch (EnvironmentException | ParamMistakeException | NoSuchSessionException e) {
throw e;
}catch (Exception e) {
logger.error("判断文本是否存在出错,文本内容:{}", text,e);
} catch (Exception e) {
logger.error("判断文本是否存在出错,文本内容:{}", text, e);
}
if (!CollectionUtils.isEmpty(elements)) {
logger.info("找到元素{}个", elements.size());
@ -85,12 +85,8 @@ public class IfTextThread implements Callable<Boolean> {
}
swipeNum--;
}
} finally {
try {
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("driver error!");
}
} catch (Exception e) {
logger.error("判断文本是否存在出错", e);
}
CommonUtils.handleSufExecuteWait(sufExecuteWait);
return b;

View File

@ -1395,54 +1395,23 @@ public class ElementUtil {
throw e;
}
WebElement webElement = null;
try {
while (swipeNum >= 0) {
List<WebElement> elements = null;
try {
elements = driver.findElements(By.xpath(xpath));
} catch (NoSuchSessionException e) {
throw e;
}
logger.info("找到元素{}个", elements.size());
if (!CollectionUtils.isEmpty(elements)) { //xpath找到了
webElement = elements.get(0);
} else { //xpath没找到
if (swipeNum > 0) {
ScreenUtil.standardSwipe(swipe, 2000, driver);
}
}
swipeNum--;
}
} finally {
while (swipeNum >= 0) {
List<WebElement> elements = null;
try {
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("driver error");
elements = driver.findElements(By.xpath(xpath));
} catch (NoSuchSessionException e) {
throw e;
}
logger.info("找到元素{}个", elements.size());
if (!CollectionUtils.isEmpty(elements)) { //xpath找到了
webElement = elements.get(0);
} else { //xpath没找到
if (swipeNum > 0) {
ScreenUtil.standardSwipe(swipe, 2000, driver);
}
}
swipeNum--;
}
/* SessionId sessionId = driver.getSessionId();
logger.debug("当前driver的sessionId为{}", sessionId);
try {
webElement = submit.get(waitTimeout, TimeUnit.SECONDS);
logger.info("拿到元素:{}", webElement);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoSuchSessionException) {
logger.error("driver失效了。。。。");
NoSuchSessionException nsse = (NoSuchSessionException) cause;
throw nsse;
}
} catch (Exception e) {
logger.error("xpath找元素出错", e);
xpathThread.kill();
} finally {
try {
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("driver error");
}
}*/
return webElement;
}
@ -1643,12 +1612,6 @@ public class ElementUtil {
throw e;
} catch (Exception e) {
logger.error("查找控件异常", e);
} finally {
try {
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("driver error");
}
}
return point;
}
@ -1661,12 +1624,6 @@ public class ElementUtil {
throw e;
} catch (Exception e) {
logger.error("查找控件异常", e);
} finally {
try {
driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
} catch (Exception e) {
logger.error("driver error");
}
}
return exist;
}