mardi 1 septembre 2015

How to Click link in phpunit testing with Symfony 2

I am new in PHPUnit Testing with Symfony 2. I am trying to click a link to and test whether its redirects to the page which contains some text. My code is :

$client = static::createClient();

$crawler = $client->request('GET', '/Site');

$link = $crawler->filter('a:contains("Click for Report")')->eq(1)->link();

$crawler->$client->click($link);

$this->assertEquals(200, $client->getResponse()->getStatusCode());

$this->assertContains('Detail Report',$client->getResponse()->getContent());

Every time I run this test an error says: "InvalidArgumentException: The current node list is empty." on the code >> $link = $crawler->filter('a:contains("Detail Report")')->eq(1)->link();

I don't know why the node is empty.

Any help will be highly Appreciated ! Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire