0

I'm running Win10 with developer mode enabled, and I started WinAppDriver. In VS 2019 I ran the calculator example but every test fails with an exception. I then tried setting a bunch of breakpoints, but when I run the tests, it never breaks at my breakpoints.

Here is a stack trace for the exception:

Test Name:  Addition
Test FullName:  Test Detail Summary
Test Source:    C:\Code\WinAppDriver-1.1.1\Samples\C#\CalculatorTest\ScenarioStandard.cs : line 31
Test Outcome:   Failed
Test Duration:  0:00:00

Test Name:  Addition
Test Outcome:   Failed
Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Appium.AppiumDriver`1.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebElement.Click()
   at CalculatorTest.ScenarioStandard.Clear() in C:\Code\WinAppDriver-1.1.1\Samples\C#\CalculatorTest\ScenarioStandard.cs:line 131
Result Message: Initialization method CalculatorTest.ScenarioStandard.Clear threw exception. System.InvalidOperationException: An unknown error occurred in the remote end while processing the command..

Any ideas why the tests aren't working, and why it isn't breaking at my breakpoints?

dymanoid
  • 14,771
  • 4
  • 36
  • 64
Jan Huus
  • 63
  • 8
  • Is you problem related to [this](https://stackoverflow.com/questions/54114128/appium-winappdriver-c-sharp-calculator-example-error/54478256#54478256)? – Señor CMasMas Sep 09 '19 at 14:56
  • About the breakpoints, I experienced some sort of bug where I always had to clean and rebuild my solution before any code changes would get picked up by the test script. It was like VS was compiling old code. If you have any break points on that code, it won't get triggered. – PixelPlex Sep 10 '19 at 06:48
  • The debug problem was my mistake. I'm new to Test Explorer and I thought the breakpoints would hit when you select Run Tests, but I see now that you have to right-click and select Debug Tests. – Jan Huus Sep 18 '19 at 12:19

1 Answers1

0

Line 31 contains the "Addition" test method.

The driver is unable to find the element it wants to click, I suppose either the element under question was not shown on screen when this happened.

session.FindElementByName("One").Click();

Try adding a sleep call right before the click method call.

System.Threading.Thread.Sleep(5000); 
Flexo
  • 87,323
  • 22
  • 191
  • 272
Naeem A. Malik
  • 995
  • 4
  • 19
  • Please consider a more dynamic way of waiting for elements. See my answer [here](https://stackoverflow.com/a/56124852/2697348). – PixelPlex Sep 10 '19 at 06:42
  • Thanks for the help everyone. I see that the main problem was a wait issue. For now I've worked around it by increasing the value assigned to session.Manage().Timeouts().ImplicitWait, but I may consider more sophisticated solutions later. – Jan Huus Sep 18 '19 at 12:47
  • @PixelPlex: You're killing a fly with a shotgun. Try using WebDriverWait class with Until method instead. – Naeem A. Malik Sep 19 '19 at 13:15
  • @NaeemA.Malik, I get your point. I can agree with your argument for small projects that need to be delivered quickly. On larger projects, it makes sense to implement more robust ways of solving this. BTW, if you look at the second code snippet from my linked answer, you'll see I do use 'Until' ;-). – PixelPlex Sep 19 '19 at 14:35
  • Yeah, I agree. I guess I missed the Until call at a glance. – Naeem A. Malik Sep 20 '19 at 11:20
  • Final thought, wait is a test developer's best friend. – Naeem A. Malik Nov 19 '19 at 10:46