This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Adds "Element::isValid" method for checking element presence in DOM

  • Loading branch information...
1 parent c1dd197 commit 1568f845a0406b03ab68e694449c46950e2cd399 @aik099 aik099 committed Feb 19, 2014
@@ -54,6 +54,16 @@ public function has($selector, $locator)
return null !== $this->find($selector, $locator);
}
+ /**
+ * Checks if an element is still valid.
+ *
+ * @return boolean
+ */
+ public function isValid()
+ {
+ return 1 === count($this->getSession()->getDriver()->find($this->getXpath()));
+ }
+
/**
* Finds first element with specified selector.
*
@@ -43,6 +43,13 @@ public function getSession();
*/
public function has($selector, $locator);
+ /**
+ * Checks if an element is still valid.
+ *
+ * @return boolean
+ */
+ public function isValid();
+
/**
* Finds first element with specified selector.
*
@@ -34,6 +34,34 @@ public function testGetText()
$this->assertEquals($expected, $node->getText());
}
+ public function testElementIsValid()
+ {
+ $elementXpath = 'some xpath';
+ $node = new NodeElement($elementXpath, $this->session);
+
+ $this->session->getDriver()
+ ->expects($this->once())
+ ->method('find')
+ ->with($elementXpath)
+ ->will($this->returnValue(array($elementXpath)));
+
+ $this->assertTrue($node->isValid());
+ }
+
+ public function testElementIsNotValid()
+ {
+ $node = new NodeElement('some xpath', $this->session);
+
+ $this->session->getDriver()
+ ->expects($this->exactly(2))
+ ->method('find')
+ ->with('some xpath')
+ ->will($this->onConsecutiveCalls(array(), array('xpath1', 'xpath2')));
+
+ $this->assertFalse($node->isValid(), 'no elements found is invalid element');
+ $this->assertFalse($node->isValid(), 'more then 1 element found is invalid element');
+ }
+
public function testHasAttribute()
{
$node = new NodeElement('input_tag', $this->session);

0 comments on commit 1568f84

Please sign in to comment.