How can I run UI tests with FlaUI on a remote machine whilst not RDP'd into it?
Asked Answered
F

3

9

We have some UI tests that use FlaUI to automate interaction with the windows UI.

When we run these tests on the build server, they fail to interact with the UI unless someone is connected via RDP.

The error we get from the tests is just a Could not send mouse input. ErrorCode: 5

The machine is set up to log in a user on startup and if we log in to an RDP session as that user and 'watch' the tests then they run ok and can interact with the desktop. As soon as we disconnect that user then they stop being able to interact again.

We are running the tests via NCrunch grid nodes, using NCrunch grid node console app, which starts on log in (ie its not running as a service so it can interact with the desktop).

Is there some way to make the tests run in a way that means we don't have to watch them continuously?

Focus answered 10/1, 2019 at 20:23 Comment(7)
do they stop running after a RDP session was closed or do they not even start to run at all when no RDP session is open?Lorelle
I have made some progress on this and have them able to run as long as no RDP session has been started, and they stop after an RDP session is connected and then disconnected.Focus
How about this Remote Execution Guide?Plainclothesman
Are there physical monitors connected to the remote machine?Andras
@JaredBeach nope.Focus
@SamHolder, I think the easiest thing to do would be to get a physical monitor or even a fake monitor plugged into the machine and leave it always logged in. Is this an azure instance or something?Andras
its a VM sitting in a room full of server racks, and mostly the issue is resolved nowFocus
L
6

If you simulate a mouse click, there has to be an active desktop session (https://github.com/Roemer/FlaUI/wiki/FAQ#how-can-i-run-flaui-tests-on-a-build-serveragent).

You have two options: test without mouse clicks (use UIA patterns) or ensure an active desktop session for the build agent. As stated in the FAQ, make sure the session is not closed after disconnecting RDP by running tscon 1 /dest:console

Lorelle answered 16/1, 2019 at 12:53 Comment(3)
I'm unfamiliar with the command tscon 1 /dest:console. If I run this then disconnect the RDP session will that ensure that the machine does not lock?Focus
that's exactly what it does, yesLorelle
This is pretty much the right answer. Many UI interactions need a desktop session. The mentioned command keeps the desktop session open, whilst disconnecting from RDP closes it. As an alternative, we were fairly successfull in using VNC instead of RDP.Fallon
W
1

As far as I remember, you can invoke events on the controls instead of simulating them with the mouse. It is different as the events are injected. This applies not just in TestStack.White adaptation, but in the most robot frameworks. So what was and is the motivation behind using the mouse?

When the JQuery came to Javascript, among other things it changed paradigm how items are referenced. But it also reduced the amount of code you need to write, create a utility method and change:

FindFirstChild(cf => cf.ByAutomationId("RedButton")).AsButton().Click();

to something shorter, for example:

_.Find<Button>("RedButton").Click();

Inadvertently you remove one layer of abstraction, make them more readable, runs faster, does not depend on screen resolution or dpi, etc.

One thing I would try if previous was not applicable - run the NCrunch Grid implementation in a virtual machine. I mean, in theory, it could work.

Wandy answered 19/1, 2019 at 14:7 Comment(0)
F
1

So I have made this work. Mainly I followed the instructions here but I also disabled ServerManager from starting up when the user logs in in TaskScheduler.

The company policy also prevents machines from not locking so we have a powershell script which presses numlock twice every minute to prevent the desktop from locking.

There were also issues with the desktop being too small when the default user logs in which also prevented things from being clicked.

Focus answered 22/1, 2019 at 6:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.