Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
TypeError: Cannot read properties of undefined (reading 'v')

I am trying to run a scenario by grouping my repetitive steps in cucumber background. I am using an excel sheet to give username and password as i don't want to hardcode it in feature file.

but while executing its hitting "TypeError: Cannot read properties of undefined (reading 'v')"

However if I remove the background and put everything in the scenario and run then it works fine.

Can anybody help me what I am missing here.

Feature file

Feature:  UI Testing

  Background: User log-in
  Given I am on the login page
  When I enter <email>
  When I enter <password>
  When  I click on sign in button
  Then  I should see home page

  Scenario: Create template 1
    When I Click on the templates-1
    When I fill in the required details and <desc> click create
    Then I validate template is created successfully
    Then I should click sign out button
    Examples:
      |email|password|desc|
      |A3|B2|testing|

  Scenario: Create template 2
    When I Click on the templates-2
    When I fill in the required details and <desc> click create
    Then I validate template is created successfully
    Then I should click sign out button
    Examples:
      |email|password|desc|
      |A3|B2|testing|

(A3 and B2 are cells of excel sheet)

Step Def

Given(/^I am on the login home page$/, function () {
    loginPage.openPage()
});
When(/^I enter email (.+)$/, async(email) => {
    var excelvalue = common.readExcelData(email);
    await mazeHome.username(excelvalue)
});
When(/^I enter password (.+)$/, async(password) => {
    var excelvalue = common.readExcelData(password);
    await mazeHome.password(excelvalue)
});

and here my common function where i wrote the logic of feeding data from excel.

const { default: ChromeDriverService } = require("wdio-chromedriver-service");
var XLSX = require('xlsx');

class commonFunctions  {

     readExcelData(cellnumber) {

        var workbook = XLSX.readFile('./testData.xlsx');
        var worksheet = workbook.Sheets['Sheet1'];
        var celldata = worksheet[cellnumber].v;
        return celldata;
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should check the value in these functions. It should take valid values like 'A3' for email and 'B2' for password

When(/^I enter email (.+)$/, async(email) => {
    console.log(1,email);
    var excelvalue = common.readExcelData(email);
    await mazeHome.username(excelvalue)
});
When(/^I enter password (.+)$/, async(password) => {
    console.log(2,password);
    var excelvalue = common.readExcelData(password);
    await mazeHome.password(excelvalue)
});
And you should handle not found call on readexcel function

  readExcelData(cellnumber) {
        var workbook = XLSX.readFile('./testData.xlsx');
        var worksheet = workbook.Sheets['Sheet1'];
        if(!worksheet[cellnumber]){
          // handle not found cell
          return null;
        }

        var celldata = worksheet[cellnumber].v;
        return celldata;
    }

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda