Selenium Development in the Cloud

The cloud is a fairly ambiguous term these days with every product and sales presentation is talking about how they are forward thinking and in the cloud. With all of the talk about the cloud there is still the counter point that most of the development is still done on locally on their desktops or laptops. There is a bonus with working locally as the feedback loop is as short as it can possibly be. Travelling though with laptops can get tiring though, which begs the question is there a better way to develop?

Options for Remote Development

I believe there is, not necessarily better, an alternative way to develop and that is developing in the cloud. Now how do those two play together in a way that you benefit the most from. Now there are a few options which I will outline below with what I think is the best alternative.

Remote Access

There is the easiest solution by far as you still use the your setup that you remote into. The downside is that it is quite cpu and battery intensive to run since the entire screen will need to be rendering the entire screen.

Automatic Deploys

This may be possible depending on your setup that once you send code in to repository that your project can be built and deployed according to a pre-configured setup. I have this currently setup for maintaining this site, please see this post for further details on this setup.

Cloud Development

This is option that I believe will grow very soon as not just an option but as a standard development process that will be adopted soon. The service is called Cloud 9. It is a service that allows you to have an IDE in the cloud. I want to go into more detail with you. There is this service called Cloud 9 with is an entire IDE based in the cloud. An entire IDE based in the cloud? Yes and how they do it is absolutely fascinating.

Introducing Cloud 9

What you actually get is a virtual machine that is a blank slate. They integrate directly with you GitHub or BitBucket repository so you can work locally when needed and then use their service when you are roaming. Now how you develop is different than just remoting in to a machine because they provide a web application that is based on NodeJS. This is where it gets interesting it a full IDE that support a bunch of languages. Now no development environment is not is not complete without terminal access which they do provide to you.

Since it is a web application that is the IDE you can actually develop on your choice of machine. If you want to get crazy here you can develop on a ChromeBook or even a tablet.

Shocking, I know. The idea of using a cheap almost throwaway computer that can do almost any type of development is amazing. You dont need to have a beefy machine that you carry with you everywhere.

Secondly, since your development environment is in the cloud you will have the same setup no matter how you access it as it runs currently on the Google Cloud Platform. There is another option that I will explore in detail which is the ability of using the Cloud 9 IDE to SSH into your development machine so that you can have the power of your workstation available from anywhere.

Upcoming Potential Features

Amazon Web Services just recently bought Cloud 9, so that means that all of these features will be brought into the AWS environment so this may soon become not just the standardized system for AWS Development but it may become the best practice way to develop on AWS.

This is the biggest reason why I see this becoming a standard way of development as all of the AWS infrastructure tools may be brought in.

How do I set this up?

Cloud 9 was mainly built for web development so there is a bonus feature built-in, which is integration with Sauce Labs. This integration allows for previewing your application or site without even leaving the one browser tab. That is just about the fastest feedback you can get. No need to switch apps.

First get yourself a Cloud 9 account. Bonus if you use your GitHub or BitBucket login then you are connected to your repositories. If you use your Google account then you will still need to connect to your repositories.

The pricing plans that are available for Cloud 9 increase the performance of the virtual machine and unlocks an unlimited number of spaces. They have a great write up on why they made that decision located [insert link] here.

Once you are connected to your repository you can just open up the repo and the Cloud 9 IDE will load up with your code.

Where to Start with Python Testing

For this example I am going to use python, mainly just to mix things up. Also this will be a bit of a different setup but I think it works quite will with running Selenium tests on Sauce Labs. Once the VM is initialized then the editor window opens up and then the development can start.

Cloud 9 does provide more integration with Node JS so I will do another write-up on how to use Cloud 9 as a full development and testing platform.

#!/usr/bin/env python3

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import logging
from sauceclient import SauceClient
from config import settings

logging.basicConfig(filename="log.txt", level=logging.INFO)

class PythonSeleniumExample(unittest.TestCase):

    def setUp(self):
        self.driver  = webdriver.Remote(
		command_executor="http://%s:%s@ondemand.saucelabs.com/wd/hub" % (settings["sauce"]["user"], settings["sauce"]["pass"]),
		desired_capabilities={
            "browserName": "firefox",
            "version": "45",
            "video": "True",
            "platform": "VISTA",
        })
        self.driver.implicitly_wait(30)
        self.driver.maximize_window()
        self.sauce_client = SauceClient(settings["sauce"]["user"], settings["sauce"]["pass"])
		   
    def test_webdriver_search(self):
        try:
           driver = self.driver
           driver.get("http://www.google.com")
           elem = driver.find_element_by_name("q")
           elem.send_keys("webdriver")
           elem.send_keys(Keys.RETURN)
           self.sauce_client.jobs.update_job(driver.session_id, passed=True) 
        except Error as e:
           self.sauce_client.jobs.update_job(driver.session_id, passed=False)

    def tearDown(self):
        self.driver.quit()

if __name__ == "__main__":
    unittest.main()

settings[“sauce”][“user”]

You are probably wondering what that command is. That is where I have the settings file being parsed and available to me as set of nested arrays. the file it self is simple:

sauce:
  user: [your_sauce_username]
  pass: [your_sauce_passkey]

I know that still does not explain how that works so here is the config.py that parses that config file and makes it available to use.

import yaml

with open("settings.yaml", "r") as f:
    settings = yaml.load(f)

Now What?

With that as a backbone you can now setup your own test suite with python on the cloud. You want more? Follow me in this post series as we will go on to lookup full web development in this environment and utilize the preview feature that is powered by Sauce Labs and then we will continue on to connect the Cloud 9 web interface to you own local environment.

Andrew Krug's Picture

About Andrew Krug

Automation consultant helping you deliver greatness effectively.

New York, USA http://andrewmkrug.com

Comments