I'm writing some functionality tests using Codeception and the PHPBrowser webdriver.
Codeception uses specific references in CSS or XPath to check elements on a page.
But I want to be able to loop through all the links in my menu, click on it and run a test to see if the link is working.
ie. if my menu looks like this:
<ul id='nav'>
<li><a>Link1</a></li>
<li><a>Link2</a></li>
<li><a>Link3</a></li>
<li><a>Link4</a></li>
<li><a>Link5</a></li>
</ul>
I want to be able to loop through the links and pass its index:
$links = somefunctiontogetalllinks();
for ($x = 0; $x <= count($links); $x++) {
codeceptionTest($x);
}
And then the test can refer to the link using CSS pseudo selectors:
public function codeceptionTest($index) {
$i->click('#nav > li:nth-child(' . $index . ') > a');
$I->see('Page Content');
}
I can;t find any way to get a collection of elements using PHPbrowser or Codeception methods, and I'm unsure whether either presents the page it scrapes as an object to traverse.
Aucun commentaire:
Enregistrer un commentaire