Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a bunch of safeguard in tests to avoid fatal errors on failure

If the elements used in the tests are not found, most cases are now
reporting a failure instead of triggering a fatal error by calling a
method on null.
  • Loading branch information...
commit 53b48cbafa2d1112c0158b4f44bce6d7d414c265 1 parent b0f7b97
@stof stof authored
View
20 tests/Behat/Mink/Driver/GeneralDriverTest.php
@@ -125,6 +125,7 @@ public function testIssue212()
$page = $session->getPage();
$field = $page->findById('poney-button');
+ $this->assertNotNull($field);
$this->assertEquals('poney', $field->getValue());
}
@@ -314,7 +315,7 @@ public function testElementsTraversing()
$this->assertFalse($page->find('xpath', '//div/strong[2]')->hasAttribute('class'));
$strongs = $page->findAll('css', 'div#core > strong');
- $this->assertEquals(3, count($strongs));
+ $this->assertCount(3, $strongs);
$this->assertEquals('Lorem', $strongs[0]->getText());
$this->assertEquals('pariatur', $strongs[2]->getText());
@@ -343,6 +344,7 @@ public function testGetAttribute($attributeName, $attributeValue)
$element = $this->getSession()->getPage()->findById('attr-elem[' . $attributeName . ']');
+ $this->assertNotNull($element);
$this->assertSame($attributeValue, $element->getAttribute($attributeName));
}
@@ -403,11 +405,11 @@ public function testDeepTraversing()
$traversDiv = $this->getSession()->getPage()->findAll('css', 'div.travers');
- $this->assertEquals(1, count($traversDiv));
+ $this->assertCount(1, $traversDiv);
$traversDiv = $traversDiv[0];
$subDivs = $traversDiv->findAll('css', 'div.sub');
- $this->assertEquals(3, count($subDivs));
+ $this->assertCount(3, $subDivs);
$this->assertTrue($subDivs[2]->hasLink('some deep url'));
$this->assertFalse($subDivs[2]->hasLink('come deep url'));
@@ -429,6 +431,7 @@ public function testLinks()
$page = $this->getSession()->getPage();
$link = $page->findLink('Redirect me to');
+ $this->assertNotNull($link);
$this->assertRegExp('/redirector\.php$/', $link->getAttribute('href'));
$link->click();
@@ -438,6 +441,7 @@ public function testLinks()
$page = $this->getSession()->getPage();
$link = $page->findLink('basic form image');
+ $this->assertNotNull($link);
$this->assertRegExp('/basic_form\.php$/', $link->getAttribute('href'));
$link->click();
@@ -512,6 +516,7 @@ public function testFormSubmitWays($submitVia)
$page = $session->getPage();
$firstname = $page->findField('first_name');
+ $this->assertNotNull($firstname);
$firstname->setValue('Konstantin');
$page->findButton($submitVia)->click();
@@ -567,6 +572,7 @@ public function testBasicGetForm()
$this->assertEquals('Basic Get Form Page', $page->find('css', 'h1')->getText());
$search = $page->findField('q');
+ $this->assertNotNull($search);
$search->setValue('some#query');
$page->pressButton('Find');
@@ -601,6 +607,7 @@ public function testMultiselect()
$this->assertEquals(array('1', '3'), $multiSelect->getValue());
$button = $page->findButton('Register');
+ $this->assertNotNull($button);
$button->press();
$space = ' ';
@@ -627,6 +634,7 @@ public function testElementSelectedStateCheck($selectName, $optionValue, $option
$optionValueEscaped = $session->getSelectorsHandler()->xpathLiteral($optionValue);
$option = $select->find('xpath', 'descendant-or-self::option[@value = ' . $optionValueEscaped . ']');
+ $this->assertNotNull($option);
$this->assertFalse($option->isSelected());
$select->selectOption($optionText);
@@ -708,6 +716,7 @@ public function testAdvancedForm()
$about->attachFile($this->mapRemoteFilePath(__DIR__ . '/web-fixtures/some_file.txt'));
$button = $page->findButton('Register');
+ $this->assertNotNull($button);
$page->fillField('first_name', 'Foo "item"');
$page->fillField('last_name', 'Bar');
@@ -799,6 +808,7 @@ public function testMultiInput()
$this->assertEquals('tag3', $third->getValue());
$button = $page->findButton('Register');
+ $this->assertNotNull($button);
$button->press();
$space = ' ';
@@ -835,6 +845,7 @@ public function testAdvancedFormSecondSubmit()
$page = $this->getSession()->getPage();
$button = $page->findButton('Login');
+ $this->assertNotNull($button);
$button->press();
$toSearch = array(
@@ -959,6 +970,9 @@ public function testHtmlDecodingNotPerformed()
$span = $page->find('css', 'span');
$input = $page->find('css', 'input');
+ $this->assertNotNull($span);
+ $this->assertNotNull($input);
+
$expectedHtml = '<span custom-attr="&amp;">some text</span>';
$this->assertContains($expectedHtml, $page->getHtml(), '.innerHTML is returned as-is');
$this->assertContains($expectedHtml, $page->getContent(), '.outerHTML is returned as-is');
View
25 tests/Behat/Mink/Driver/JavascriptDriverTest.php
@@ -110,6 +110,7 @@ public function testClick()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$clicker = $this->getSession()->getPage()->find('css', '.elements div#clicker');
+ $this->assertNotNull($clicker);
$this->assertEquals('not clicked', $clicker->getText());
$clicker->click();
@@ -123,6 +124,7 @@ public function testDoubleClick()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$clicker = $this->getSession()->getPage()->find('css', '.elements div#clicker');
+ $this->assertNotNull($clicker);
$this->assertEquals('not clicked', $clicker->getText());
$clicker->doubleClick();
@@ -136,6 +138,7 @@ public function testRightClick()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$clicker = $this->getSession()->getPage()->find('css', '.elements div#clicker');
+ $this->assertNotNull($clicker);
$this->assertEquals('not clicked', $clicker->getText());
$clicker->rightClick();
@@ -149,6 +152,7 @@ public function testFocus()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$focusBlurDetector = $this->getSession()->getPage()->find('css', '.elements input#focus-blur-detector');
+ $this->assertNotNull($focusBlurDetector);
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->focus();
@@ -163,6 +167,7 @@ public function testBlur()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$focusBlurDetector = $this->getSession()->getPage()->find('css', '.elements input#focus-blur-detector');
+ $this->assertNotNull($focusBlurDetector);
$this->assertEquals('no action detected', $focusBlurDetector->getValue());
$focusBlurDetector->blur();
@@ -176,6 +181,7 @@ public function testMouseOver()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
$mouseOverDetector = $this->getSession()->getPage()->find('css', '.elements div#mouseover-detector');
+ $this->assertNotNull($mouseOverDetector);
$this->assertEquals('no mouse action detected', $mouseOverDetector->getText());
$mouseOverDetector->mouseOver();
@@ -194,6 +200,11 @@ public function testKeyboardEvents($modifier, $eventProperties)
$input3 = $this->getSession()->getPage()->find('css', '.elements input.input.third');
$event = $this->getSession()->getPage()->find('css', '.elements .text-event');
+ $this->assertNotNull($input1);
+ $this->assertNotNull($input2);
+ $this->assertNotNull($input3);
+ $this->assertNotNull($event);
+
$input1->keyDown('u', $modifier);
$this->assertEquals('key downed:' . $eventProperties, $event->getText());
@@ -219,11 +230,14 @@ public function testWait()
{
$this->getSession()->visit($this->pathTo('/js_test.php'));
- $this->getSession()->getPage()->findById('waitable')->click();
+ $waitable = $this->getSession()->getPage()->findById('waitable');
+ $this->assertNotNull($waitable);
+
+ $waitable->click();
$this->getSession()->wait(3000, '$("#waitable").has("div").length > 0');
$this->assertEquals('arrived', $this->getSession()->getPage()->find('css', '#waitable > div')->getText());
- $this->getSession()->getPage()->findById('waitable')->click();
+ $waitable->click();
$this->getSession()->wait(3000, 'false');
$this->assertEquals('timeout', $this->getSession()->getPage()->find('css', '#waitable > div')->getText());
}
@@ -235,6 +249,9 @@ public function testVisibility()
$clicker = $this->getSession()->getPage()->find('css', '.elements div#clicker');
$invisible = $this->getSession()->getPage()->find('css', '#invisible');
+ $this->assertNotNull($clicker);
+ $this->assertNotNull($invisible);
+
$this->assertFalse($invisible->isVisible());
$this->assertTrue($clicker->isVisible());
}
@@ -246,6 +263,9 @@ public function testDragDrop()
$draggable = $this->getSession()->getPage()->find('css', '#draggable');
$droppable = $this->getSession()->getPage()->find('css', '#droppable');
+ $this->assertNotNull($draggable);
+ $this->assertNotNull($droppable);
+
$draggable->dragTo($droppable);
$this->assertEquals('Dropped!', $droppable->find('css', 'p')->getText());
}
@@ -297,6 +317,7 @@ public function testExecuteScript($script)
sleep(1);
$heading = $this->getSession()->getPage()->find('css', 'h1');
+ $this->assertNotNull($heading);
$this->assertEquals('Hello world', $heading->getText());
}
Please sign in to comment.
Something went wrong with that request. Please try again.