· projects  · 2 min read

Getting started with Selenium

Learn how to get started using Selenium using a proven framework.

Learn how to get started using Selenium using a proven framework.

As a regular user on StackOverflow and one of the top answerers for Selenium, one of the most frequent issues I notice on the questions, is that people do not know how to get started with using Selenium.

First let’s discuss what selenium is. Directly from the Selenium website,

Selenium automates browsers. That’s it!

This being said, Selenium is designed in particular for testers and other automation experts that want to automate some website.

So what about getting started?

As I said previously, not a lot of people are aware on how to get started, so I’ve actually designed a framework particularly for those users not sure where to start. Now you can use the base Selenium API, sure. but why not use a proven solution in automation?

The Getting Started with Selenium framework was designed for users wanting to get started with selenium, and have an easy and effective method of doing so.

This framework provides a few effective modern web testing techniques including fluent interfaces.

The framework was designed to be simple and intuitive:

package com.company.seleniumframework.functional;

import com.company.seleniumframework.AutomationTest;
import com.company.seleniumframework.Browser;
import com.company.seleniumframework.Config;
import org.junit.Test;
import org.openqa.selenium.By;

@Config(url="https://collaboration.skype.com/promotion/?cm_mmc=AFCJ%7C1250_B1-_-11129583-1225267", browser= Browser.CHROME)
public class SkypeTest extends AutomationTest {
    @Test
    public void testSkypePromotion() {
        log("Attempt: 1")
        .setText(By.name("email"), "[email protected]")
        .click(By.cssSelector("div.button > button"))

        .log("Finished.")
        ;
    }
}

We will

  1. Simply print to the output: "Attempt: 1"; then we will
  2. Set the text of an email field using the name selector strategy, to "[email protected]"
  3. We’ll then utilize CSS selectors to click some button that does something, then
  4. After the click, something will happen. We will then just simply log to the console "Finished"

This test is very easy to follow, and intuitive.

Convinced yet?

How about this one:

@Config(url="https://flipkart.com", browser=Browser.FIREFOX)
public class TestFlipKart extends AutomationTest {
    @Test
    public void testLoginLogout() {
        String username = "<username>";
        String password = "<password>";
        
        click(By.cssSelector("a[href*='/login']"))
        .setText(By.cssSelector("input[name='email']"), username)
        .setText(By.cssSelector("input[name='password']"), password)
        .click(By.cssSelector("input[type='submit'][value='Login']"))
        
        .validatePresent(By.cssSelector("li.greeting-link > a"))
        
        .hoverOver(By.cssSelector("li.greeting-link > a"))
        
        .click(By.cssSelector("ul.account-dropdown a[href*='/logout']"))
        
        // should be logged out now.
        .validatePresent(By.cssSelector("a[href*='/login']"));
    }
}

This is a simple test to automate flipkart

Here we utilize some CSS selectors and some inline validation calls. Consult the README for more information about inline validations.

I have a few people that use this framework so far as it’s a fairly new project. These people include Major League Gaming for their front-end automated regression suite!

Back to Blog