Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

184
Views
How to read values from input.json file into gherkin feature file in cypress

My Feature file :

Feature: Login page

Feature Login page will work depending on the user credentials.

Background: 
    Given A user opens a saucelabs website
Scenario: Success Login 
    When A user enters the username "standard_user"
    And A user enters the password "secret_sauce"
    And A user clicks on the login button
    Then the url will contains the /inventory subdirectory

Input file :sauceCreds.json { "standardUserName":"standard_user", "systempwd":"secret_sauce", }

My class file :

class homeSaucePage{

elements = {
    usernameInput: () => cy.get('#user-name'),
    passwordInput: () => cy.get('#password'),
    loginBtn: () => cy.get('#login-button'),
    errorMessage: () => cy.get('h3[data-test="error"]')
}

typeUsername(username){
    this.elements.usernameInput().type(username);
}

typePassword(password){
    this.elements.passwordInput().type(password);
}

clickLogin(){
    this.elements.loginBtn().click();
}

}

module.exports = new homeSaucePage();

Stepdefinition file :

import {Given, When, And, Then} from 'cypress-cucumber-preprocessor/steps'
const loginPage = require('../../pages/loginPage')

beforeEach(function () {
    cy.fixture('sauceCreds').then(function (credentials) {
     this.credentials = credentials;
    })
  })

Given('A user opens a saucelabs website', () => {
     cy.visit('https://www.saucedemo.com/')
    
})
When('A user enters the username {string}', function() {
    loginPage.typeUsername(this.credentials.standardUserName)
})

I want to access the json input file from feature file and want to achieve something like this

My Feature file :

Feature: Login page

Feature Login page will work depending on the user credentials.

Background: 
    Given A user opens a saucelabs website
Scenario: Success Login 
    When A user enters the username sauceCreds.json.standard_user
    And A user enters the password sauceCreds.json.systempwd
    And A user clicks on the login button
    Then the url will contains the /inventory subdirectory
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!