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