Skip to content

Instantly share code, notes, and snippets.

@stenver
Created September 9, 2014 17:01
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save stenver/337aea741fe7d70ce703 to your computer and use it in GitHub Desktop.
Save stenver/337aea741fe7d70ce703 to your computer and use it in GitHub Desktop.
How to set up windows machine for selenium and jenkins
# Setting up internet explorer machine with selenium
Download the machine with appropriate windows and IE from microsoft
https://www.modern.ie/en-us/virtualization-tools
Boot it up with GUI
Disable UAC and firewall - its an isolated machine that noone will access anyway(and if they do, theres really nothing there), so why bother
# Copssh
Download and install copssh. This tool will easily allow you to ssh into the machine
in Copssh control panel open the "Users" tab and add the current user to there as(eg. "ie10win7\ieuser") and some public key to that you use for logging in
# Java
Download and install java and add java to windows PATH
# Selenium
Download selenium stand alone server and IEDriver
Put the files to C:\selenium
Add C:\selenium to windows PATH
Create a .bat file to the selenium folder. Inside the bat file, paste this:
```
java.exe -jar C:\selenium\selenium-server-standalone-2.42.2.jar -browser "browserName=internet explorer,maxinstance=1,platform=WINDOWS" -Dwebdriver.ie.driver="C:/selenium/IEDriverServer.exe" -timeout 120 -browserTimeout 120
```
# Set up jenkins slave
Create a JNLP slave in CI and set up a scheduled slave agent on windows boot
https://wiki.jenkins-ci.org/display/JENKINS/Launch+Java+Web+Start+slave+agent+via+Windows+Scheduler
To make it comfortable, i suggest keeping the slave.jar in C:\selenium. Then Everything regarding selenium is in 1 folder
# Setting up Internet Explorer
Open IE and then choose "Dont use the recommended settings". Open internet options and make sure that
a) Set the Protected Mode settings for each zone to be the same value. The value can be on or off(RECOMMENDED), as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab.
b) Pop ups are blocked
c) On IE 10 and higher Enhanced Protected Mode must be disabled
# Download and install ultravnc
You should always use VNC, when possible, to log in to a windows machine. If you use RDP, then once you close the session, it locks it and you cant see any screenshots. Also, windows lose their focus. We will also create local vnc session, to keep user session open.
http://www.uvnc.com/component/jdownloads/finish/4-setup/86-ultravncw321201setup/0.html
Make sure you install the server as service and to log on at the startup
The VNC and view-only passwords can be the same, e.g. vagrant
Try to connect with the ultraVNC viewer to ```localhost``` make sure that the server works. Then try to connect from another computer. You may need to restart the service, or in a worse case, virtual machine for it to work.
You should now set up a local vnc viewer connection, so when tests run, the windows will always think there is an actual graphical session going on and doesnt time out Internet Explorer for whatever reason(Maybe because it thinks its a background process?)
Donwload nircmd and extract it to C:\selenium
Create a ```vnc.bat``` file to C:\selenium and copy-paste this inside it(chaning password to whatever you chose):
```
ping -n 9 127.0.0.1 >nul # Wait for vnc service to become online
start "" "C:\Program Files\uvnc bvba\UltraVNC\vncviewer.exe" -connect localhost -password vagrant
ping -n 5 127.0.0.1 >nul # Wait for vnc viewer to load itself
cd C:\selenium
nircmd.exe sendkeypress rwin+D # Minimize all windows
```
Now create a shortcut of this script, change the shortcut properties to it would start minimized and put it to the windows startup folder. This makes sure the script is run every time windows starts.
# Make it into vagrant box
Shutdown the machine and go to the linux machine where vagrant is installed.
List all the running vms you have and find you windows machine name
vboxmanage list vms
Run the command(https://docs.vagrantup.com/v2/cli/package.html)
vagrant package --base TheWindowsMachineName --output YourNameBoxName.box
# Set up a new instance of the machine
Go to some folder you would like the new machine and run the following:
vagrant init myBoxName
Change the vagrant file to include the following:
```
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "win7ie10"
config.vm.network :public_network, ip: "192.168.5.4", bride: 'th0'
config.ssh.username = "ieuser"
config.vm.provider "virtualbox" do |v|
v.memory = 1024
end
end
```
Run the command
```vagrant up```
You can now get into the machine with the command
```vagrant ssh```
Then you can get the machine ip, to log in with remote desktop using the command
```ipconfig```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment