Functional Test Conditions with Intern / Leadfoot

I want to conditionally execute some commands / assertions depending on whether the previous assertions were successful or not.

I can't seem to find a way to then

nest calls or conditionally do things using the leadfoot chaining syntax.

Here is my test (returned at the end of each function due to the fact that this is compiled by coffeescript):

tdd.test(tableUrl, function() {
    this.timeout = 60000;
    return this.remote.get(require.toUrl("tests/pages/" + tableUrl))
    .setPageLoadTimeout(60000)
    .setFindTimeout(20000)
    .findByCssSelector('.dataTables_wrapper table.dataTable')
    .then(null, function(err) {
      return assert.fail('', '', 'Table should exist');
    }).then(pollUntil(function() {
      var table;
      table = document.querySelector('.dataTables_wrapper table.dataTable');
      if (table.querySelectorAll('tbody td').length > 1) {
        return true;
      } else {
        return null;
      }
    }, null, 20000, 500)).then(function() {
      console.log('Assertion succeeded: Table should have data');
      return assert.ok(true, 'Table should have data');
    }, function(err) {
      return assert.fail('', '', 'Table should have data');
    });
  });

      

When a table does not exist, both tables must exist, and "Table must have data" statements must be reported as a failure. However, only the last statement fails. When I comment out the "Table must have data" error callback, the "Table must exist" statement is reported as erroneous.

What I would like to do is

  • check if it exists table

    (via findByCssSelector).

    a) If it exists, please report that it exists and check that it has more than one item td

    . This is currently done with help pollUntil

    to ensure that the command is complete / promise is resolved as soon as more than one is found td

    , rather than waiting for the entire implicit timeout.

    b) If it does not exist, please report that it does not exist.

I can't find a way to fail the second poll error callback "The table must have data" if the first findByCssSelector

fails due to missing conditionals and only the last confirmation failure is reported in the test.

+3


source to share


1 answer


So conditional forking can happen with calls then

, this answer describes how to do conditional forking with the internet.

The problem I ran into was the pollUntil function, which does not behave the same as the normal leadfoot Command because of the function that returns a callback function that returns a promise, not just a promise .

You can work around this by wrapping it in pollUntil

an anonymous function, immediately calling the function pollUntil

using the method call

, passing the current value this

from behind then defining the callback context to the Command object, and then finally chaining another command.



This is what the above code turned into using correct conditional branching with pollUntil

.

tdd.test(tableUrl, function() {
  this.timeout = 60000;
  return this.remote.get(require.toUrl("tests/pages/" + tableUrl))
  .setPageLoadTimeout(60000)
  .setFindTimeout(5000)
  .findByCssSelector('.dataTables_wrapper table.dataTable')
  .then((function() {
    return pollUntil(function() {
      var table;
      table = document.querySelector('.dataTables_wrapper table.dataTable');
      if (table.querySelectorAll('tbody td').length > 1) {
        return true;
      } else {
        return null;
      }
    }, null, 20000, 500).call(this).then(function() {
      console.log('Assertion succeeded: Table should have data');
      return assert.ok(true, 'Table should have data');
    }, function(err) {
      return assert.fail('', '', 'Table should have data');
    });
  }), function(err) {
    return assert.fail('', '', "Table should exist. Error: " + err.name);
  });
});

      

+3


source







All Articles