PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/PHPUnit/Testcase/Selenium1.php

https://github.com/andreaswolf/Menta
PHP | 139 lines | 33 code | 12 blank | 94 comment | 2 complexity | c25ccb50fb881e9babea403858a8b15c MD5 | raw file
  1. <?php
  2. /**
  3. * Selenium1_Testcase
  4. *
  5. * @author Fabrizio Branca
  6. * @since 2011-11-18
  7. */
  8. /**
  9. * Update this index using:
  10. * cat Menta/Component/Selenium1Facade.php | grep 'public function' | sed 's/^.*public function / * @method /' | sed 's/\w*{.*\?//'
  11. *
  12. * @method setBrowserUrl($baseUrl)
  13. * @method assertTitle($title)
  14. * @method isElementPresent($element)
  15. * @method isTextPresent($text)
  16. * @method waitForElementPresent($locator, $timeout=null, $message=null)
  17. * @method waitForElementNotPresent($locator, $timeout=null, $message=null)
  18. * @method waitForTextPresent($text, $timeout=null, $message=null)
  19. * @method waitForTextNotPresent($text, $timeout=null, $message=NULL)
  20. * @method waitForCondition($jsSnippet, $timeout=NULL, $message=NULL)
  21. * @method waitForVisible($locator, $timeout=NULL, $message=NULL)
  22. * @method waitForNotVisible($locator, $timeout=NULL, $message=NULL)
  23. * @method getElement($element)
  24. * @method getTitle()
  25. * @method getText($element)
  26. * @method getBrowserUrl()
  27. * @method open($url)
  28. * @method start()
  29. * @method stop()
  30. * @method windowFocus()
  31. * @method windowMaximize()
  32. * @method waitForPageToLoad()
  33. * @method getEval($jsSnippet)
  34. * @method click($element)
  35. * @method type($element, $text)
  36. * @method select($element, $option)
  37. * @method fireEvent($element, $event)
  38. * @method getValue($element)
  39. * @method isVisible($element)
  40. * @method getSelectedLabel($element)
  41. * @method getSelectedValue($element)
  42. * @method getFirstSelectedOption($element)
  43. * @method getXpathCount($xpath)
  44. * @method getElementCount($locator)
  45. * @method assertTextPresent($text, $message='')
  46. * @method assertTextNotPresent($text, $message='')
  47. * @method clickAndWait($element)
  48. * @method assertElementPresent($element, $message='')
  49. * @method assertElementNotPresent($element, $message='')
  50. * @method waitForAjaxCompletedJquery()
  51. * @method waitForAjaxCompletedPrototype()
  52. * @method clickAndWaitAjax($clickElement, $waitForElementAfterClick, $timeout=NULL)
  53. * @method typeAndLeave($element, $text)
  54. * @method assertElementContainsText($element, $text, $message='')
  55. */
  56. abstract class Menta_PHPUnit_Testcase_Selenium1 extends Menta_PHPUnit_Testcase_Selenium2 {
  57. protected $captureScreenshotOnFailure = false;
  58. /**
  59. * @var string
  60. */
  61. protected $testId;
  62. /**
  63. * @var Menta_Component_Selenium1Facade
  64. */
  65. protected $selenium1Facade;
  66. /**
  67. * @param string $name
  68. * @param array $data
  69. * @param string $dataName
  70. * @param array $browser
  71. * @throws InvalidArgumentException
  72. */
  73. public function __construct($name = NULL, array $data = array(), $dataName = '', array $browser = array()) {
  74. $this->testId = md5(uniqid(rand(), TRUE));
  75. parent::__construct($name, $data, $dataName, $browser);
  76. }
  77. /**
  78. * Get test id
  79. *
  80. * @return string
  81. */
  82. public function getTestId() {
  83. return $this->testId;
  84. }
  85. /**
  86. * @return Menta_ConfigurationPhpUnitVars
  87. */
  88. public function getConfiguration() {
  89. return Menta_ConfigurationPhpUnitVars::getInstance();
  90. }
  91. /**
  92. * Set browser url
  93. *
  94. * @param $baseUrl
  95. * @return void
  96. */
  97. public function setBrowserUrl($baseUrl) {
  98. $this->getSelenium1Facade()->setBrowserUrl($baseUrl);
  99. }
  100. /**
  101. * Get selenium1 api
  102. *
  103. * @return Menta_Component_Selenium1Facade
  104. */
  105. public function getSelenium1Facade() {
  106. if (is_null($this->selenium1Facade)) {
  107. $this->selenium1Facade = Menta_ComponentManager::get('Menta_Component_Selenium1Facade');
  108. $this->selenium1Facade->setTest($this);
  109. }
  110. return $this->selenium1Facade;
  111. }
  112. /**
  113. * Delegate method calls to the selenium 1 api.
  114. *
  115. * @param string $command
  116. * @param array $arguments
  117. * @return mixed
  118. */
  119. public function __call($command, $arguments) {
  120. // file_put_contents('debug.txt', var_export($command, 1) ."\n", FILE_APPEND);
  121. if (!method_exists($this->getSelenium1Facade(), $command)) {
  122. throw new Exception("Command $command is not implemented in the selenium1 api wrapper class");
  123. }
  124. $result = call_user_func_array(array($this->getSelenium1Facade(), $command), $arguments);
  125. return $result;
  126. }
  127. }