2

I have recorded a few test cases using selenium IDE.I have exported these testcase in the c#(nunit) language.Since the testcases has to be compiled into a .dll file , i created a library project using visual studio community and pasted my testcases into that project.Then i build this project for generating all the necessary .dll files needed to run the testcase from azure.After this i pushed the entire library project folder into azure repos(along with the DLL files).Unfortunately when i run my pipeline, it keeps failing at the task "VsTest - testAssemblies".

Error message from azure logs-

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

Note: I am able to run the dll directly through vstest.console.exe on my local machine using the command promp without any issue and i dont get any of these errors.I am also able to see the automation happening after this.Why can't i do the same from the azure pipelines?Plz help

Vignesh Swaminathan
  • 319
  • 1
  • 9
  • 24

2 Answers2

2

Sometimes running UI tests locally is faster than on server, and the desired element is not complete loaded when the method get called. Thus you see above error Unable to locate element....

You can try checking option Test mix contains UI tests for VsTest task. Or set to rerun the failed tests for a couple of times.

enter image description here

You can also try using WebDriverWait for the ElementExists() in your test code to make sure the element is visible. Please check about this thread to check if page has completely loaded in Selenium for more information.

Hope above helps!

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
2

Your locator is not able to find the element for which it is looking for. That’s probably because the website is loading slowly. You can put a wait before every line in your script or you might have given the wrong location.

For example:

 Thread.Sleep(3000);  //3 seconds wait
 driver.FindElement(By.Name("q"));   // finding element by name
pheeleeppoo
  • 1,491
  • 6
  • 25
  • 29