【问题标题】:My test cases fail when all test cases are run. But passing when ran individually运行所有测试用例时,我的测试用例失败。但是单独跑的时候通过
【发布时间】:2021-02-02 19:22:25
【问题描述】:
//This command is for scrolling into view of an element
public static void scrollIntoView(WebElement element, WebDriver driver) {
  ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
}

//This command will make the script wait until a certain element is visible before doing any actions
public static void untilVisibility(WebElement element, WebDriver driver) {
  WebDriverWait wait = new WebDriverWait(driver, Helper.TWENTY);
  wait.until(ExpectedConditions.visibilityOf(element));
}

//This command will make the script wait until a certain element is clickable before doing any actions
public static void untilClickable(WebElement element, WebDriver driver) {
  WebDriverWait wait = new WebDriverWait(driver, Helper.TWENTY);
  wait.until(ExpectedConditions.elementToBeClickable(element));
}

我在我的测试用例中使用了这三种方法,但有时脚本仍然无法等待元素的可见性,或者即使在运行时显示了元素,它仍然会失败。但是当我重新运行它们时,它们会单独通过

例如我有 98 个测试用例,第一次运行 20 个会失败,但是当我重新运行 20 个测试用例时,它们通过了

【问题讨论】:

  • 您可以尝试在每次测试之前重新加载页面(如果您还没有这样做的话)。您也可以尝试找到存在此问题的较小测试集,这可能会缩小原因。
  • 等待是如何配置的?可以分享一下代码吗?

标签: java selenium


【解决方案1】:

您能提供异常消息吗?我猜这个异常是由这些测试方法使用不支持同时使用的同一对象引起的,比如文件的IO。

【讨论】:

  • 抱歉,异常消息是什么意思?它像错误消息吗?返回的错误是脚本无法通过我页面中声明的 xpath 找到元素。但如果我独立运行它就会失败
  • 是的,这是错误信息。这些方法是否在线程池中按顺序执行,例如Executors?为什么他们有时会出错?相反,他们是正确的。你能考虑一下执行顺序吗?
猜你喜欢
  • 2019-12-18
  • 1970-01-01
  • 1970-01-01
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
相关资源
最近更新 更多