top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

My Areas Of Interest in Selenium

Apr 28, 2025
4 min read






Selenium is a free, open source automation testing suite for web applications across different browsers and platforms. Though I started with no idea , but slowly I grew my interests in some areas, while I was doing my project. I would like to share some of my areas of interest.



Cucumber Gherkin Writing:




The Gherkin format, popularized by BDD (Behaviour - Driven Development) community.It is designed to improve the clarity and effectiveness of user stories. It is a structured language that uses a simple, easy-to-read syntax, predominantly based on the concept of Given-When-Then(GWT).


Example:
Feature: Guess the word
  # The first example has two steps
  Scenario: Maker starts a game
    When the Maker starts a game
    Then the Maker waits for a Breaker to join
  # The second example has three steps
  Scenario: Breaker joins a game
    Given the Maker has started a game with the word "silky"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 5 characters

Keywords:

Each line starts with the Gherkin keyword, followed by any text you like.


Primary Keywords

Secondary Keywords

Feature

“ “ (Doc Strings)

Rule

  |  (Data Tables)

Scenario/Example

            @ (Tags)

Given,When,Then,And,But

#  (Comments)

Background


Scenario Outline



Feature - It is the Name of the feature file. There should be only one feature keyword per feature file.


Feature: User Features
  Application should be tested against possible behaviors of registered users.
  Scenario: Logging in with registered user

Rule - This keyword is used to group certain scenarios having the same rule. Each rule can have its own background block.


Background:
  Given go to home page
Rule: User must be logged in
  Background:
    Given sign in with 'username' and 'password'
  Scenario: Logging out
    When click logout button on home page
    Then verify user is logged out on home page
Rule: User must be non-logged in
  Scenario: Verify non-logged in on refreshed page
    When go to home page
    Then verify user is not logged in


Scenario/Example - It is the name of the test case. It contains Given,When,Then,But, and And keywords.

Given: It describes the initial content of the system.(preconditioned)

When: It is used to declare events or actions specific to the scenario.

Then: It declares the expected result or outcome after the when step.

And and But: These are used to declare more conditions or steps. They are used more than once to increase readability.


Example:

Scenario: Signing in
  Given home page is open
  When click on sign in button
  And fill areas with 'username' and 'password'
  Then 'username' is displayed on top right corner
  But sign in button shouldn't be displayed

Scenario Outline: This is the name of the test case. This keyword is used to run a scenario with different values consecutively.Thus, enables the Data-Driven testing. It also has Given, When, Then, And, and But keywords. The keyword Examples used with Scenario Outline to specify the values to be replaced with placeholders.


Scenario Outline: Shop cart item removal
  Given there are  items in the cart
  When I remove  items from the cart
  Then verify  items left in the cart
  Examples:
    | start | remove | left |
    |    12 |   5    |    7 |
    |    20 |   5    |   15 |



Step Definitions:


What are Step Definitions?

Step Definitions connect Gherkin steps to programming code. A step definition carries out the action that should be performed by the step. So step definitions hard-wire the specification to the implementation.



Example:




TestNG Dynamic Data-Provider:




What is a Data-Provider?Why do we need to use a dataprovider?

Data Provider helps with data-driven test cases that carry the same methods but can be run multiple times with different data sets. It also helps in providing complex parameters to the test methods.


Data-Driven Framework:

It stores the test data in a table or spreadsheet format. It allows automation engineers to use a single test script to execute all test data in the table. In this framework , input values are read from data files and are stored in a variable in test scripts. Data-Driven testing enables the creation of both positive and negative test cases into a single test.


TestNG Parameterization:

Parameterization is an execution strategy that runs a test case automatically multiple times with various input values. The test design provides the provision to read data from a file or database rather than hard-coded values.


Types of Parameterization:




Method 1:With the help of parameters annotation and TestNG XML file.

@Parameters({“name”, “searchKey”})


Method 2:With the help of DataProvider annotation

@DataProvider(name= “searchProvider”)


Data-Provider inTestNG:

To provide the test data, first declare a method that returns the data set in the form of a two dimensional object array Object[][].

  • The first array represents the data set, whereas the second contains the parameter values.

  • The data provider method can be in the same test class or one of its superclasses.

  • Data provider can also be provided in another class but that has to be static.

  • The method can be annotated using @DataProvider to let TestNG know it is a DataProvider method.


Example:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Chrome.ChromeDriver;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataProviderTest {
// this will take data from dataprovider which we created
@Test(dataProvider="testdata")
public void TestChrome(String uname,String password){
System.setProperty("webdriver.chrome.driver", "Path of the driver");
WebDriver driver = new ChromeDriver();
// Maximize browser
driver.manage().window().maximize();
// Load application
driver.get("https://twitter.com/login");
// clear email field
driver.findElement(By.name("session[username_or_email]")).clear();
// Enter username
driver.findElement(By.name("session[username_or_email]")).sendKeys(uname);
// Clear password field
driver.findElement(By.name("session[password]")).clear();
// Enter password
driver.findElement(By.name("session[password]")).sendKeys(password);
}
@DataProvider(name="testdata")
public Object[][] TestDataFeed(){
// Create object array with 2 rows and 2 column- first parameter is row and second is //column
Object [][] tdata=new Object[2][2];
// Enter data to row 0 column 0
tdata[0][0]="username1@gmail.com";
// Enter data to row 0 column 1
tdata[0][1]="Password1";
// Enter data to row 1 column 0
tdata[1][0]="username2@gmail.com";
// Enter data to row 1 column 0
tdata[1][1]="Password2";
// return arrayobject to testscript
return tdata;
}
}

The above are my areas of interest in learning Selenium. Even though I started with no idea, it took me to the interesting world of coding. Now I feel more confident in writing and understanding Programming Language. Looking forward with very good opportunity to work more on Selenium testing .

 
 

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page