Building a browser-based test automation server on the Google Cloud Platform by using SeleniumBase
(This tutorial, from a previous Google Cloud Meetup, will teach you how to setup a Linux server for running automated browser tests. The cost of running this server is about $13.60/month on Google Cloud (enough to handle 5 parallel tests). This is less expensive than using other platforms.)
(SeleniumBase Google Cloud Video)
- Navigate to https://console.cloud.google.com/launcher
- (If you already have an active Google Cloud project, the Google Cloud Launcher will probably default to using that. If you don't, sign up for the free trial of Google Cloud Platform here to get started.)
- Under "Cloud Launcher", Click on "Jenkins Certified by Bitnami"
- Click on "Launch on Compute Engine"
- Give the instance a name
- Give the instance a zone
- Click "Create"
- SSH into your new instance by selecting: "SSH" => "Open in browser window" from the instance page.
cd /
sudo git clone https://github.com/seleniumbase/SeleniumBase.git
cd SeleniumBase/integrations/linux/
Step 6. Give Jenkins (aka "tomcat" user) sudo access (See tomcat_permissions.sh for details)
./tomcat_permissions.sh
sudo su tomcat
bash
Step 8. Install dependencies (See Linuxfile.sh for details)
./Linuxfile.sh
Step 9. Start up the headless browser display mechanism: Xvfb (See Xvfb_launcher.sh for details)
./Xvfb_launcher.sh
cd /SeleniumBase
Step 11. Install the requirements for SeleniumBase
sudo pip install -r requirements.txt --upgrade
sudo python setup.py develop
Step 13. Run an example test on Chrome to verify installation (May take up to 10 seconds)
pytest examples/my_first_test.py --headless
nosetests examples/my_first_test.py --headless
pytest examples/my_first_test.py --headless --browser=firefox
- (The url, as well as username and password, should be accessible from your Google Cloud Platform VM instance page.)
- Click on "New Item"
- Give your new Jenkins job a name (ex: "My_First_Test")
- Select "Freestyle project"
- Click "OK"
- Under "Source Code Management", select "Git".
- For the "Repository URL", put:
https://github.com/seleniumbase/SeleniumBase.git
. (You'll eventually be using your own clone of the repository here.) - Under "Build", click the "Add build step" dropdown and then select "Execute shell".
- For the "Command", put:
pytest examples/my_first_test.py --headless
- Click "Save" when you're done.
- 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.)
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 then 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". You can also use MySQL to save test results in the DB so that you can query the data at any time.
- Under "Featured Solutions", Click on "MySQL"
- Click on "Launch on Compute Engine"
- Give the instance a name
- Give the instance a zone
- Click "Create"
- Under the Google Cloud Platform menu, go to "Compute Engine"
- Find your new MySQL instance and then write down the value written in the "External IP" section.
- Under the Google Cloud Platform menu, go to "Deployment Manager"
- Find your new MySQL instance and then click on it.
- Write down the values for Admin username and password. (Username should be "root")
- You can download MySQL Workbench for this.
- Use the MySQL DB credentials that you saved in Step 21 for this.
- You can name your database/schema
test_db
.
- Run the create_db_tables.sql script in your MySQL database/schema to create all the required DB tables.
- Update the MySQL connection details in your settings.py file to use the credentials that you saved in Step 21.
- For the "Execute shell", use the following as your updated "Command":
pytest examples/test_suite.py --headless --with-db_reporting
- Click "Save" when you're done.
- Click on "Build Now"
- If all goes well, you should be seeing new rows appear in your MySQL DB tables.