How to simulate that someone is "watching" the monitor? - selenium

I am automating web-application tests that are driven by Selenium architecture in Windows VMs, connecting via Windows Remote Desktop. It became known to me that Flash/SWF and other in-browser elements behave differently if the VM window is opened/shown (all is cool) and when the window is closed (or maybe even minimized). Which means that browsers/plugins engage some optimization if no one watches the screen (I might be wrong with that - if so - please correct me).
As a (working) workaround, installing VNC (and logging into it at least once before running the tests) helps. From that moment noone needs to "watch" the monitor.
I think that the same functionality/system calls is used by (for example) movie players that cancel the screensaver during the film watching.
The question is if any special daemon was written for those purposes, so I won't need to connect to those machines by VNC, but only to run the daemon.
Update: http://www.jddesign.co.uk/products/freeware/freeware_programs.htm - meanwhile found this utility, checking if it will do the job. Advices are still welcomed.
Update N2: the utility above doesn't do the job.

What you experience is the standard render optimization: The OS will ignore all rendering commands if the window isn't visible.
My guess is that VM tools "minimize" the whole desktop to save memory as long as no one is connected.
On Unix, I'd write a small script which runs the VNC viewer when the tests are started.
[EDIT] What you're looking for is a kind of /dev/null device for VNC connections.
Here is a solution that might work: Download the sources for the TightVNC Java Viewer (license: GPL) and remove all the rendering code.
That should allow you to start a headless VNC client for your tests.

Related

How does selenium behave without an "active session"

I've been working with Selenium for a few years already.
I started with some little stuff in Java and in my previous job I did a project using C# bindings with SpecFlow framework, page objects model, I dealt with complex locators, some JavascriptExecutor even some browsermobproxy work, bottom line I have some experience with Selenium.
Still there is something that is not clear to me.
Is Selenium expected to work properly when there is no "interactive session" into the machine that is running the code ?
Let's say that I connect into remote desktop to a machine in the cloud (Let's say Amazon or Azure), I develop a script and schedule a windows job to run it on the next 10 minutes, then I disconnect from the remote desktop session, the machine is on but no user is connected to it in remote desktop.
Will the script work ? Or depends what does it do ? Might some of the actions not work (Script might include changing the window size, sending keystrokes both through selenium sendkeys and by OS level actions) ? Can we ensure that any script that we developed and works OK while we are connected to the machine will also work when I'm not ?
I hope the question is clear, if not I can maybe explain further
Thanks !!!
Yes, Selenium can run on the cloud machine even though you are not connected to it. It should work without any issue.
As per my knowledge cloud machines are protected by firewall which blocks almost all the ports. You may need to get permission to use the default selenium ports like 4444 or 5555.
Also, may need to increase wait time because the cloud machines are slow in performance compared to normal physical desktop.
Usually cloud machines are linux based, you need to consider the environment as well.

Running Selenium Server & ChromeDriver as a Windows Service

So that we may perform front-to-back web UI testing, we are using Selenium and ChromeDriver to automate page loads/interaction as part of our testing pack.
This is behaving as expected during developer testing (on a developer's local machine), but we are struggling to perform these checks as part of our continuous integration build.
Our server plant is *NIX based, and all of our CI infrastructure runs on these machines. So that we may test Chrome under Windows (our delivery mechanism), we have configured a Selenium Grid. When the CI tests run, they access the grid, in order to locate a Windows node to run the tests on.
We have had a Windows desktop provisioned solely for the purpose of running these tests. This contains our standard enterprise build of Windows 7. This machine will be periodically rebooted in-line with the IT department's update policy.
In an effort to ensure the Selenium server is always running, we have added the Selenium Server (running in "node" mode) as a Windows service. The selenium Server is configured to start-up ChromeDriver to invoke the simulated user-interaction.
However, when running the tests from CI they fail due to timeout. Our working theory is, the system user that is running the service cannot create interactive windows. A web search has raised reference to the "Session 0" problem, but with little to no constructive advice on how to move forward.
Starting the Selenium Server process manually from an interactive session is not a viable solution, as this is leading to brittle tests - which are failing due to an infrastructure problem, rather than a genuine test regression.
How can we have an instance of Selenium Server started via a Windows Service whenever the system reboots, that is capable of launching Chrome instances?
It could be easily done with NSSM.
Installation of services looks like these:
nssm install seleniumhub java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role hub -hubConfig C:\selenium\hub.json
nssm install seleniumnode java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\node.json
It provides easily way to remove service if needed:
nssm remove seleniumnode confirm
Add destination to nssm to your PATH variable and run from console as admin
UPDATE April 2021
NSSM is not supported for more than 3 years. So please consider other options like winsw or any other. WinSW does the same job as NSSM and allows to keep run configuration in xml.
You cannot run Selenium Grid as a windows service ever since Windows Vista. Microsoft calls it "Session 0 Isolation". You could do it in Windows 2000 or XP but since the time that Vista came out, Microsoft no longer will let Grid interact with the desktop (or any other UI programs for that matter). Regardless of the fact that you still see that "interact with desktop" checkbox, it is a red herring. So, you MUST run Selenium Grid in the foreground on that server in order for it to get access to the session. If it is running Windows Server, you could in theory have multiple sessions and leave Grid running in the foreground on one of the non-zero user sessions.
Right now you can't help it - it used to work fine in session 0 but for the past few days after chrome update only works for interactive sessions.
Related bugs:
https://code.google.com/p/selenium/issues/detail?id=8029
https://code.google.com/p/chromium/issues/detail?id=422218
My preferred solution to this problem (and my default choice for running Selenium Grid as a service) is to use a simple tool called AlwaysUp. It has a free 30 day trial to try it out.
What to do:
Download AlwaysUp
Configure AlwaysUp to start the Selenium Grid node on startup
Configure AlwaysUp to run the Selenium node as a specific user (not the default System user)
This way the the node will run as a service, survive machine restarts and work with the latest version Chrome.
If the user account you use to login to the machine is different from the user account you specify to run the node as a service then you will not see the browsers pop up on the desktop as they are running in a different user session. The end result is that it is almost identical to running as a normal service but gets round the Session 0 issue.
Yeah, you should use NSSM. Important is, that you add your windows account in the "Log on" tab, or any other valid account. If you run your node with the "Local System account" option, you will get the session 0 problem. With a normal user session, the nodes run smoothly invisible in the background :)
we don't use selenium GRID, we were disappointed with its stability. We use a "Jenkins Grid", that is jenkins slaves nodes on various servers.
The slaves are services with the interact with desktop flag. They run as services with NSSM, and the SERVICE_INTERACTIVE_PROCESS flag. Making sure that NoInteractiveProcess is set to 1 (cf https://learn.microsoft.com/en-us/windows/desktop/services/interactive-services).
We don't have the fancy features of the grid (that is balancing according the browser types slots). Instead, we have Jenkins balancing the test jobs using a slave node or another.
Initially we did not use the interact with desktop flag, having browsers to run without "real" display, but the behavior was not very stable (especially with resize commands).
Hope this helps.
As I explained on this thread, I found that using a small paid tool FireDaemon Pro saved me a lot of time from trying to configure NSSM and other free tools.
It works well in the background, and restarts Selenium along with the server, which was my main requirement for running Selenium Standalone Server as a Windows Service.
This free tool would probably do it:
http://yajsw.sourceforge.net/
For that to work, you need a wrapper.conf file and a script to run the YAJSW wrapper. I takes time to read the documentation, but it is a free solution.
I wrote an example shared here, that installs JBoss7 as a Windows service.
Of course, you can simplify my example by a lot.

Selenium Chromedriver on remote Mac machine very slow and timing out

I am running a Selenium test suite on multiple browsers on a remote Apple Mini. I schedule these tests with Bamboo.
When running the tests on Chrome, they are extremely slow and some actions timeout, causing the tests to fail.
More interestingly, this only happens when Bamboo kicks off the test. When I kick off the tests from my local computer, they run fine.
I have read that Chromedriver performs poorly sometimes when automatically detecting proxy settings. I have addressed this but still the performance is poor.
Has something like this happened to others and does anyone know what could cause something like this?
Something similar happens to me.
The root cause can be in the network connection between the Bamboo server (where the project is built) and the Selenium server (which probably runs on another machine).
When you kick off tests suite from your local machine, you probably have the project build and Selenium running at the same place. So, the commands sent to Selenium do not have to pass the network stage and there are almost no delays.
Try to eliminate the slow connection or investigate if it is possible to build and launch your tests on the machine which runs the Selenium server.
I had this when running tests on Team City with multiple browsers on a remote Mac Mini.
After much head scratching we stumble upon the fact that tests sped up if we remotely connected or connected a monitor to the Mac Mini.
We can only assume that the Mac Mini is smart enough to reduce resource to GUI activities if it knows there is no mechanism to attach a GUI.
Therefore, we purchased a very cheap monitor and left it attached to the MAc Mini, and all started running normally

Automated UI testing on remote computers without installing anything remotely

Which options do we have to do automated UI testing on remote computers connected via RDP, if I don't want to install anything on the remote computer?
My only idea is to open the rdp session always in the same way and use recorded mouse and key strokes, but there are some disadvantages, e.g. I assume it's slow?
Anyways, do you know any open source or proprietary tools I can use? Best would be that I have to install nothing on the remote machine and play the record on my local machine.
Starting with UFT 11.50 (previously known as QTP) there is support for image based testing.
You can have one machine with UFT installed and replay on other machines via RDP using Insight UFT's image based automation solution.
eggPlant Functional allows you to automate the UI of any app on Windows machines using an RDP connection. It's pretty fast assuming you are connecting over a decent network, and you don't need to install anything additional on the target machine.

Using laptop as a second programming monitor

The joys of multimonitor programming are countless, I think there are about 5 blog posts on Coding Horror on the topic alone!
I often code in Windows on my main machine, and have my Mac laptop set up to the side. I use the Mac both to compile Mac builds but also as my "reference web browser". There's no KVM or anything.
However a casual conversation at a conference led me to the question, could I use two independent machines to share windows? Literally move some windows from one machine to another, so I could use one PC's display as "overflow" from the other.
Some googling suddenly shows that this is possible in some situations for sure:
Synergy and Maxivista
My question is whether any programmers have tried such a setup. We have unique needs especially with multiple text windows and editors, and this kind of tool may be a huge win or a huge hassle.
This solution feels like a combination of easy KVM switching AND multiple monitors.. it sounds like a programming dream! So advice or especially reports of actual experience in a programming environment would be greatly useful before I invest in the rather complex setup.
Followup:
Sounds like I'm asking for something that doesn't exist! It's kind of combination of a software KVM and VNC. But the VNC would need to break out the app windows and allow individual manipulation (like that maxivista commercial tool, which is Vista only).
Thanks for all the feedback. Looks like there's demand for a cool app if anyone has the drive to be first in this new nich!
Synergy doesn't allow you to move windows between machines (that would require a silly amount of work behind the scenes), but it does allow you to share a keyboard and mouse between two machines so they "appear" to be all one machine, but actually run separately.
I personally use Input Director, as I found it more stable than Synergy. I have my laptop with an external monitor to the right, and my desktop to the left as an Input Director slave. My desktop runs a different O/S and is basically my guinea pig box for testing stuff and for anything I need to keep running when I leave the office. Cut + paste is pretty seamless, so I can quite happily fire up an RDP session to a server on my desktop, and cut+paste SQL scripts from that to my laptop.
It's a very useful thing to have if you have a few physical boxes and monitors kicking around :)
I've actually managed to use spare notebook as a second monitor to Desktop PC. This allows to move windows to second PC, but not vise-versa.
Solution would work basically with any OS.
The only requirement is a spare VGA (or DVI-I/DVI-A) port on server PC.
Make a dummy VGA plug http://www.overclock.net/t/384733/the-30-second-dummy-plug
This will also work for DVI-I/DVI-A port + DVI-VGA adapter
Detect virtual monitor with your OS. Monitor will be detected as very generic monitor, so you can set up any resolution. Set it to slave PC resolution.
Use any remote control software to connect from slave to server PC. Set it to display only "virtual" monitor.
That's all. Your slave PC is a second monitor for server PC.
I've used this on Windows 7 + TeamViewer. I've additionally set up Mouse Without Borders (Microsoft Synergy analog) to be able to use slave PC with same mouse&keyboard, though this is not required if you intend to transform it to monitor-only.
Xdmx - Distributed Multihead X Project (linux only)
Provides native X display on external machines, no VNC cons.
The following is not exactly what you want, but pretty close:
You can start a VNC server on the Windows machine, which will let you "export" its graphical screen.
Then, unplug the monitor from the Windows machine and use it as external laptop monitor instead, with your Mac laptop.
There, on your Mac, you just connect to the VNC session using Chicken of the VNC, which will give you the graphical screen content of the Windows machine as a Mac window (interactively, so you can actually control the windows machine as if you were working on it directly). You can put that on the external monitor, and you can also put other windows there, so you really have a shared environment.
I believe this solution also lets you copy and paste content from the Windows screen to Mac windows and vice versa.
I use MaxiVista on WinXP while programming. It works fantastically and lets me add a third screen to my multi-monitor configuration.
There is hope, here for windows users: http://virtualmonitor.github.io/ Looks like a work-in-progress and only supports windows 2000 - windows 7, but he's looking for help with windows 7 - 8.
Unfortunately, synergy doesn't allow moving windows across screens currently. It only forwards mouse&keyboard events from one set of physical devices to different computers.
Yes, and I love it. It allows you get past 2 screens on a laptop, and really I find 3 a great amount.
If your main machine is a Mac you want ScreenRecycler. You can then use monitors on other Mac, Windows, and Linux machines (anything with a VNC client). You will want something better than the Mac's crappy windows management though. I suggest Many Tricks' Moom and Witch.
On Windows, as #LachlanG said, MaxiVista works great. And it supports adding monitors from Windows, Mac, and Linux machines.
I am reusing my old laptop as a second monitor to see the live preview while coding. I am using SpaceDesk, which is free.
I use barrier and open source fork of synergy. Its a little hard to use but works really well. (To find it just search google for 'barrier github').