minkphp / MinkZombieDriver

Zombie.js driver for Mink framework
41 stars 49 forks source link

Failing "Basic\ContentTest::testHtmlDecodingNotPerformed" test #108

Closed aik099 closed 10 years ago

aik099 commented 10 years ago

I've tried to run tests against latest Zombie 2.0.1 and I've got only 1 failed test:

1) Behat\Mink\Tests\Driver\Basic\ContentTest::testHtmlDecodingNotPerformed
Behat\Mink\Exception\DriverException: Error "Cannot call method 'toLowerCase' of null" while executing code: var node = pointers[1],
    tagName = node.tagName.toLowerCase(),
    value = null;
if (tagName == "input") {
  var type = node.getAttribute('type').toLowerCase();
  if (type == "checkbox") {
    value = node.checked ? node.value : null;
  } else if (type == "radio") {
    if (node.checked) {
      value = node.value;
    } else {
      var name = node.getAttribute('name');
      if (name) {
        var formElements = node.form.elements,
            element;
        for (var i = 0; i < formElements.length; i++) {
          element = formElements[i];
          if (element.type == 'radio' && element.getAttribute('name') === name && element.checked) {
            value = element.value;
            break;
          }
        }
      }
    }
  } else {
    value = node.value;
  }
} else if (tagName == "textarea") {
  value = node.value;
} else if (tagName == "select") {
  if (node.getAttribute('multiple')) {
    value = [];
    for (var i = 0; i < node.options.length; i++) {
      if (node.options[ i ].selected) {
        value.push(node.options[ i ].value);
      }
    }
  } else {
    var idx = node.selectedIndex;
    if (idx >= 0) {
      value = node.options.item(idx).value;
    } else {
      value = null;
    }
  }
} else {
  value = node.value;
}
stream.end(JSON.stringify(value));

.../src/Behat/Mink/Driver/NodeJS/Server/ZombieServer.php:44
.../src/Behat/Mink/Driver/NodeJS/Server.php:366
.../src/Behat/Mink/Driver/ZombieDriver.php:467
.../vendor/behat/mink/src/Behat/Mink/Element/NodeElement.php:91
.../vendor/behat/mink/driver-testsuite/tests/Basic/ContentTest.php:72
aik099 commented 10 years ago

From the error itself looks like something wasn't found on a page and we try to lowercase it's tagName.

aik099 commented 10 years ago

I've restarted the build to use Zombie 2.0.1 to demonstrate that all errors but this one were fixed: https://travis-ci.org/Behat/MinkZombieDriver/jobs/33988060

aik099 commented 10 years ago

I've figured out why it's crashing and it's funny. The line in question in the driver is var type = node.getAttribute('type').toLowerCase(); (see https://github.com/Behat/MinkZombieDriver/blob/master/src/Behat/Mink/Driver/ZombieDriver.php#L420) which lowercases type attribute value. Problem comes in when node doesn't have the type attribute and Zombie returns null and in JavaScript NULL doesn't have any methods.

Test fixture code is: <input value="&amp;"/> (see https://github.com/Behat/Mink/blob/master/driver-testsuite/web-fixtures/html_decoding.html#L11).

@stof what way we should go:

  1. add type attribute to fixture file if it's required for all input HTML tags
  2. add protection against missing type attribute to be considered as having text value in it
stof commented 10 years ago

We should be using node.type to get the type of an input instead, which already handle the fallback to text