Headless Xcode UI testing for a macOS app - xcode

We're trying to run our tests automatically on a test machine where all the non-UI tests run perfectly well. We have scripts that run the tests on the command line and collect results for analysis.
The test machine (a Mac mini) runs in a headless manner.
For UI tests, however, the test fails to launch the app with an error of the kind,
t = 83.86s Assertion Failure: <TestCaseName>: Application '<XCUIApplicationImpl: 0x60400026e300 com.<app-identifier> at <app-name>.app>' failed to activate (current state: Running Background)
It seems that it's due to the fact that there's no GUI session around when the machine is running headless (macOS calls such a session an Aqua session). We've tried to find a way around this, but haven't made any real progress.
If anyone has any ideas, we'd appreciate.

I believe I was able to get around this by disabling the "Require Password" setting in System Preferences > Security & Privacy and not allowing the machine to sleep or start a screen saver. There's no screen attached to the Mac Mini so that's fine.

Related

Reporting status back to TeamCity when a test is ran locally

We have a testing framework made in AutoIt for our Windows apps (older legacy apps that we will continue supporting). These have never been run on a schedule or part of CI (always been run manually). I tried to get some kind of auto run (or even just status reporting) out of the tests, with minimal luck.
I have a VM where the tests can run. I experimented with my own web app, which works okay locally for running and status reporting. But when set up on the server, AutoIt reports it cannot open the application. Same thing happens if I try to run the tests from a .bat file.
My current solution is to have AutoIt call my web app to report status (working okay locally, untested on the server), or to see if I can get AutoIt to report results back to TeamCity. I have the agent installed but when I run the build from TeamCity, AutoIt reports it can't launch the application. I tried this while logged into the VM, logged out, with RDS open; no luck.
Is it possible to run the tests manually from the VM and send results back to TeamCity? When I run them from TeamCity it reads the AutoIt output (which is in the expected format), but I need to let TeamCity know to update the results (so we can use TeamCity rather than my web app to show the results).
I may need to find a way to let TeamCity know a build has been started, which might then let it know to keep an eye on the process' output, but I'm not positive. Any ideas?
I solved this so it could be done more traditionally.
If anyone is confused by what "running the agent from the console" meant, it just means installing the agent without selecting the "as a service" checkbox, and then manually starting the agent by cd'ing to the BuildAgent/bin directory and running the command agent start. I also created a batch file that will do this automatically (but you must run it as admin).
Further, I found AutoIt couldn't do anything if the test doesn't run from the right directory, so I had to devise a solution to this.
The only issue now is that I have to have an old laptop always connected to the virtual machine the tests and app run on (since the AutoIt tests won't work without the VM desktop being interactive).

Automate tests on virtual machine without graphical session

Context :
I execute automated GUI tests on virtual machines (there are few of them) on running on windows and using UFT/Ranorex, executions are piloted by Jenkins.
Problem:
VM must have an active graphic session, otherwise, UFT won't run GUI tests (unable to launch browser) and Ranorex will run but poorly and without screenshots. i mean that in my tests, the VM is configured not to "sleep" or to have any screen saver, vm is connected with jenkins properly.
The behavior is : i launch via Jenkins the test, one the build done inthe vm, automation tools start running but then finds difficulties to open browser.
I would like to know if there is any workaround to run those tests without being needed to physically open VMware or Remote desktop Connection.
Notice that the VM is running all the time and the session is always open (we are using a server to host the VM).
So the problem is: how to simulate in windows active graphical session. I guess it's like simulating that there is actually a screen connected even though there isn't...
Any suggestions will be welcomed.
Had to go through this many times and you can find a lot of resources related to your issue in the Ranorex Forum. (My username there is Martin for reference).
But to go through the points you need to do quickly:
1) Have an RDP machine to connect to that is used to run your tests
2) You need to disable screen saver for that machine (I had to do it from registry)
3) Then disable the "On Resume, display logon screen" option under Personalize settings for the screen saver
4) And finally create a .bat script with the following content "%windir%\System32\tscon.exe RDP-Tcp#0 /dest:console"
So basically when you have everything set up (required only once) you will run the .bat script. This will close the RDP window BUT the session will be left open with the screen enabled.
Just connect the RDP with Jenkins and you have full functionality that you need to run your tests.
Regards
Martin
In the Tools ⇨ Options menu, select General ⇨ Run Sessions there you will find an option to Enable continued testing on locked/disconnected remote computers.
If this fails, see my other answer.
I had the same problem when I try to run an automate tests on virtual machine and I find this solution to generated a graphical session although you are not connected to the virtual machine. You need to created a task to opend a session on the virtual machine when you disconected or terminated the session , this created a graphical session but will not function when you are connected and you have the screen minimize. Here is the link for the solution and the explanation
http://blogs.microsoft.co.il/arnona/2016/01/03/keeping-an-active-desktop-session/

Black screen when taking screenshot with Internet Explorer driver on Windows build server

I am running several automated browser tests with selenium on our build server. There is no problems taking screenshots while running Chrome or Firefox driver, but when running Internet Explorer driver I just get a black screen.
Virtual Machine
Selenium version: 2.53.0
IEDriver: 2.53.0
OS:
Windows Server 2012
Browser:
Internet Explorer 11
I have gone through all the required configuration in the documentation https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
I have also tried the third option here:
https://lostechies.com/keithdahlby/2011/08/13/allowing-a-windows-service-to-interact-with-desktop-without-localsystem/
I have also enabled service interaction globally:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms683502(v=vs.85).aspx
When I remotely access the build server, I can trigger running the tests manually. This works fine. So there must be a problem with our CI(TeamCity) setup interacting with the build server.
I am currently stuck and could need some help ?
This is the default behavior of Windows. since Internet Explorer is tightly coupled with Windows, it behaves this way but other browsers don't.
In order to have better resource utilization, when running on remote, windows detects that since session is running in remote mode and nobody is watching the screen, it takes away the resources required to show the screen and screen goes black. When you log into the machine, resources to show screen UI are deployed again.
Hence, when running in remote mode, since there is no screen being showed, screenshot comes out to be blank.
There are only workarounds, no solution.
Workaround:
Workaround 1: Use VNC server for your remote session instead of RDP since VNC keeps the remote session alive.
Workaround 2: Add this command to batch file : tscon rdp-tcp#1 /dest:console
It will switch the session to "1" which is active mode.
By default it will be running on "0" mode. It will disconnect your session and now you can run your test case.

Why CodedUI test runs in one browser and does not in another with the same version

I have a few automated UI tests implemented with CodedUI. I have a virtual machine where the tests are run by Test Manager (via test controller and test agent). The benefits of this set up is that I can do other work while the tests are run. If I use my desktop to run the tests.
Recently, these tests are failing. The test is not able to step over from a input field to input password field. So, every test fail due to the tests can't log in to the system under test.
When I run these tests on my desktop then the tests are run without any issue.
Since the tests have been failing there were no updates on either system. Only, restarts.
Both system is Windows 7. Both has the same IE10 version. I requested a new virtual machine and the issue is the same. Tests are failing.
I'm in the situation where I can't decide which way of working is the proper. I want my tests running on the virtual env.
Have anybody experienced like this? Do you know any method to identify what could be the problem?
Another part of the situation is that, if I set up the tests to run on Chrome, then they are running, but it seems CodedUI doesn't like working together with other browsers than IE. I got some "method is not implemented" exceptions. I feel this would be another hell.
First of all, Coded UI only works with IE, unless you use Selenium components.
If you can, add the error the test gives after failing.
In any case make sure your test machine has access to the system you're logging into. To run a Coded UI test on a remote machine you also need to have a user logged in.
The root of my problem is really simple, however annoying and this is not the first I'm looking for when I experience issue. The browsers I use for test have different Browser Mode and Document Mode settings.
That one where the tests failed had "Browser Mode: IE 10 Compatibility Mode" and "Document Mode: IE 7 Standards".
The another one where the tests have passed had "Browser Mode: IE 10" and "Document Mode: quirks".
I modified the browser set up values and the tests are running properly.

selenium web driver on windows 7 parallels vm - browser hidden - allow service to interact with desktop?

I am using a script on my mac host to launch a selenium node on a local parallels VM.
Something like
"prlctl exec Win7-VM-Name-Here 'C:\path_here\start_node.bat'"
The node starts up nicely and registers itself with the hub. I can run tests fine against this node.
However, when the tests are running, the browser is not visible on the VM, which means that screenshots are useless.
I think it has something to do with allowing a service to interact with the desktop, but I can't figure out which one, or how to proceed.
Any help?
Thank you.
Unfortunately, this is a common problem with selenium (or any other browser automation software) on Windows. If selenium is running in the background as a service, the browser will not appear when the tests are being run and taking screenshots will just result in a black picture. If you want to be able to watch the tests being run and grab screenshots, the general consensus is to start your script manually from the command line and leave it running.

Resources