How to get Sikuli working in headless mode - testing

If we have a headless test server running sikuli (both ubuntu and windows configurations needed), how to get it work without a physical monitor and preferably for as many screen resolutions as possible.

I successfully got sikuli running in headless mode (no physical monitor connected)
Ubuntu: check Xvfb.
Windows: install display driver on the machine (to be headless) from virtualbox guest additions display drivers and use TightVNC to remotely set resolution from another machine.
Detailed steps for windows 7
Assume that:
Machine A: to be headless machine, windows 7, with vnc server ready (e.g. TightVNC server installed and waiting for connections).
Machine B: will be used to remotely setup the virtual display driver on machine A.
steps:
Download virtualbox guest additions iso file on Machine A from here (for latest version check latest version here and download VBoxGuestAdditions_x.y.z.iso)
Extract iso file (possibly with winrar) into a directory (let us call it folder D)
using command prompt cd to D folder
Driver extraction
-To extract the 32-bit drivers to "C:\Drivers", do the following:
VBoxWindowsAdditions-x86 /extract /D=C:\Drivers
-For the 64-bit drivers:
VBoxWindowsAdditions-amd64 /extract /D=C:\Drivers
Goto device manager
add hardware
Restart and connect with VNC viewer, now you should be able to change screen resolution
other valuable info on launchpad.

I got SikuliX working in a true headless mode in GCE with a Windows 2016 client system. It takes some duct tape and other Rube Goldberg contraptions to work, but it can be done.
The issue is that, for GCE (and probably AWS and other cloud environment Windows clients), you don't have a virtual video adapter and display, so, unless there's an open RDP connection to the client, it doesn't have a screen, and SikuliX/OpenCV will get a 1024x768 black desktop, and fail.
So, the question is, how to create an RDP connection without having an actual screen anywhere. I did this using Xvfb (X Windows virtual frame buffer). This does require a second VM, though. Xvfb runs on Linux. The other piece of the puzzle is xfreerdp 2.0. The 2.x version is required for compatibility with recent versions of Windows. 1.x is included with some Linux distros; 2.x may need to be built from sources, depending on what flavor Linux you're using. I'm using CentOS, which did require me to build my own.
The commands to establish the headless RDP session, once the pieces are in place, look something like this:
/usr/bin/Xvfb :0 -screen 0 1920x1080x24 &
export DISPLAY=:0.0
/usr/local/bin/xfreerdp /size:1920x1080 /u:[WindowsUser] /p:"[WindowsPassword]" /v:[WindowsTarget]
In our environment we automated this as part of the build job kicked off by Jenkins. For this to work under the Jenkins slave, it was also necessary to run the Jenkins slave as a user process, rather than a service... this can be accomplished by enabling auto admin login and setting the slave launch script as a run (on logon) command.

For those looking to automate on ec2 windows machines, this worked for me: http://www.allianceglobalservices.com/blog/executing-automation-suite-on-disconnectedlocked-machines
In summary, I used RDC to connect, put the following code in a batch file on remote desktop, double clicked it, and sikulix started working remotely (kicking me out of RDC at the same time). Note that ec2 windows machines default to 1024x768 when tscon takes over which may be too small so TightVnc can be used to increase the resolution to 1280x1024 before running.
tscon.exe 0 /dest:console
tscon.exe 1 /dest:console
tscon.exe 2 /dest:console
tscon.exe 3 /dest:console
START /DC:\Sikulix /WAIT /B C:\Sikulix\runsikulix.cmd -d 3 -r C:\test.sikuli -f C:\Sikulix\log.txt -d C:\Sikulix\userlog.txt

I just figure out a way to resolve similar issue.
My env:
local: windows pc
remote (for running sikulix + app I would like to test): windows ec2 instance
My way:
1.create a .bat file, its contents:
ping 127.0.0.1 -n 15 > nul
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
cd "\path\to\sikulix"
java -jar sikulixide-2.0.5.jar -r /path/to/sikulix -c > logfile.log
prepare your app
run the bat (right click > run as administrator)
ping will give your 10s, so that you can bring your app back to front
you will be disconnnected from rdp connection
Explanation:
ping is like "sleep"
for loop: kick out current user & keep session alive

Related

install weblogic on VM with Solaris OS

I stuck in install weblogic on my vm solaris. i try that
java -d64 -jar fmw_12.2.1.3.0_wls.jar
and i got an error
Checking monitor: must be configured to display at least 256 colors. DISPLAY environment variable not set. Failed <<<<
Any solution for these error?
This happens if you want to do an graphical install of the system without having a X11 running. The error message is quite normal for such an situation.
You could:
Not running the installer in the graphical mode by doing a silent install (please refer to https://docs.oracle.com/cd/E24329_01/doc.1211/e24492/silent.htm#WLSIG131 for information)
Install the nescessary package to have an X11 and stuff running in your VM with pkg install solaris-desktop. Then execute the java command again from the GUI . This obviously only works if you can get a the graphical output of the VM for example via VNC or other tools.
You could set the DISPLAY variable to an installed X11 implementation. For example i use Xquartz on my Apple notebook. Then configure DISPLAY and XAUTHORITY correctly. Or you could simply log into the Solaris system with ssh -X . I prefer the second one, as it does everything automatically.

Run : Apache:j-meter in linuxServer as GUI or any other approach

I have apache j meter installed in my local machine which has .bat file .sh executable files in it, to run in gui mode in windows, now i want to execute it on server which is in linux environment, how can i run as gui mode in server?
Actually you should not be running JMeter in GUI mode, you should use GUI mode for tests development and/or debugging. When it comes to executing the load test itself make sure you run JMeter in command-line non-GUI mode like:
jmeter -n -t test.jmx -l result.jtl
In regards to how you can proceed there are several options:
Develop the test under Windows, transfer the .jmx file to Linux box using pscp, WinSCP, FileZilla, etc.
Develop the test under Windows and run JMeter in distributed mode, i.e. have JMeter Master on Windows and JMeter Slave on Linux, see JMeter Distributed Testing Step-by-step guide for more details
You can install X Window Server implementation on Windows box (i.e. Xming or Cygwin/X and use X forwarding so you will run JMeter on linux and see its GUI on Windows.

Connect to Docker Machine remotely in Docker Toolbox

Every time i run a docker command remotely (e.g docker-machine ssh default) I always get an error saying that default is not running although I started the docker machine manually on the Windows machine. When I run "docker-machine ls" the state is set to "Timeout" but I run it on the actually windows machine and it is "Running". Im using Docker Toolbox w/ VirtalBox on Windows 10 machine with UAC disabled. I also have a Server 2012 box that shows the same results with docker toolbox. Im running the command remotely through power shell. I installed Docker Toolbox using my local account with and without elevated permissions.
I want to be able to spin up and remove docker containers from TeamCity through the command line (Teamcity on Windows).
Thanks

Can Vagrant suffice my requirement?

I have been looking out for ways to setup an automation environment and I found this application named Vagrant. I read the docs on the site, however I wanted to know from the experts out there if Vagrant with Oracle VirtualBox would suffice my needs.
I need to have a script that will call Vagrant to initialize a VM [The VM-Image is always the same - Windows Server 2008 R2]
I need to copy some of my project related files from a shared location onto the VM
Call a Batch file that will take care of test runs for me inside the VM
Once my test run is complete, This VM needs to be self destroyed/destructed.
Also, I would like to know if the Image be a custom .ISO file?
Sounds like Vagrant and VirtualBox will work for that scenario. Also, you might find that running commands in the VM using WinRM or SSH may be the easiest way to launch tests.
If you haven't already seen it, the blog post about Windows support in Vagrant 1.6 is informative: https://www.vagrantup.com/blog/feature-preview-vagrant-1-6-windows.html
Creating a VirtualBox/Vagrant base VM from an .iso should work, and you can then do all of your work using the VM from that point onward.
To get started, you might try these steps:
Create a VirtualBox VM from your Windows .iso, using the VirtualBox GUI or cmdline tools.
Once you have the VM in the state you want it, shut it down and package it as a vagrant box - for example, on a Mac that step looks like (where Win7x64 is the dir containing the VirtualBox VM):
cd ~/VirtualBox\ VMs
vagrant package --base Win7x64 --output win7x64_base.box
Once that finishes, tell vagrant about the new base box:
vagrant box add win7x64_base /path/to/win7_base.box
Then you can vagrant init/vagrant up the VM:
mkdir win7 && cd win7
vagrant init win7x64
vagrant up
To enable SSH access, I installed Cygwin in the VM and configured sshd. So, after launching you can SSH in by running vagrant ssh
Note that if there's no Windows user in the VM named 'vagrant', you can specify the SSH username to use with vagrant ssh by placing this in your Vagrantfile:
config.ssh.username = 'user1'
As mentioned above, WinRM is also an option for remotely running commands.
And Vagrant apparently has some convenience features to make it easy to RDP into the VM, but I haven't looked at that.

How to use Selenium Grid to run some commands on the node and system commands locally

I'm trying to solve a problem and I was hoping I could do it with Selenium Grid but I'm not entirely sure that it's possible. Here's my problem...I'm developing test cases using Selenium WebDriver and I need my tests to run on a Windows machine however the AUT runs on a Linux server. I have several tools that only run on Linux and I would like to be able to run some commands/tests on the Windows machine and others in the Linux server. For instance
Test Starts -> Firefox launches (Windows machine)
Login to site (Windows machine)
Run command in Linux server
Return running commands/tests on the Windows box.
Alternatively I could figure out how to run those commands remotely from a Windows machine but I'm not looking forward to doing that.
Out of the box, you cannot use selenium to run commands on your local machine. Selenium/Webdriver is a browser testing tool and can interact only with browser.
Updated Answer based on your comments
Common part to both ways (which I think you already know)
In your java code you should have the code for webdriver/selenium commands that will do step 1 and 2. Your java code should also the contain the logic/code to execute the linux commands as step 3. Step 4 should again be your webdriver command.
This test code should run from the linux server so that the java command execution will happen in the linux box.
Now the only pending part is the execution of test in remote machine.
Method 1 without using grid
Start the selenium server in the windows machine. Point your java tests to the selenium server running in this machine. If your windows machine IP is 10.0.0.1, you should initialize the webdriver object as
WebDriver wd = new RemoteWebDriver(new URL("http://10.0.0.1:4444/wd/hub"),DesiredCapabilities.Firefox());
This will send all your webdriver commands to the selenium server running in 10.0.0.1 on port 4444. Your tests will then get executed in the windows machine. For this to work, your linux server and windows machine should be in same network.
Method 2 using grid.
Its all the same as above, but instead of giving the ip/dns name of windows machine, you should give the ip/dns name of the hub machine. You should also have windows machine registered as an RC to that hub.
I think with AutoIT kind of windows frameworks, we can invoke C:\Windows\System32\cmd.exe to open a command prompt and run some .bat files. If it is Linux /bin/csh or /bin/bash myscript.sh.