microsoft / WinAppDriver

Windows Application Driver
MIT License
3.69k stars 1.4k forks source link

Executing Tests on another pc : AutomationId and XPath not found #783

Open JulesCharlet opened 5 years ago

JulesCharlet commented 5 years ago

Hi, I developped some winAppDriver tests for a UWP application, using Visual Studio and NUnit. They work fine on my machine, but my purpose is to provide them to a team of testers, executable without visual studio. For that I use NUnit GUI, TestCentric, allowing to load the tests outside of the visual studio perspective, and execute them.

After setting up the solution on a tester machine, the tests work partially : Loading the app work, finding an element by name or classname (and clicking it) work, but finding an element by accessibilityId or XPath doesn't (throwing "System.InvalidOperationException : An element could not be located on the page using the given search parameters")

I guess he's missing something for it to work properly, but I don't know what.

Do you have an idea of what could explain this behavior, and how to fix it ?

Thanks

hassanuz commented 5 years ago

This sounds like it could be WinAppDriver not having enough time to find the element in question. Can you try adding a 20 second Thread.Sleep timer (I know, not ideal) on the suspect test cases to see if this resolves it?

If the XPath is absolute from the reference of a root / desktop session, then I wouldn't expect it to work anyhow since desktop elements and attributes are different from PC to PC. Though AutomationID should still work assuming the app is the exact same version with the AutomationIDs coded in.

JulesCharlet commented 5 years ago

Thanks for your answer. In my tests, for almost each interaction with an element, I have a WebDriverWait adding a dynamic wait before interacting. It is set to 1 sec (maybe it's not enough ?), and can be called twice, due to the way I made it :

try { _wait.Until(ExpectedConditions.ElementIsVisible(element)); } catch(WebDriverTimeoutException) { _wait.Until(ExpectedConditions.ElementExists(element)); }

Also, in the basic tests I made to determine what was working and what wasn't, It seemed like the test was failing instantaneously (maybe it seemed that way because the 1 second time is too short ?)

I'll test your solution and come back to share the results, but I can't do it now, so it will be some days/week later.

JulesCharlet commented 5 years ago

Also about XPath, I only use relative XPath in my tests. Here it was "//*[@Name='NameOfTheElement']"

JulesCharlet commented 5 years ago

Hi,

Firstly, I tested @hassanuz solution, to add a 20 second Thread.Sleep(). It didn't work, so instead of adding fix waiting time at the beginning of the test, I changed my WebDriverWait so it can wait up to 10 seconds instead of 1. Again, it didn't work, and that time it was clear that the test failed instantaneously, not waiting for the 10 seconds (not even 1).

Secondly, I was able to test it on another tester's computer, on which actually I've installed the solution before (but he never used it, and then was unavailable for some time). On his machine, where Visual studio is not installed either, the tests work well.

I'm still thinking it's a build issue, and that he his missing something on his computer (that the other tester would have) but I have still no idea what it could be. It could also be due to differents PC configs, but after the last tries I've made I think it is quite unlikely, isn't it ?

Thanks again