1

I am using behat with a zombie driver to test my application. Now I am trying to click on an element (a td), to fire an ajax request. But when clicking this element I receive the error:

Error while processing event 'click' (Behat\Mink\Exception\DriverException

The code I use is from this thread

Nowhere on the internet I can find someone with the same error message, so I have no clue how to solve this.

The HTML I want to click on looks like this:

<td value="2" onclick="switchStatus(this.id); updateScores();; return false;" id="37_12_2">2</td>

These javascript functions do an ajax call to the server and do nothing with the saved result (no success method).

The test function I use looks like this:

/**
 * @Given /^I click td "([^"]*)"$/
 */
public function iClickTd($id)
{
    $locator = "#$id";
    $element = $this->getSession()->getPage()->find('css', $locator);

    if (null === $element) {
        throw new \InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $locator));
    }

    $element->click();
    $this->getSession()->wait(1000);
}

And in the test I have:

And I click td "37_12_2"

The behat.yml:

default:
  suites:
    default:
      contexts:
        - FeatureContext:
          - http://localhost/
  extensions:
    Behat\MinkExtension\ServiceContainer\MinkExtension:
      base_url: http://localhost/
      sessions:
        default:
          goutte: ~
        javascript:
          zombie:
            node_modules_path: '/usr/lib/node_modules/'

Used versions:

  • "phpunit/phpunit": "4.5.*",
  • "phpspec/phpspec": "~2.1",
  • "behat/behat": "~3.0",
  • "behat/mink": "~1.6",
  • "behat/mink-extension": "~2.0",
  • "behat/mink-goutte-driver": "*",
  • "behat/mink-zombie-driver": "~1.2"
  • npm v1.4.28
  • php 5.6

Does anyone know what goes wrong, and how I can make this function work?

Community
  • 1
  • 1
Jetse
  • 1,706
  • 2
  • 16
  • 22

1 Answers1

1

The actual problem was a wrong ajax request. Using a real webbroser the ajax call went right, but using zombieJS this call went to a wrong url.

When someone else has the same exception, you can view your real problem by changing the following part in the ZombieDriver.php: From:

$out = $this->server->evalJS($js);
    if (!empty($out)) {
        throw new DriverException(sprintf("Error while processing event '%s'", $event));
    }

To:

$out = $this->server->evalJS($js);
    if (!empty($out)) {
        echo $out;
        throw new DriverException(sprintf("Error while processing event '%s'", $event));
    }

$out contains the actual error message of an ajax call.

Jetse
  • 1,706
  • 2
  • 16
  • 22