diff -u b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php --- b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -170,6 +170,31 @@ $this->assertNoFieldByXPath('//notexisting'); $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value'); + + // Test that the assertion fails correctly. + try { + $this->assertFieldByXPath("//input[@id = 'notexisting']"); + $this->fail('The "notexisting" field was found.'); + } + catch (\PHPUnit_Framework_ExpectationFailedException $e) { + $this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.'); + } + + try { + $this->assertNoFieldByXPath("//input[@id = 'edit-name']"); + $this->fail('The "edit-name" field was not found.'); + } + catch (\PHPUnit_Framework_ExpectationFailedException $e) { + $this->pass('assertNoFieldByXPath correctly failed. The "edit-name" field was found.'); + } + + try { + $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value'); + $this->fail('The "edit-name" field is found with the value "not the value".'); + } + catch (\PHPUnit_Framework_ExpectationFailedException $e) { + $this->pass('The "edit-name" field is not found with the value "not the value".'); + } } /** @@ -327,6 +352,15 @@ $this->pass($e->getMessage()); } + $this->assertNoOption('options', 'non-existing'); + try { + $this->assertNoOption('options', 'one'); + $this->fail('The select option "one" was not found.'); + } + catch (ExpectationException $e) { + $this->pass($e->getMessage()); + } + // Button field type. $this->assertFieldById('edit-save', NULL); // Test that the assertion fails correctly if the field value is passed in