Things I tried:
Windows.Graphics.Display.DisplayInformation WinRT API — GetForCurrentView throws saying “GetForCurrentView must be called on a thread that is associated with a CoreWindow”, looks like CodedUI tests run in a process without windows.
GetSystemMetrics WinAPI — returns correct size values, however the screen isn't rotated.
EnumDisplaySettingsEx WinAPI — doesn't fill any values.
DisplayProperties WinRT API — both CurrentOrientation and NativeOrientation are always portrait.
Any other ideas?
Thanks in advance.
CODEDUI Tests indeed run in a separate process. It uses a very specific form of "reflection" to find controls in "other" processes. The base class of codedUI Test controls is the UITestControl
The Windows operating system by design prevents other processes from interrupting or snooping in on what's going on. So, MSFT had to come up with an abstraction of the Process under test, to allow you to "see" those other controls. The addressiblity you get is not the actual control but a representation of that control in the other process. You are able to control it because MSTest has the ability to "send messages to that control". You are limited by the fact that you can only "Get" information on the other process via what you find in the classes in this namespace: Microsoft.VisualStudio.TestTools.UITesting
A good example of this is when testing WebBrowsers, the CODEDUI uses a class named BrowserWindow, which is not at all similar to the WebBrowser classes found elsewhere. The only way I can get at the DOM in CODEDUI is via the BrowserWindow.Document property. I then have to do some fancy casting to get what I want. I suspect this is what you have to do.
Can Anything Else be Done?
Yes, the QA team should be able to establish a few requirements/hooks for them with the programming team. The first thing to ask is "Should a Unit Test have done this?" CODEDUI is NOT true Functional test no matter what anyone teaches, it is simply nowhere close to Unit Testing in validating function.
Secondly, you can ask the development team to put hooks in their code so you can "get at those things". In other words the code now must contain stuff for QA Team to do validation. In your case you can ask developers to put in a method for you that calls GetForCurrentView and passes the results back. But because CodedUI is Visual and not functional you'd have to work with them to figure out how to expose results at GUI layer.
Anything Else?
Yes, one last thing is that you can use Fakes to intercept method calls. If they put the hook in for you, you can call it and intercept the results of the method call... But hey, doesn't this sound like Unit testing?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.