Run UI SeleniumRC tests as a part of CI process - continuous-integration

I'm trying to setup CI environment for QA department. They use SeleniumRC to run UI tests in IE and FF browsers to test some web application. I had a success configuring it to run as a windows service as described here. However when i run the test it hangs. I can see iexplore.exe process spawned by Selenium service in the process list but nothing more happens. No browser window appears, no entries in the windows event log. I did a lot of googling and as fas as i understand the problem is interaction with desktop. I tried to run the service under SYSTEM account with "Allow service to interact with desktop" check-box set as well as under a regular user account with local admin permissions. So my question is if it's possible at all?

In our organization we have a continuous integration server (Cruise Control) running the build including Selenium RC tests. The CI server is run as a Windows service (on MS Windows 2003 Server) and Selenium tests are just part of the test suite.
That is quite a straightforward setup and frankly I see no reasons for giving up with it. Currently in our setup the Selenium server (and client) is started directly from the tests (however we used to have Selenium as a separate service).
In Java code (actually in the super class of all web tests) we do something like:
// to start the server
RemoteControlConfiguration config = new RemoteControlConfiguration();
config.set(...) // set the serverHost and port
...
SeleniumServer server = new SeleniumServer(config);
server.start();
// and then to start the client
Selenium selenium = new DefaultSelenium(serverHost, port, "*firefox", "http://www.google.com");
selenium.start();
selenium.open("http://www.google.com");
// now the browser should be visible for you (if you run it locally, not as a service)
So I would suggest you trying the following (whatever language you are using):
Try to run the Selenium server and client from just a standalone application. The browser should show up as a window. Adjust the settings to your needs (browser type, etc.).
Try to incorporate the code within your test framework (xUnit or whatever). Run them manually. The result should be the same.
Then you can try to have the tests run from the continuous-integration. Run the CI server as a service and let it build your project. The browser wouldn't be visible, but that's not required for the tests to be run, isn't it?
NOTE:
if you wanted to peep what Selenium is doing, I believe it would be easier on UNIX machine. You could point the tests to use the X-server DISPLAY of your choice - a fake one or a true one connected to some monitor.

I'm skeptical about running anything as a windows service that is supposed to interact with a desktop application. Windows services run in their own sandbox; they're not supposed to interact with a user's desktop or its applications. To do so requires special efforts to communicate with the service, so if it is possible at all, I would think there would be some kind of desktop client running as well, acting as a liaison between the browser and the windows service.
I can't tell you it won't work, though, because it is obviously possible if people are blogging about it.
Why does it need to run as a Windows service, by the way? Is that how Selenium has set up their automation, or can you do it without the Windows service? Because I think that would be the shortest distance between two points.

My recommendation would be to have a dedicated machine (or virtual machine) for running Selenium RC. In my experience it's best to let Selenium run interactively rather than in a headless mode.

Related

Cypress tests against devtools port only

We use some third party enterprise software ("Container App"), which has an embedded Chromium browser, in which our webapp runs.
We use Cypress to test our webapp in a stand-alone browser outside of this container, however we would like to be able to test it inside, as it interacts with the container in various ways through javascript.
The only thing the container exposes is a "remote devtools-url" to the target (our) browser, which can be pasted to a native browser outside of the container and then debugged in devtools. Like this:
The Container provides 2 different url's for above debugging purposes, and they both work and seemingly similarly. They are something like the following (not precise, unfortunately I am not at work atm):
devtools://...inspector.html?id=xxx
http://ip/...inspector.html?id=xxx
Is it possible to setup Cypress to test "as normal", only having access to this remote devtools-url/port?
The target browser inside the container cannot be started by Cypress, as only the container can start and close it. So the target browser will already be running (with a --remote-debugging-port). I can get the devtools-id dynamically through a call to /json/list.
If not possible, any other way to achieve the goal of testing the browser/app running inside the container?
It is not possible. Testing with Cypress a web page in embedded Chromium running in your application means Cypress needs to connect to already running browser. Cypress doesn't have that possibility.
The documentation states:
When you run tests in Cypress, we launch a browser for you. This enables us to:
Create a clean, pristine testing environment.
Access the privileged browser APIs for automation.
There is a request in Cypress issue tracker to add the option to connect to already running browser. But there is no response on it from Cypress developers.

Selenium setup on Windows for Chrome and IE

As far as i understand, there are two possible ways of setting up a selenium server (just a node) on windows:
As a windows service
Using the task scheduler to start the server running within a local user account
However, using the service way (where no desktop is available) the Internet Explorer can not be used.
Therefore, i created a local user account and a scheduled task to start the selenium server at startup connected to the user account (using the selenium-standalone package, selenium-standalone start --drivers.ie.arch=ia32).
Unfortunately, i ran into the "Session 0" problem, which requires a real login for the local user account. Otherwise, i would receive a timeout error for
Chrome and black screenshots for IE and have the max resolution of 1024x768...
However, with a active user session, i still get the timeout error for IE (Chrome works). The browser makes the initial GET request (retrieving the login page) but keeps stuck after this (next step would be to fill the form with credentials using protractor).
I read about the Headless Selenium for Windows that gives me some connecting layer between the driver and the GUI. Though, i do not know if this would help and how to integrate this into the selenium-standalone package.
So, my question is, what is the missing puzzle in the setup?
I would suggest you to move away from Session 0, as Chrome is trying to move away from Session 0 too in the near future.
You can find further references of this here (comment 21 in the link below, but actually the whole thread is a good read in respect to this subject): https://bugs.chromium.org/p/chromium/issues/detail?id=615396#c21
You could try using this setup for Chrome for now, however there is no guarantee that it will still work while Chrome is started Session 0.
var chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("test-type");
chromeOptions.AddArguments("--disable-extensions");
chromeOptions.AddArguments("no-sandbox");
var driver = new ChromeDriver(chromeOptions);
I had the same issues with using Microsoft's Test Agent, and moving the agent from a windows service to a process, solved all the issues and headaches that I had.
As stated above, there are two ways to accomplish the setup. However, only with using a scheduled task i was able to workaround the session 0 issue (as #Cosmin stated). Using NSSM and FireDeamon Pro was a dead end.
I reconfigured the server, to automatically login the local user account and changed the scheduled task, to run if and only if this user is logged in (starting Selenium). So, after the server starts, the user gets logged in, which triggers the task scheduler (at this point a simple startup script should work, too) to start Selenium.
And for the screen resolution problem: The VM setup uses Hyper-V, where the default resolution is 1024x768. This could easily be changed (to the max resolution the screen adapter is providing) to 1600x1200.
PS: The Headless Selenium for Windows did not work either (can not be used with Protractor). However, even this is no longer necessary. IE works this way.

Automating TestStack.White UI Testing in Windows Slave using Jenkins

First of all, I apologize if I am wasting your time, because it looks like a simple step which I am not able to figure out even after some research.
Ok, here is what I am trying to achieve, I have written some UI tests using TestStack.White, I would like to execute this on a Jenkins Slave as different user, since the application behaves differently based on the roles that are assigned to them in Active Directory.
So after doing a bit of lookup on google I found the following links which are relevant to what I am trying to achieve.
http://teststackwhite.readthedocs.io/en/latest/AdvancedTopics/ContinuousIntegration/
How to get Sikuli working in headless mode
Jenkins on Windows and GUI Tests without RDC
It looks like that I have to install TightVNC on Jenkins slave and should connect to slave from Jenkins Master and execute tests on slave.
Which brings me to my first question, how do I exactly achieve this from a Jenkins job?
About logging in as different users, I understand I can use to "autologon.exe" to achieve this. So just wondering how I can do this on the Windows Slave from Jenkins Master. My company doesn't allow SSH to Windows instances (slave machines), I cannot remotely execute SSH from Jenkins Master.
I understand that I may not be looking at this correctly, so any help would be much appreciated.
Thanks in advance for your time and advice.
I am getting ready to do something similar to this but I am building a communication layer into our UI Automation application so that our build machine (our company rolled our own build machine) can send TCP request back and forth. I am going to deploy the UI Automation and the build to a share then start a virtual machine. The build machines template will have a startup script that launches both our applications from the share. Once the virtual machine is started then I am going to communicate with the UI Automation application to tell it to start and it will tell me when its done so I can tear down the VM. I am going to save all the test results out to a share for reporting purposes.
I know this doesn't directly answer your question but this approach is one I have heard about from multiple people working in various automation frameworks.
If I was going to do this in Jenkins I would look into Jenkins plugin system. The plugin system as far as I know uses Java so you should be able to create some type of communication layer and interface with some type of VM. If you don't have the option to start and stop a VM you will need to look into start and stopping processes on a remote machine while masquerading as a user. I know this can be done in C# but I have never looked into it in Java.
Thanks all for your comments and answers, basically this is what I did to get it working for me,
Establish VNC connection with a VNC Client on Jenkins slave, this was done manually not through Jenkins.
Use an app called "Caffeine" to prevent windows from locking out, it simulates a key up event on F15 (every xx seconds) so there is no interruption with testing task in my project.
Launch JNLP connection to the Jenkins Master and "Caffeine" app as a part of windows logon through VNC Connection.
Close out of the VNC connection (not logging off), this was done manually not through Jenkins.
Let the build run as different users using PSExec on the slaves.
This seems to be working fine so far, I didn't reply sooner since I wanted to monitor the jobs for a few days before posting my reply here.

session0 isolation in Windows 2008/windows7

I have a C++ application which used Mutex, Events,Semaphores for synchronization. While hosted in windows 2008 server/Windows 7, this application is not starting from a remote client.
I used telnet client to connect remotely to this application and saw that telnet server is running under session 0 and therefore it is trying to start my application under session 0. My application is trying call OpenMutex to open a mutex which was created by another application running locally (in session 1).
I can make my application work by perpending "Global\" to mutex name. What I am looking for is a way run application without making this code change. Is it even possible? Is it possible to launch telnet service under session 1.
CreateMutex(&sa,FALSE,Buffer, "MyMutexName"));
I can modify this to CreateMutex(&sa,FALSE,SYS_ID2(szSysIdBuffer, "Global\MyMutexName")); but is there any other way other that making this change.
Thanks
You probably know the document http://www.microsoft.com/whdc/system/sysinternals/session0changes.mspx which describes problems with the Session 0 isolation. The old way to make a service interactive which are described in http://msdn.microsoft.com/en-us/library/ms683502.aspx not works on Widows 7 because Terminal Services are active per default.
So it seems to me that in your case the way with the "Global\" prefix, which you currently use, is really the best one. To understand the complexity of an other possible way you can read following Process with administrative privileges run on user logon.

How does a windows service set off an application at a standard interval?

A consultant setup a windows service to run a application. The application is supposed to run every 15 minutes. The application is not running at all and the service appears to be running fine.
I am not familiar with how an application will run at a standard interval when running as a service.
The service uses the SRVANY.EXE tool.
Any 'consultant' that sets up a service to run using SRVANY.EXE should be fired. SRVANY is an unfortunate hack that should have been retired a decade ago; it should never be used in a production environment.
If the only purpose for the service is to run the app on a schedule then it shouldn't exist at all. Run the app as a Scheduled Task. If it has other functionality then rewrite it as a real service. If it is reasonably well written it should be a fairly easy conversion.
There are many potential issues with your application.
SRVANY.EXE turns any application into a Windows Service. If that application ever asks for user input, it will hang. You will want to confirm that the application running as a service does nothing more than start the other application.
You should also be able to run the "starter" application manually, outside the Windows Service. If it still doesn't work as it should you know it's not related to being run as a service.
To add to the other answers: see KB137890 on what SRVANY.EXE actually does and how to find out what application it is running.
It seems to me that you would be better off (if you can) setting up a scheduled task that runs every the application every 15 minutes if you can.
I'm not sure if this is correct, but I believe one way of a serivce running an application is merely to have a thread within OnStart and set it to run the application on an invertal of 15 minutes.

Resources