Get SurfEasy VPN
SurfEasy VPN

Tutorials

Under the Hood: Web Automation at SurfEasy

Dear blog readers, we love you guys.

We love that you care about your privacy and security. We love that you tell us what you want from our service. And we especially love when you’re tech-minded, and ask us about the ins and outs of SurfEasy VPN.

It seems that you’re keen to take a peek under the hood, and we’re keen to let you look. So, from now on, we’re going to be introducing regular blog posts from our development team, so you can get a clearer view of how we do what we do, and how SurfEasy VPN works.

Hopefully we can give you some information that you can put into use in future. Knowledge is power, after all, and we want to empower you.

Without further ado, here’s Moe, our QA Engineer Lead, to explain our web automation process, and show you how to do it.

Web Automation at SurfEasy

Here at SurfEasy we are constantly looking for ways to ensure our products and services are of the highest quality for our users. Our QA team is responsible for testing all our websites and web flows, including www.surfeasy.com and accounts.surfeasy.com.

Selenium WebDriver has long been the de-facto standard for web automation, and considering the amount of support and ease of use of the tool, we decided to adopt it. While there is a lot of documentation out there, we haven’t found an article explaining a good architecture for running tests with different browsers.

This is the first part of a two part series. Overall, we’ll touch upon the following:

– Setting up an architecture to handle running tests with different browser
– Setting up Ant to build our project
– Using Ant to pass parameters to our code for specifying tests to run and/or a browser to us
– Generating XML result reports

In this post, we’ll focus on point #1 (architecture).

For our purposes, we used IntelliJ as our Java IDE. We started by creating a new project, giving it a name, and completing the rest of the setup (there are many tutorials on this so we will not go into detail). We used the Page Object Model for our overall architecture. Here’s our folder structure.

To handle running tests with different browsers, we used the factory pattern. We created a class called DriverFactory. Its responsibility is to create the driver of whatever type (browser) we’d like the tests to run with, and return it to the tests.

Here’s a test class:

public class SignInTests {

  private static WebDriver driver = DriverFactory.constructDriver();

  @BeforeClass
  public static void beforeClass() {}

  @Test
  public void registerAccountSuccessfully() {}
  
}

Here’s the DriverFactory class:

public class DriverFactory {

  public static WebDriver constructDriver() {
    if(System.getProperty("browsername") != null) {
      String browser = System.getProperty("browsername");
      if (browser.toLowerCase().equals("firefox")) {
        return new Firefox().setDriver();
      }
      else if(browser.toLowerCase().equals("chrome")) {
        return new Chrome().setDriver();
      }
      // Add more browsers here
    }
    return new Firefox().setDriver();
  }

}

Finally, here’s one of the browser classes:

public class Firefox {

  public WebDriver setDriver() {
    // Using new Firefox WebDriver based off of marionette
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability("marionette", true);
    WebDriver driver = new FirefoxDriver(capabilities);

    return driver;
  }
  
}

The key idea is the following:

—Test uses DriverFactory to create a WebDriver

—DriverFactory determines what browser we want to generate (from system property ‘browsername’)

—DriverFactory returns an instance of a driver of type Firefox, Chrome, etc.

These are the basics of our web automation, but later in the week we’ll go into more detail about how to use Ant to run tests with a specific browser and generate XML result files through command line or Mac terminal.

See you then!

About Us

SurfEasy is a VPN tool that protects your online privacy and unblocks the internet. Use it on your Mac, PC, iPhone, iPad or Android.

Learn More
Continue Reading
To Top