硒测试有时会因天蓝色管道而失败,并在本地通过

问题描述 投票:1回答:1

单击按钮后,测试用例失败,但未找到链接或任何验证消息,但失败。

我使用显式等待页面加载:

var waitForDocumentReady = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(10));
            waitForDocumentReady.Until((wdriver) => (WebDriver as IJavaScriptExecutor).ExecuteScript("return document.readyState").Equals("complete"));

对于等待验证消息的特定div:

 WebDriverWait wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(10));
            wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.ClassName("validationErrors")));

但是测试用例有时会通过管道通过,有时会失败。

selenium selenium-webdriver azure-devops azure-pipelines timeoutexception
1个回答
0
投票

您需要注意以下几点:

  • 在单击按钮后找不到链接或任何验证消息的测试案例失败:很大程度上取决于button的属性。如果button包含以下任一属性/事件,则DOM Tree将得到更新,随后尝试查找所需的元素可能fail

    • onclick()事件:

      <button onclick="myFunction()">Click me</button>
      
    • jQuery click()事件:

      $("p").click(function(){
         alert("The paragraph was clicked.");
      });
      
    • 因此,在单击[[button之后,要找到需要诱导的元素,就必须为WebDriverWait引入ElementExists()

    • 您可以在ElementExists()中找到相关的讨论
  • ExpectedConditions.ElementIsVisible returns TimeoutException even when element is present:这行代码对确保所需的元素是否在ExecuteScript("return document.readyState").Equals("complete")中为

    present / visible / interactable无效。

      您可以在HTML DOM中找到相关的讨论
  • 但是
  • 等待特定的div与Do we have any generic function to check if page has completely loaded in Selenium应该已经起作用了。相关的HTML可以帮助我们分析出了什么问题。但是,如果validationErrors相关元素基于ElementExists(),则必须使用 HTML5 Constraint validation方法。
  • © www.soinside.com 2019 - 2024. All rights reserved.