> For the complete documentation index, see [llms.txt](https://docs.precisiontestautomation.in/scriptlessautomation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.precisiontestautomation.in/scriptlessautomation/automation-platforms/scriptlessweb-automation/gherkin-template-for-web-automation.md).

# Gherkin Template for Web Automation

### Introduction

This documentation provides a comprehensive guide to using the Gherkin language template for web automation. Gherkin is a business-readable, domain-specific language that allows you to describe software's behaviour without detailing how that functionality is implemented. This makes it easier to communicate requirements and test scenarios between technical and non-technical stakeholders.

### Gherkin Language Basics

Gherkin syntax uses a set of special keywords to define the structure of tests. The main keywords are:

* **Feature**: Describes the feature under test.
* **Scenario**: Defines a particular scenario to be tested.
* **Given**: Sets up the initial context of the scenario.
* **When**: Describes the action that triggers the scenario.
* **Then**: Specifies the expected outcome of the scenario.
* **And**: Used to combine multiple Given, When, or Then steps.

### Template Overview

This template helps you to structure your web automation test cases using Gherkin. The template maps web automation actions and validations into Gherkin steps, ensuring clarity and consistency.

#### Key Components

* **PAGE\_NAME**: The name of the page or context.
* **WAIT\_TYPE**: The type of wait condition (e.g., visibility, presence).
* **SCROLL\_TYPE**: The type of scroll action (e.g., none, to element).
* **ELEMENT\_NAME**: The name or identifier of the web element.
* **ACTIONS**: The action to be performed (e.g., click, send keys).
* **SEND\_KEYS**: The text or keys to be sent to an element.
* **VALIDATION**: The type of validation (e.g., text, attribute).
* **VALIDATION\_TYPE**: The validation method or expected outcome.

### Gherkin Template Structure

#### General Structure

```gherkin
Feature: <Feature Name>
  <Description of the feature>

  Scenario: <Scenario Name>
    Given the user is on PAGE_NAME: "<PAGE_NAME>"
    When the user waits for WAIT_TYPE: "<WAIT_TYPE>" and scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" to perform ACTIONS: "<ACTIONS>" with data SEND_KEYS: "<SEND_KEYS>"
    Then the user waits for WAIT_TYPE: "<WAIT_TYPE>" and scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" to validate VALIDATION: "<VALIDATION>" with VALIDATION_TYPE: "<VALIDATION_TYPE>"
    Then the user waits for WAIT_TYPE: "<WAIT_TYPE>" and scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" and verifies VALIDATION_TYPE: "<VALIDATION_TYPE>"
    Then the user scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" and verifies VALIDATION_TYPE: "<VALIDATION_TYPE>"
    When the user scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" to perform ACTIONS: "<ACTIONS>" with data SEND_KEYS: "<SEND_KEYS>"
    When the user waits for WAIT_TYPE: "<WAIT_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" to perform ACTIONS: "<ACTIONS>" with data SEND_KEYS: "<SEND_KEYS>"
    When the user interacts with ELEMENT_NAME: "<ELEMENT_NAME>" to perform ACTIONS: "<ACTIONS>" with data SEND_KEYS: "<SEND_KEYS>"
    Then the user verifies ELEMENT_NAME: "<ELEMENT_NAME>" for VALIDATION_TYPE: "<VALIDATION_TYPE>"
    Then the user scrolls using SCROLL_TYPE: "<SCROLL_TYPE>" on ELEMENT_NAME: "<ELEMENT_NAME>" to validate VALIDATION: "<VALIDATION>" with VALIDATION_TYPE: "<VALIDATION_TYPE>"
    Then the user interacts with ELEMENT_NAME: "<ELEMENT_NAME>" to validate VALIDATION: "<VALIDATION>" with VALIDATION_TYPE: "<VALIDATION_TYPE>"
```

#### Handling Multiple Given Steps with PAGE\_NAME

In some scenarios, the PAGE\_NAME needs to be persistent across multiple steps until a new PAGE\_NAME is specified. The following example demonstrates how to handle multiple Given steps and ensure the PAGE\_NAME persists:

**Example with Persistent PAGE\_NAME**

```gherkin
Feature: Multi-Page Workflow
  This feature describes a workflow involving multiple pages.

  Scenario: Navigate through multiple pages
    Given the user is on PAGE_NAME: "LoginPage"
    When the user waits for WAIT_TYPE: "NONE" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "NONE" to perform ACTIONS: "LOAD_URL" with data SEND_KEYS: "https://www.loginpage.com/"
    Then the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "username" to perform ACTIONS: "SEND_KEYS" with data SEND_KEYS: "testuser"
    Given the user is on PAGE_NAME: "HomePage"
    When the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "menuButton" to perform ACTIONS: "CLICK" with data SEND_KEYS: "NONE"
    Then the user waits for WAIT_TYPE: "PRESENCE" and scrolls using SCROLL_TYPE: "TO_ELEMENT" on ELEMENT_NAME: "dashboard" and verifies VALIDATION_TYPE: "IS_PRESENT"

```

In this example:

1. **First Given Step**:

   ```gherkin
   Given the user is on PAGE_NAME: "LoginPage"
   ```

   * This step sets the PAGE\_NAME to "LoginPage".
2. **Subsequent Steps**:

   ```gherkin
   When the user waits for WAIT_TYPE: "NONE" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "NONE" to perform ACTIONS: "LOAD_URL" with data SEND_KEYS: "https://www.loginpage.com/"
   Then the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "username" to perform ACTIONS: "SEND_KEYS" with data SEND_KEYS: "testuser"
   ```

   * These steps apply to the "LoginPage".
3. **New Given Step**:

   ```gherkin
   Given the user is on PAGE_NAME: "HomePage"
   ```

   * This step updates the PAGE\_NAME to "HomePage".
4. **Remaining Steps**:

   ```gherkin
   When the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "menuButton" to perform ACTIONS: "CLICK" with data SEND_KEYS: "NONE"
   Then the user waits for WAIT_TYPE: "PRESENCE" and scrolls using SCROLL_TYPE: "TO_ELEMENT" on ELEMENT_NAME: "dashboard" and verifies VALIDATION_TYPE: "IS_PRESENT"
   ```

   * These steps apply to the "HomePage".

#### Example

Here’s how to use the Gherkin template to describe a web automation scenario for logging into Gmail and verifying the email field:

**Web Automation Template Data**

```
PAGE_NAME,WAIT_TYPE,SCROLL_TYPE,ELEMENT_NAME,ACTIONS,SEND_KEYS,VALIDATION,VALIDATION_TYPE
gmail,NONE,NONE,NONE,LOAD_URL,https://www.gmail.com/,NONE,NONE
gmail,VISIBILITY,NONE,email,SEND_KEYS,prabhatgaddam,NONE,NONE
gmail,VISIBILITY,NONE,email,NONE,NONE,NONE,ATTRIBUTE_VALUE_PRESENT
```

**Converted to Gherkin**

```gherkin
Feature: Gmail Login
  This feature allows users to log in to Gmail.

  Scenario: Load Gmail and enter email
    Given the user performs ACTIONS: "LOAD_URL" with data SEND_KEYS: "https://www.gmail.com/"
    Given the user is on PAGE_NAME: "gmail"
    Then the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "email" to perform ACTIONS: "SEND_KEYS" with data SEND_KEYS: "prabhatgaddam"
    Then the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "email" and verifies VALIDATION_TYPE: "ATTRIBUTE_VALUE_PRESENT"
```

### Additional Examples

#### Example: Adding an Item to the Cart

**Web Automation Template Data**

```csv
PAGE_NAME,WAIT_TYPE,SCROLL_TYPE,ELEMENT_NAME,ACTIONS,SEND_KEYS,VALIDATION,VALIDATION_TYPE
shoppingPage,VISIBILITY,NONE,itemButton,CLICK,NONE,NONE,NONE
shoppingPage,VISIBILITY,NONE,cart,VALIDATE,NONE,text,Item added
```

**Converted to Gherkin**

```gherkin
Feature: Shopping Cart
  This feature allows users to add items to the shopping cart.

  Scenario: Add an item to the cart
    Given the user is on PAGE_NAME: "shoppingPage"
    When the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "itemButton" to perform ACTIONS: "CLICK" with data SEND_KEYS: "NONE"
    Then the user waits for WAIT_TYPE: "VISIBILITY" and scrolls using SCROLL_TYPE: "NONE" on ELEMENT_NAME: "cart" to validate VALIDATION: "text" with VALIDATION_TYPE: "Item added"
```

### Conclusion

This documentation provides a structured approach to using Gherkin language for web automation, ensuring clear and maintainable test scenarios. By following this template, you can effectively describe and automate various web interactions in a business-readable format.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.precisiontestautomation.in/scriptlessautomation/automation-platforms/scriptlessweb-automation/gherkin-template-for-web-automation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
