无法从天蓝色管道运行硒测试用例?

时间:2020-03-23 10:07:22

标签: selenium-webdriver azure-devops selenium-ide

我已经使用Selenium IDE记录了一些测试用例。我已经以c#(nunit)语言导出了这些测试用例。由于必须将测试用例编译为.dll文件,因此我使用Visual Studio社区和将我的测试用例粘贴到该项目中。然后我构建该项目以生成从azure运行该测试用例所需的所有必需.dll文件。此后,我将整个库项目文件夹推送到了azure repos(以及DLL文件)中。我运行我的管道,它始终无法执行“ VsTest-testAssemblies”任务。

天蓝色日志中的错误消息-

Running all tests in d:\a\1\s\chrometest\chrometest\bin\Debug\chrometest.dll
   NUnit3TestExecutor converted 1 of 1 NUnit test cases
  X createnewfolderonly [18s 200ms]
  Error Message:
   OpenQA.Selenium.NoSuchElementException : no such element: Unable to locate element: {"method":"css selector","selector":".butt > span"}
  (Session info: chrome=80.0.3987.132)
  Stack Trace:
     at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)
   at OpenQA.Selenium.By.<>c__DisplayClass23_0.<CssSelector>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
   at DefaultSuiteTest.createnewfolderonly() in C:\Users\Admin\source\repos\chrometest\chrometest\chrometestpage.cs:line 33

注意:我可以使用命令提示符直接在本地计算机上通过vstest.console.exe直接运行dll,而没有任何问题,而且我也没有收到任何这些错误。在此之后,我还可以看到自动化的发生。为什么我不能从azure管道中做同样的事情?plz帮助

2 个答案:

答案 0 :(得分:1)

您的定位器无法找到它正在寻找的元素。这可能是因为网站加载缓慢。您可以在脚本的每一行之前等待,否则您可能给出了错误的位置。

例如:

 Thread.Sleep(3000);  //3 seconds wait
 driver.FindElement(By.Name("q"));   // finding element by name

答案 1 :(得分:0)

有时在本地运行UI测试比在服务器上运行更快,并且在调用该方法时,所需元素未完全加载。因此,您会看到上述错误Unable to locate element...

您可以尝试检查VsTest任务的选项Test mix contains UI tests。或设置为重新运行失败的测试几次。

enter image description here

您还可以尝试在测试代码中使用WebDriverWait for the ElementExists(),以确保该元素可见。请查看有关this thread to check if page has completely loaded in Selenium的更多信息。

希望上面有帮助!