WebDriverNotConstraintTest.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. require_once __DIR__.'/mocked_webelement.php';
  3. class WebDriverConstraintNotTest extends PHPUnit_Framework_TestCase
  4. {
  5. /**
  6. * @var Codeception\PHPUnit\Constraint\WebDriver
  7. */
  8. protected $constraint;
  9. public function setUp()
  10. {
  11. $this->constraint = new Codeception\PHPUnit\Constraint\WebDriverNot('warcraft', '/user');
  12. }
  13. public function testEvaluation()
  14. {
  15. $nodes = array(new TestedWebElement('Hello world'), new TestedWebElement('Bye world'));
  16. $this->constraint->evaluate($nodes);
  17. }
  18. public function testFailMessageResponseWithStringSelector()
  19. {
  20. $nodes = array(new TestedWebElement('Bye warcraft'), new TestedWebElement('Bye world'));
  21. try {
  22. $this->constraint->evaluate($nodes, 'selector');
  23. } catch (PHPUnit_Framework_AssertionFailedError $fail) {
  24. $this->assertContains("There was 'selector' element on page /user", $fail->getMessage());
  25. $this->assertNotContains('+ <p> Bye world', $fail->getMessage());
  26. $this->assertContains('+ <p> Bye warcraft', $fail->getMessage());
  27. return;
  28. }
  29. $this->fail("should have failed, but not");
  30. }
  31. public function testFailMessageResponseWithArraySelector()
  32. {
  33. $nodes = array(new TestedWebElement('Bye warcraft'));
  34. try {
  35. $this->constraint->evaluate($nodes, ['css' => 'p.mocked']);
  36. } catch (PHPUnit_Framework_AssertionFailedError $fail) {
  37. $this->assertContains("There was css 'p.mocked' element on page /user", $fail->getMessage());
  38. $this->assertContains('+ <p> Bye warcraft', $fail->getMessage());
  39. return;
  40. }
  41. $this->fail("should have failed, but not");
  42. }
  43. public function testFailMessageResponseWhenMoreNodes()
  44. {
  45. $nodes = array();
  46. for ($i = 0; $i < 15; $i++) {
  47. $nodes[] = new TestedWebElement("warcraft $i");
  48. }
  49. try {
  50. $this->constraint->evaluate($nodes, 'selector');
  51. } catch (PHPUnit_Framework_AssertionFailedError $fail) {
  52. $this->assertContains("There was 'selector' element on page /user", $fail->getMessage());
  53. $this->assertContains('+ <p> warcraft 0', $fail->getMessage());
  54. $this->assertContains('+ <p> warcraft 14', $fail->getMessage());
  55. return;
  56. }
  57. $this->fail("should have failed, but not");
  58. }
  59. public function testFailMessageResponseWithoutUrl()
  60. {
  61. $this->constraint = new Codeception\PHPUnit\Constraint\WebDriverNot('warcraft');
  62. $nodes = array(new TestedWebElement('Bye warcraft'), new TestedWebElement('Bye world'));
  63. try {
  64. $this->constraint->evaluate($nodes, 'selector');
  65. } catch (PHPUnit_Framework_AssertionFailedError $fail) {
  66. $this->assertContains("There was 'selector' element", $fail->getMessage());
  67. $this->assertNotContains("There was 'selector' element on page", $fail->getMessage());
  68. return;
  69. }
  70. $this->fail("should have failed, but not");
  71. }
  72. }