Skip to content

Commit 8d119a9

Browse files
committed
Merge pull request #8 from mdmintz/google-cloud-jenkins-support
Add Google Cloud Jenkins integration
2 parents 5e50e50 + aa971ed commit 8d119a9

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# SeleniumBase Debian Linux Dependency Installation
2+
# (Installs all required dependencies on Linux)
3+
4+
# Make sure this is only run on Linux
5+
value="$(uname)"
6+
if [ $value == "Linux" ]
7+
then
8+
echo "Initializing Requirements Setup..."
9+
else
10+
echo "Not on a Linux machine. Exiting..."
11+
exit
12+
fi
13+
14+
# Configure apt-get resources
15+
sudo sh -c "echo \"deb http://packages.linuxmint.com debian import\" >> /etc/apt/sources.list"
16+
sudo sh -c "echo \"deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main\" >> /etc/apt/sources.list"
17+
18+
# Install Xvfb (headless display system) and other dependencies
19+
cd ~
20+
sudo aptitude update
21+
sudo aptitude install -y xvfb
22+
sudo aptitude install -y x11-xkb-utils
23+
sudo aptitude install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
24+
sudo aptitude install -y xserver-xorg-core
25+
26+
# Install Firefox
27+
sudo gpg --keyserver pgp.mit.edu --recv-keys 3EE67F3D0FF405B2
28+
sudo gpg --export 3EE67F3D0FF405B2 > 3EE67F3D0FF405B2.gpg
29+
sudo apt-key add ./3EE67F3D0FF405B2.gpg
30+
sudo rm ./3EE67F3D0FF405B2.gpg
31+
sudo apt-get update
32+
sudo apt-get install -y python-setuptools
33+
sudo apt-get -qy --no-install-recommends install -y firefox
34+
sudo apt-get -qy --no-install-recommends install -y $(apt-cache depends firefox | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ')
35+
cd /tmp
36+
sudo wget --no-check-certificate -O firefox-esr.tar.bz2 'https://download.mozilla.org/?product=firefox-esr-latest&os=linux32&lang=en-US'
37+
sudo tar -xjf firefox-esr.tar.bz2 -C /opt/
38+
sudo rm -rf /usr/bin/firefox
39+
sudo ln -s /opt/firefox/firefox /usr/bin/firefox
40+
sudo rm -f /tmp/firefox-esr.tar.bz2
41+
sudo apt-get -f install -y firefox
42+
43+
# Install more dependencies
44+
sudo apt-get update
45+
sudo apt-get install -y xvfb
46+
sudo apt-get install -y build-essential chrpath libssl-dev libxft-dev
47+
sudo apt-get install -y libfreetype6 libfreetype6-dev
48+
sudo apt-get install -y libfontconfig1 libfontconfig1-dev
49+
sudo apt-get install -y unzip
50+
51+
# Install PhantomJS
52+
cd ~
53+
export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64"
54+
sudo wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
55+
sudo tar xvjf $PHANTOM_JS.tar.bz2
56+
sudo mv -f $PHANTOM_JS /usr/local/share
57+
sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin
58+
59+
# Install Chrome
60+
cd /tmp
61+
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
62+
sudo apt-get -f install -y
63+
sudo dpkg -i google-chrome-stable_current_amd64.deb
64+
65+
# Install Chromedriver
66+
sudo wget -N http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip -P ~/Downloads
67+
sudo unzip -o ~/Downloads/chromedriver_linux64.zip -d ~/Downloads
68+
sudo chmod +x ~/Downloads/chromedriver
69+
sudo rm -f /usr/local/share/chromedriver
70+
sudo rm -f /usr/local/bin/chromedriver
71+
sudo rm -f /usr/bin/chromedriver
72+
sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver
73+
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
74+
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
75+
76+
# Other Dependencies
77+
sudo apt-get -f install -y
78+
sudo easy_install pip

integrations/google_cloud/ReadMe.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
## Google Cloud setup instructions for SeleniumBase (using Jenkins)
2+
3+
#### 1. Go to the Google Cloud Launcher
4+
5+
Navigate to [https://console.cloud.google.com/launcher](https://console.cloud.google.com/launcher)
6+
(If you already have an active Google Cloud project, Google Cloud Lanucher will probably default to using that)
7+
8+
#### 2. Launch a Jenkins Instance
9+
10+
Under "Featured Solutions", Click on "Jenkins"
11+
Click on "Launch on Compute Engine"
12+
Give the instance a name
13+
Give the instance a zone
14+
Click "Create"
15+
16+
#### 3. Connect with your new Jenkins instance
17+
18+
SSH into your new instance by selecting: "SSH" => "Open in browser window" from the instance page.
19+
20+
#### 4. Clone the SeleniumBase repository from the root ("/") directory.
21+
22+
```bash
23+
cd /
24+
sudo git clone https://github.com/mdmintz/SeleniumBase.git
25+
```
26+
27+
#### 5. Enter the "google_cloud" folder
28+
29+
```bash
30+
cd SeleniumBase/integrations/google_cloud/
31+
```
32+
33+
#### 6. Give Jenkins (aka "tomcat" user) sudo access
34+
35+
```bash
36+
./jenkins_permissions.sh
37+
```
38+
39+
#### 7. Become "tomcat" (the Jenkins user) and enter a "bash" shell
40+
41+
```bash
42+
sudo su tomcat
43+
bash
44+
```
45+
46+
#### 8. Install dependencies
47+
48+
```bash
49+
./Linuxfile.sh
50+
```
51+
52+
#### 9. Start up the headless browser display mechanism (Xvfb)
53+
54+
```bash
55+
./Xvfb_launcher.sh
56+
```
57+
58+
#### 10. Go to the SeleniumBase directory
59+
60+
```bash
61+
cd /SeleniumBase
62+
```
63+
64+
#### 11. Install the requirements for SeleniumBase
65+
66+
```bash
67+
sudo pip install -r requirements.txt
68+
```
69+
70+
#### 12. Install SeleniumBase
71+
72+
```bash
73+
sudo python setup.py install
74+
```
75+
76+
#### 13. Run an example test in Chrome to make sure everything's working properly
77+
78+
```bash
79+
nosetests examples/my_first_test.py --with-selenium --headless --browser=chrome
80+
```
81+
82+
#### 14. You can also verify that Firefox works too
83+
84+
```bash
85+
nosetests examples/my_first_test.py --with-selenium --headless --browser=firefox
86+
```
87+
88+
#### 15. Login to Jenkins
89+
90+
(The url, as well as username and password, should be accessible from your Google Cloud Platform VM instance page.)
91+
92+
#### 16. Create a Jenkins job
93+
94+
Click on "New Item"
95+
Give your new Jenkins job a name (ex: "First_Test")
96+
Select "Freestyle project"
97+
Click "OK"
98+
99+
#### 17. Setup your new Jenkins job
100+
101+
Click on the dropdown "Add build step", then select "Execute shell".
102+
For the "Command", put:
103+
```bash
104+
cd /SeleniumBase
105+
nosetests examples/my_first_test.py --with-selenium --headless --browser=chrome
106+
```
107+
Click "Save" when you're done.
108+
109+
#### 18. Run your new Jenkins job
110+
111+
Click on "Build Now"
112+
(If all the setup was done correctly, you should see a blue dot appear after a few seconds, indicating that the test job passed.)
113+
114+
#### 19. Future Work
115+
116+
If you have a web application that you want to test, you'll be able to create SeleniumBase tests and add them to Jenkins as you saw here. You may want to create a Deploy job, which downloads the latest version of your repository, and then kicks off all tests to run after that. You could tell that Deploy job to auto-run whenever a change is pushed to your repository by using: "Poll SCM". All your tests would then be able to run by using: "Build after other projects are built".
117+
118+
#### Congratulations! You're now well on your way to becoming a build & release / automation engineer!
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Activate Headless Display (Xvfb)
2+
3+
sudo Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &
4+
export DISPLAY=:99
5+
exec "$@"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file will add "tomcat" to the sudoers file.
2+
# "tomcat" is the Jenkins user name by default
3+
4+
# To become tomcat from a different user, use the following:
5+
# sudo su tomcat
6+
# bash
7+
8+
sudo sh -c "echo \"%tomcat ALL=(ALL:ALL) ALL\" >> /etc/sudoers"
9+
sudo sh -c "echo \"%tomcat ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers"
10+
sudo sh -c "echo \"tomcat ALL=NOPASSWD: ALL\" >> /etc/sudoers"

0 commit comments

Comments
 (0)