无法在 Azure Pipeline 中通过 Selenium 测试

Unable to Pass Selenium tests within Azure Pipeline

我正在尝试在 Azure Devops 中的 CI/CD 构建管道中构建 UI 测试用例,但我似乎无法解决我们路由到内部应用程序之一的基本用例网页登录屏幕,并验证 Div 和选择器是否存在。

        [Theory]
        [InlineData("Chrome")]
        public void TestFindElementByID(string browser)
        {
            var driver = SetupDriver(browser);
            try
            {
                driver.Navigate().GoToUrl(TestConfig.WebURL);
            
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
                IWebElement element = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("mainRepDiv")));
                //Thread.Sleep(2500);
                //IWebElement element = driver.FindElement(By.Id("mainRepDiv"));
                Assert.True(element != null);
            }
            catch (Exception ex)
            {
                
            }
            finally
            {
                driver.Quit();
            }
            

        }

在我的网页中,我有一个基本的 div,我只想在 chromedriver 导航到 URL 后看到它存在。

Element To Check

这里是 Azure Pipeline 在此测试中失败的日志。 Pipeline Log

我确实有一个额外的测试,它只是断言浏览器能够转到 URL,而 URL 实际上是我路由到的,并且该测试通过了。

driver.Navigate().GoToUrl(TestConfig.URL);
Assert.True(driver != null);
Assert.True(driver.Url.ToLower() == TestConfig.URL.ToLower());

还有一些层可能使这变得更加困难,例如 Azure Pipeline 运行正在关闭自托管代理。

到目前为止我已经尝试过的事情:

所以对于 Azure Pipeline 构建本身以及 ChromeDriver 无法通过此测试的原因,我有点不知所措。

最后 - 如果这也有帮助,这里是与任务相关的 YML 文件的屏幕截图。

- task: VSTest@2
  displayName: "Run UI Tests"
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\Project.Test.UI.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    uiTests: true

Unable to Pass Selenium tests within Azure Pipeline

请确保您的私人代理运行是一个交互式进程。

根据文档Interactive vs. service

You can run your self-hosted agent as either a service or an interactive process. After you've configured the agent, we recommend you first try it in interactive mode to make sure it works. Then, for production use, we recommend you run the agent in one of the following modes so that it reliably remains in a running state.

  1. As an interactive process with auto-logon enabled. In some cases, you might need to run the agent interactively for production use - such as to run UI tests. When the agent is configured to run in this mode, the screen saver is also disabled. Some domain policies may prevent you from enabling auto-logon or disabling the screen saver. In such cases, you may need to seek an exemption from the domain policy, or run the agent on a workgroup computer where the domain policies do not apply.

因此,如果您的代理不是 运行 交互模式,请配置另一个交互模式的代理来测试此问题。