Estoy tratando de ejecutar un escenario agrupando mis pasos repetitivos en un fondo de pepino. Estoy usando una hoja de Excel para proporcionar el nombre de usuario y la contraseña, ya que no quiero codificarlo en el archivo de funciones.
pero al ejecutar su golpe "Error de tipo: no se pueden leer las propiedades de undefined (leyendo 'v')"
Sin embargo, si elimino el fondo y pongo todo en el escenario y lo ejecuto, entonces funciona bien.
¿Alguien puede ayudarme en lo que me estoy perdiendo aquí?
archivo de características
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 y B2 son celdas de hoja de Excel)
Definición de paso
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) });y aquí mi función común donde escribí la lógica de alimentación de datos de 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; }Debe verificar el valor en estas funciones. Debe tomar valores válidos como 'A3' para correo electrónico y 'B2' para contraseña
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) }); 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; }