vendredi 27 janvier 2017

Generate dynamic tests based on a parameter in Nightwatch

I'm using NightwatchJS to automate the test on our reporting website.

This is my actual code:

module.exports = {
  '@tags': ['Report 1','base','full'],
  'Report 1' : function (browser) {
    checkAnalisi(browser, 'report1', 1, 2015, '767.507')
  }
};

function checkAnalisi(browser, nomeAnalisi, scheda, year, risultatoAtteso){
  return browser
      .url('http://ift.tt/2kCujzy' + nomeAnalisi)
      .waitForElementVisible('body', 5000)
      .selectScheda(scheda-1) //Seleziona la scheda (0-based)
      .selectPromptValue('Year', year)
      .selectRappresentazione('Table')
      .waitForElementVisible('table', 5000, true)
      .assert.containsText('table tr:last-child td:last-child', risultatoAtteso)
      .end();
}

I made some helper commands to select different things in the page:

.selectScheda(scheda-1) .selectPromptValue('Year', year) .selectRappresentazione('Table')

selectPromptValue wants a prompt name and the value to set it in the page.

For now the function only sets the year parameter but in my reports I also have different parameters.

What I want to do is to pass an object to the checkAnalisi function to dynamically generate test. For example if I want to set different prompt values I want to pass something like [['Year', 2015],['Another prompt','another value']] and the checkAnalisi function should add 2 .selectPromptValue steps with the respective values.

Is it possible to cycle an input array in my function to add more steps?

Aucun commentaire:

Enregistrer un commentaire