Sunday 15 January 2012

php - Find content in specific DIV with Behat/Selenium -



php - Find content in specific DIV with Behat/Selenium -

i creating behat/selenium automated test script. want create statement says:

given on "/" should see <content> in <specific div>

i want create function in featurecontext.php file allow me verify content (text) exists within specified div tag. can please point me in right direction?

if want pointed in right direction, should avoid doing things such – contradict behat ideology. scenario describes actions user performs , assertions makes verify result user looks @ page, not developer looks code. logic of lastly must done behind scenes. in other words, step should read more this:

given on homepage page title should read "hello world" , user list should contain "john doe" , dialogue title should "foo bar"

if want reply initial question, can such:

/** * @then /^(?:|i )should see "(?p<text>.+)" in "(?p<selector>\w+)" element$/ */ public function assertelementtext($text, $selector) { $page = $this->getsession()->getpage(); $element = $page->findall('css', $selector); foreach($this->getsession()->getpage()->findall() $element) { if (strpos(strtolower($text), strtolower($element->gettext()) !== false) { return; } } throw exception("text '{$text}' not found in '{$selector}' element."); }

and utilize this:

then should see "hello world" in "div#title" element should see "john doe" in "ul#users > li" element

php html xpath behat mink

No comments:

Post a Comment