diff --git a/integrations/google_cloud/Linuxfile.sh b/integrations/google_cloud/Linuxfile.sh new file mode 100755 index 00000000000..c889897c683 --- /dev/null +++ b/integrations/google_cloud/Linuxfile.sh @@ -0,0 +1,78 @@ +# SeleniumBase Debian Linux Dependency Installation +# (Installs all required dependencies on Linux) + +# Make sure this is only run on Linux +value="$(uname)" +if [ $value == "Linux" ] +then + echo "Initializing Requirements Setup..." +else + echo "Not on a Linux machine. Exiting..." + exit +fi + +# Configure apt-get resources +sudo sh -c "echo \"deb http://packages.linuxmint.com debian import\" >> /etc/apt/sources.list" +sudo sh -c "echo \"deb http://downloads.sourceforge.net/project/ubuntuzilla/mozilla/apt all main\" >> /etc/apt/sources.list" + +# Install Xvfb (headless display system) and other dependencies +cd ~ +sudo aptitude update +sudo aptitude install -y xvfb +sudo aptitude install -y x11-xkb-utils +sudo aptitude install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic +sudo aptitude install -y xserver-xorg-core + +# Install Firefox +sudo gpg --keyserver pgp.mit.edu --recv-keys 3EE67F3D0FF405B2 +sudo gpg --export 3EE67F3D0FF405B2 > 3EE67F3D0FF405B2.gpg +sudo apt-key add ./3EE67F3D0FF405B2.gpg +sudo rm ./3EE67F3D0FF405B2.gpg +sudo apt-get update +sudo apt-get install -y python-setuptools +sudo apt-get -qy --no-install-recommends install -y firefox +sudo apt-get -qy --no-install-recommends install -y $(apt-cache depends firefox | grep Depends | sed "s/.*ends:\ //" | tr '\n' ' ') +cd /tmp +sudo wget --no-check-certificate -O firefox-esr.tar.bz2 'https://download.mozilla.org/?product=firefox-esr-latest&os=linux32&lang=en-US' +sudo tar -xjf firefox-esr.tar.bz2 -C /opt/ +sudo rm -rf /usr/bin/firefox +sudo ln -s /opt/firefox/firefox /usr/bin/firefox +sudo rm -f /tmp/firefox-esr.tar.bz2 +sudo apt-get -f install -y firefox + +# Install more dependencies +sudo apt-get update +sudo apt-get install -y xvfb +sudo apt-get install -y build-essential chrpath libssl-dev libxft-dev +sudo apt-get install -y libfreetype6 libfreetype6-dev +sudo apt-get install -y libfontconfig1 libfontconfig1-dev +sudo apt-get install -y unzip + +# Install PhantomJS +cd ~ +export PHANTOM_JS="phantomjs-1.9.8-linux-x86_64" +sudo wget https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2 +sudo tar xvjf $PHANTOM_JS.tar.bz2 +sudo mv -f $PHANTOM_JS /usr/local/share +sudo ln -sf /usr/local/share/$PHANTOM_JS/bin/phantomjs /usr/local/bin + +# Install Chrome +cd /tmp +sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +sudo apt-get -f install -y +sudo dpkg -i google-chrome-stable_current_amd64.deb + +# Install Chromedriver +sudo wget -N http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip -P ~/Downloads +sudo unzip -o ~/Downloads/chromedriver_linux64.zip -d ~/Downloads +sudo chmod +x ~/Downloads/chromedriver +sudo rm -f /usr/local/share/chromedriver +sudo rm -f /usr/local/bin/chromedriver +sudo rm -f /usr/bin/chromedriver +sudo mv -f ~/Downloads/chromedriver /usr/local/share/chromedriver +sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver +sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver + +# Other Dependencies +sudo apt-get -f install -y +sudo easy_install pip diff --git a/integrations/google_cloud/ReadMe.md b/integrations/google_cloud/ReadMe.md new file mode 100755 index 00000000000..3e0485eb306 --- /dev/null +++ b/integrations/google_cloud/ReadMe.md @@ -0,0 +1,118 @@ +## Google Cloud setup instructions for SeleniumBase (using Jenkins) + +#### 1. Go to the Google Cloud Launcher + +Navigate to [https://console.cloud.google.com/launcher](https://console.cloud.google.com/launcher) +(If you already have an active Google Cloud project, Google Cloud Lanucher will probably default to using that) + +#### 2. Launch a Jenkins Instance + +Under "Featured Solutions", Click on "Jenkins" +Click on "Launch on Compute Engine" +Give the instance a name +Give the instance a zone +Click "Create" + +#### 3. Connect with your new Jenkins instance + +SSH into your new instance by selecting: "SSH" => "Open in browser window" from the instance page. + +#### 4. Clone the SeleniumBase repository from the root ("/") directory. + +```bash +cd / +sudo git clone https://github.com/mdmintz/SeleniumBase.git +``` + +#### 5. Enter the "google_cloud" folder + +```bash +cd SeleniumBase/integrations/google_cloud/ +``` + +#### 6. Give Jenkins (aka "tomcat" user) sudo access + +```bash +./jenkins_permissions.sh +``` + +#### 7. Become "tomcat" (the Jenkins user) and enter a "bash" shell + +```bash +sudo su tomcat +bash +``` + +#### 8. Install dependencies + +```bash +./Linuxfile.sh +``` + +#### 9. Start up the headless browser display mechanism (Xvfb) + +```bash +./Xvfb_launcher.sh +``` + +#### 10. Go to the SeleniumBase directory + +```bash +cd /SeleniumBase +``` + +#### 11. Install the requirements for SeleniumBase + +```bash +sudo pip install -r requirements.txt +``` + +#### 12. Install SeleniumBase + +```bash +sudo python setup.py install +``` + +#### 13. Run an example test in Chrome to make sure everything's working properly + +```bash +nosetests examples/my_first_test.py --with-selenium --headless --browser=chrome +``` + +#### 14. You can also verify that Firefox works too + +```bash +nosetests examples/my_first_test.py --with-selenium --headless --browser=firefox +``` + +#### 15. Login to Jenkins + +(The url, as well as username and password, should be accessible from your Google Cloud Platform VM instance page.) + +#### 16. Create a Jenkins job + +Click on "New Item" +Give your new Jenkins job a name (ex: "First_Test") +Select "Freestyle project" +Click "OK" + +#### 17. Setup your new Jenkins job + +Click on the dropdown "Add build step", then select "Execute shell". +For the "Command", put: +```bash +cd /SeleniumBase +nosetests examples/my_first_test.py --with-selenium --headless --browser=chrome +``` +Click "Save" when you're done. + +#### 18. Run your new Jenkins job + +Click on "Build Now" +(If all the setup was done correctly, you should see a blue dot appear after a few seconds, indicating that the test job passed.) + +#### 19. Future Work + +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". + +#### Congratulations! You're now well on your way to becoming a build & release / automation engineer! diff --git a/integrations/google_cloud/Xvfb_launcher.sh b/integrations/google_cloud/Xvfb_launcher.sh new file mode 100755 index 00000000000..48d1208f01e --- /dev/null +++ b/integrations/google_cloud/Xvfb_launcher.sh @@ -0,0 +1,5 @@ +# Activate Headless Display (Xvfb) + +sudo Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 & +export DISPLAY=:99 +exec "$@" diff --git a/integrations/google_cloud/jenkins_permissions.sh b/integrations/google_cloud/jenkins_permissions.sh new file mode 100644 index 00000000000..9316219b9ff --- /dev/null +++ b/integrations/google_cloud/jenkins_permissions.sh @@ -0,0 +1,10 @@ +# This file will add "tomcat" to the sudoers file. +# "tomcat" is the Jenkins user name by default + +# To become tomcat from a different user, use the following: +# sudo su tomcat +# bash + +sudo sh -c "echo \"%tomcat ALL=(ALL:ALL) ALL\" >> /etc/sudoers" +sudo sh -c "echo \"%tomcat ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers" +sudo sh -c "echo \"tomcat ALL=NOPASSWD: ALL\" >> /etc/sudoers"