PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/blog/www/system/library/PEAR/Testing/Selenium.php

https://bitbucket.org/vmihailenco/vladimirwebdev
PHP | 2506 lines | 627 code | 280 blank | 1599 comment | 6 complexity | 5f292cc61bdf59fa5f88bdf8ec7bd186 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /** Copyright 2006 ThoughtWorks, Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. * -----------------
  17. * This file has been automatically generated via XSL
  18. * -----------------
  19. *
  20. *
  21. *
  22. * @category Testing
  23. * @package Selenium
  24. * @author Shin Ohno <ganchiku at gmail dot com>
  25. * @author Bjoern Schotte <schotte at mayflower dot de>
  26. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  27. * @version @package_version@
  28. * @see http://www.openqa.org/selenium-rc/
  29. * @since 0.1
  30. */
  31. /**
  32. * Selenium exception class
  33. */
  34. require_once 'Testing/Selenium/Exception.php';
  35. /**
  36. * Defines an object that runs Selenium commands.
  37. *
  38. *
  39. * <p>
  40. * <b>Element Locators</b>
  41. * </p><p>
  42. *
  43. * Element Locators tell Selenium which HTML element a command refers to.
  44. * The format of a locator is:
  45. * </p><p>
  46. *
  47. * <i>locatorType</i><b>=</b><i>argument</i>
  48. * </p>
  49. * <p>
  50. *
  51. * We support the following strategies for locating elements:
  52. *
  53. * </p>
  54. * <ul>
  55. *
  56. * <li>
  57. * <b>identifier</b>=<i>id</i>:
  58. * Select the element with the specified @id attribute. If no match is
  59. * found, select the first element whose @name attribute is <i>id</i>.
  60. * (This is normally the default; see below.)
  61. * </li>
  62. * <li>
  63. * <b>id</b>=<i>id</i>:
  64. * Select the element with the specified @id attribute.
  65. * </li>
  66. * <li>
  67. * <b>name</b>=<i>name</i>:
  68. * Select the first element with the specified @name attribute.
  69. *
  70. * <ul>
  71. *
  72. * <li>
  73. * username
  74. * </li>
  75. * <li>
  76. * name=username
  77. * </li>
  78. * </ul>
  79. <p>
  80. * The name may optionally be followed by one or more <i>element-filters</i>, separated from the name by whitespace. If the <i>filterType</i> is not specified, <b>value</b> is assumed.
  81. * </p>
  82. * <ul>
  83. *
  84. * <li>
  85. * name=flavour value=chocolate
  86. * </li>
  87. * </ul>
  88. * </li>
  89. * <li>
  90. * <b>dom</b>=<i>javascriptExpression</i>:
  91. *
  92. * Find an element by evaluating the specified string. This allows you to traverse the HTML Document Object
  93. * Model using JavaScript. Note that you must not return a value in this string; simply make it the last expression in the block.
  94. *
  95. * <ul>
  96. *
  97. * <li>
  98. * dom=document.forms['myForm'].myDropdown
  99. * </li>
  100. * <li>
  101. * dom=document.images[56]
  102. * </li>
  103. * <li>
  104. * dom=function foo() { return document.links[1]; }; foo();
  105. * </li>
  106. * </ul>
  107. * </li>
  108. * <li>
  109. * <b>xpath</b>=<i>xpathExpression</i>:
  110. * Locate an element using an XPath expression.
  111. *
  112. * <ul>
  113. *
  114. * <li>
  115. * xpath=//img[@alt='The image alt text']
  116. * </li>
  117. * <li>
  118. * xpath=//table[@id='table1']//tr[4]/td[2]
  119. * </li>
  120. * <li>
  121. * xpath=//a[contains(@href,'#id1')]
  122. * </li>
  123. * <li>
  124. * xpath=//a[contains(@href,'#id1')]/@class
  125. * </li>
  126. * <li>
  127. * xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td
  128. * </li>
  129. * <li>
  130. * xpath=//input[@name='name2' and @value='yes']
  131. * </li>
  132. * <li>
  133. * xpath=//*[text()="right"]
  134. * </li>
  135. * </ul>
  136. * </li>
  137. * <li>
  138. * <b>link</b>=<i>textPattern</i>:
  139. * Select the link (anchor) element which contains text matching the
  140. * specified <i>pattern</i>.
  141. *
  142. * <ul>
  143. *
  144. * <li>
  145. * link=The link text
  146. * </li>
  147. * </ul>
  148. * </li>
  149. * <li>
  150. * <b>css</b>=<i>cssSelectorSyntax</i>:
  151. * Select the element using css selectors. Please refer to CSS2 selectors, CSS3 selectors for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
  152. *
  153. * <ul>
  154. *
  155. * <li>
  156. * css=a[href="#id3"]
  157. * </li>
  158. * <li>
  159. * css=span#firstChild + span
  160. * </li>
  161. * </ul>
  162. <p>
  163. * Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after).
  164. * </p>
  165. * </li>
  166. * </ul><p>
  167. *
  168. * Without an explicit locator prefix, Selenium uses the following default
  169. * strategies:
  170. *
  171. * </p>
  172. * <ul>
  173. *
  174. * <li>
  175. * <b>dom</b>, for locators starting with "document."
  176. * </li>
  177. * <li>
  178. * <b>xpath</b>, for locators starting with "//"
  179. * </li>
  180. * <li>
  181. * <b>identifier</b>, otherwise
  182. * </li>
  183. * </ul>
  184. * <p>
  185. * <b>Element Filters</b>
  186. * </p><p>
  187. *
  188. * <p>
  189. * Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.
  190. * </p>
  191. <p>
  192. * Filters look much like locators, ie.
  193. * </p>
  194. <p>
  195. *
  196. * <i>filterType</i><b>=</b><i>argument</i>
  197. * </p>
  198. * <p>
  199. * Supported element-filters are:
  200. * </p>
  201. <p>
  202. * <b>value=</b><i>valuePattern</i>
  203. * </p>
  204. <p>
  205. *
  206. *
  207. * Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.
  208. * </p>
  209. * <p>
  210. * <b>index=</b><i>index</i>
  211. * </p>
  212. <p>
  213. *
  214. *
  215. * Selects a single element based on its position in the list (offset from zero).
  216. * </p>
  217. *
  218. * </p>
  219. *
  220. * <p>
  221. * <b>String-match Patterns</b>
  222. * </p><p>
  223. *
  224. * Various Pattern syntaxes are available for matching string values:
  225. *
  226. * </p>
  227. * <ul>
  228. *
  229. * <li>
  230. * <b>glob:</b><i>pattern</i>:
  231. * Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
  232. * kind of limited regular-expression syntax typically used in command-line
  233. * shells. In a glob pattern, "*" represents any sequence of characters, and "?"
  234. * represents any single character. Glob patterns match against the entire
  235. * string.
  236. * </li>
  237. * <li>
  238. * <b>regexp:</b><i>regexp</i>:
  239. * Match a string using a regular-expression. The full power of JavaScript
  240. * regular-expressions is available.
  241. * </li>
  242. * <li>
  243. * <b>regexpi:</b><i>regexpi</i>:
  244. * Match a string using a case-insensitive regular-expression.
  245. * </li>
  246. * <li>
  247. * <b>exact:</b><i>string</i>:
  248. *
  249. * Match a string exactly, verbatim, without any of that fancy wildcard
  250. * stuff.
  251. * </li>
  252. * </ul><p>
  253. *
  254. * If no pattern prefix is specified, Selenium assumes that it's a "glob"
  255. * pattern.
  256. *
  257. * </p><p>
  258. *
  259. * For commands that return multiple values (such as verifySelectOptions),
  260. * the string being matched is a comma-separated list of the return values,
  261. * where both commas and backslashes in the values are backslash-escaped.
  262. * When providing a pattern, the optional matching syntax (i.e. glob,
  263. * regexp, etc.) is specified once, as usual, at the beginning of the
  264. * pattern.
  265. *
  266. * </p>
  267. *
  268. * @package Selenium
  269. * @author Shin Ohno <ganchiku at gmail dot com>
  270. * @author Bjoern Schotte <schotte at mayflower dot de>
  271. */
  272. class Testing_Selenium
  273. {
  274. /**
  275. * @var string
  276. * @access private
  277. */
  278. private $browser;
  279. /**
  280. * @var string
  281. * @access private
  282. */
  283. private $browserUrl;
  284. /**
  285. * @var string
  286. * @access private
  287. */
  288. private $host;
  289. /**
  290. * @var int
  291. * @access private
  292. */
  293. private $port;
  294. /**
  295. * @var string
  296. * @access private
  297. */
  298. private $sessionId;
  299. /**
  300. * @var string
  301. * @access private
  302. */
  303. private $timeout;
  304. /**
  305. * Constructor
  306. *
  307. * @param string $browser
  308. * @param string $browserUrl
  309. * @param string $host
  310. * @param int $port
  311. * @param int $timeout
  312. * @access public
  313. * @throws Testing_Selenium_Exception
  314. */
  315. public function __construct($browser, $browserUrl, $host = 'localhost', $port = 4444, $timeout = 30000)
  316. {
  317. $this->browser = $browser;
  318. $this->browserUrl = $browserUrl;
  319. $this->host = $host;
  320. $this->port = $port;
  321. $this->timeout = $timeout;
  322. }
  323. /**
  324. * Run the browser and set session id.
  325. *
  326. * @access public
  327. * @return void
  328. */
  329. public function start()
  330. {
  331. $this->sessionId = $this->getString("getNewBrowserSession", array($this->browser, $this->browserUrl));
  332. return $this->sessionId;
  333. }
  334. /**
  335. * Close the browser and set session id null
  336. *
  337. * @access public
  338. * @return void
  339. */
  340. public function stop()
  341. {
  342. $this->doCommand("testComplete");
  343. $this->sessionId = null;
  344. }
  345. /**
  346. * Clicks on a link, button, checkbox or radio button. If the click action
  347. * causes a new page to load (like a link usually does), call
  348. * waitForPageToLoad.
  349. *
  350. * @access public
  351. * @param string $locator an element locator
  352. */
  353. public function click($locator)
  354. {
  355. $this->doCommand("click", array($locator));
  356. }
  357. /**
  358. * Double clicks on a link, button, checkbox or radio button. If the double click action
  359. * causes a new page to load (like a link usually does), call
  360. * waitForPageToLoad.
  361. *
  362. * @access public
  363. * @param string $locator an element locator
  364. */
  365. public function doubleClick($locator)
  366. {
  367. $this->doCommand("doubleClick", array($locator));
  368. }
  369. /**
  370. * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
  371. *
  372. * @access public
  373. * @param string $locator an element locator
  374. */
  375. public function contextMenu($locator)
  376. {
  377. $this->doCommand("contextMenu", array($locator));
  378. }
  379. /**
  380. * Clicks on a link, button, checkbox or radio button. If the click action
  381. * causes a new page to load (like a link usually does), call
  382. * waitForPageToLoad.
  383. *
  384. * @access public
  385. * @param string $locator an element locator
  386. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  387. */
  388. public function clickAt($locator, $coordString)
  389. {
  390. $this->doCommand("clickAt", array($locator, $coordString));
  391. }
  392. /**
  393. * Doubleclicks on a link, button, checkbox or radio button. If the action
  394. * causes a new page to load (like a link usually does), call
  395. * waitForPageToLoad.
  396. *
  397. * @access public
  398. * @param string $locator an element locator
  399. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  400. */
  401. public function doubleClickAt($locator, $coordString)
  402. {
  403. $this->doCommand("doubleClickAt", array($locator, $coordString));
  404. }
  405. /**
  406. * Simulates opening the context menu for the specified element (as might happen if the user "right-clicked" on the element).
  407. *
  408. * @access public
  409. * @param string $locator an element locator
  410. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  411. */
  412. public function contextMenuAt($locator, $coordString)
  413. {
  414. $this->doCommand("contextMenuAt", array($locator, $coordString));
  415. }
  416. /**
  417. * Explicitly simulate an event, to trigger the corresponding "on<i>event</i>"
  418. * handler.
  419. *
  420. * @access public
  421. * @param string $locator an element locator
  422. * @param string $eventName the event name, e.g. "focus" or "blur"
  423. */
  424. public function fireEvent($locator, $eventName)
  425. {
  426. $this->doCommand("fireEvent", array($locator, $eventName));
  427. }
  428. /**
  429. * Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
  430. *
  431. * @access public
  432. * @param string $locator an element locator
  433. */
  434. public function focus($locator)
  435. {
  436. $this->doCommand("focus", array($locator));
  437. }
  438. /**
  439. * Simulates a user pressing and releasing a key.
  440. *
  441. * @access public
  442. * @param string $locator an element locator
  443. * @param string $keySequence Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
  444. */
  445. public function keyPress($locator, $keySequence)
  446. {
  447. $this->doCommand("keyPress", array($locator, $keySequence));
  448. }
  449. /**
  450. * Press the shift key and hold it down until doShiftUp() is called or a new page is loaded.
  451. *
  452. * @access public
  453. */
  454. public function shiftKeyDown()
  455. {
  456. $this->doCommand("shiftKeyDown", array());
  457. }
  458. /**
  459. * Release the shift key.
  460. *
  461. * @access public
  462. */
  463. public function shiftKeyUp()
  464. {
  465. $this->doCommand("shiftKeyUp", array());
  466. }
  467. /**
  468. * Press the meta key and hold it down until doMetaUp() is called or a new page is loaded.
  469. *
  470. * @access public
  471. */
  472. public function metaKeyDown()
  473. {
  474. $this->doCommand("metaKeyDown", array());
  475. }
  476. /**
  477. * Release the meta key.
  478. *
  479. * @access public
  480. */
  481. public function metaKeyUp()
  482. {
  483. $this->doCommand("metaKeyUp", array());
  484. }
  485. /**
  486. * Press the alt key and hold it down until doAltUp() is called or a new page is loaded.
  487. *
  488. * @access public
  489. */
  490. public function altKeyDown()
  491. {
  492. $this->doCommand("altKeyDown", array());
  493. }
  494. /**
  495. * Release the alt key.
  496. *
  497. * @access public
  498. */
  499. public function altKeyUp()
  500. {
  501. $this->doCommand("altKeyUp", array());
  502. }
  503. /**
  504. * Press the control key and hold it down until doControlUp() is called or a new page is loaded.
  505. *
  506. * @access public
  507. */
  508. public function controlKeyDown()
  509. {
  510. $this->doCommand("controlKeyDown", array());
  511. }
  512. /**
  513. * Release the control key.
  514. *
  515. * @access public
  516. */
  517. public function controlKeyUp()
  518. {
  519. $this->doCommand("controlKeyUp", array());
  520. }
  521. /**
  522. * Simulates a user pressing a key (without releasing it yet).
  523. *
  524. * @access public
  525. * @param string $locator an element locator
  526. * @param string $keySequence Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
  527. */
  528. public function keyDown($locator, $keySequence)
  529. {
  530. $this->doCommand("keyDown", array($locator, $keySequence));
  531. }
  532. /**
  533. * Simulates a user releasing a key.
  534. *
  535. * @access public
  536. * @param string $locator an element locator
  537. * @param string $keySequence Either be a string("\" followed by the numeric keycode of the key to be pressed, normally the ASCII value of that key), or a single character. For example: "w", "\119".
  538. */
  539. public function keyUp($locator, $keySequence)
  540. {
  541. $this->doCommand("keyUp", array($locator, $keySequence));
  542. }
  543. /**
  544. * Simulates a user hovering a mouse over the specified element.
  545. *
  546. * @access public
  547. * @param string $locator an element locator
  548. */
  549. public function mouseOver($locator)
  550. {
  551. $this->doCommand("mouseOver", array($locator));
  552. }
  553. /**
  554. * Simulates a user moving the mouse pointer away from the specified element.
  555. *
  556. * @access public
  557. * @param string $locator an element locator
  558. */
  559. public function mouseOut($locator)
  560. {
  561. $this->doCommand("mouseOut", array($locator));
  562. }
  563. /**
  564. * Simulates a user pressing the mouse button (without releasing it yet) on
  565. * the specified element.
  566. *
  567. * @access public
  568. * @param string $locator an element locator
  569. */
  570. public function mouseDown($locator)
  571. {
  572. $this->doCommand("mouseDown", array($locator));
  573. }
  574. /**
  575. * Simulates a user pressing the mouse button (without releasing it yet) at
  576. * the specified location.
  577. *
  578. * @access public
  579. * @param string $locator an element locator
  580. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  581. */
  582. public function mouseDownAt($locator, $coordString)
  583. {
  584. $this->doCommand("mouseDownAt", array($locator, $coordString));
  585. }
  586. /**
  587. * Simulates the event that occurs when the user releases the mouse button (i.e., stops
  588. * holding the button down) on the specified element.
  589. *
  590. * @access public
  591. * @param string $locator an element locator
  592. */
  593. public function mouseUp($locator)
  594. {
  595. $this->doCommand("mouseUp", array($locator));
  596. }
  597. /**
  598. * Simulates the event that occurs when the user releases the mouse button (i.e., stops
  599. * holding the button down) at the specified location.
  600. *
  601. * @access public
  602. * @param string $locator an element locator
  603. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  604. */
  605. public function mouseUpAt($locator, $coordString)
  606. {
  607. $this->doCommand("mouseUpAt", array($locator, $coordString));
  608. }
  609. /**
  610. * Simulates a user pressing the mouse button (without releasing it yet) on
  611. * the specified element.
  612. *
  613. * @access public
  614. * @param string $locator an element locator
  615. */
  616. public function mouseMove($locator)
  617. {
  618. $this->doCommand("mouseMove", array($locator));
  619. }
  620. /**
  621. * Simulates a user pressing the mouse button (without releasing it yet) on
  622. * the specified element.
  623. *
  624. * @access public
  625. * @param string $locator an element locator
  626. * @param string $coordString specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
  627. */
  628. public function mouseMoveAt($locator, $coordString)
  629. {
  630. $this->doCommand("mouseMoveAt", array($locator, $coordString));
  631. }
  632. /**
  633. * Sets the value of an input field, as though you typed it in.
  634. *
  635. * <p>
  636. * Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
  637. * value should be the value of the option selected, not the visible text.
  638. * </p>
  639. *
  640. * @access public
  641. * @param string $locator an element locator
  642. * @param string $value the value to type
  643. */
  644. public function type($locator, $value)
  645. {
  646. $this->doCommand("type", array($locator, $value));
  647. }
  648. /**
  649. * Simulates keystroke events on the specified element, as though you typed the value key-by-key.
  650. *
  651. * <p>
  652. * This is a convenience method for calling keyDown, keyUp, keyPress for every character in the specified string;
  653. * this is useful for dynamic UI widgets (like auto-completing combo boxes) that require explicit key events.
  654. * </p><p>
  655. * Unlike the simple "type" command, which forces the specified value into the page directly, this command
  656. * may or may not have any visible effect, even in cases where typing keys would normally have a visible effect.
  657. * For example, if you use "typeKeys" on a form element, you may or may not see the results of what you typed in
  658. * the field.
  659. * </p><p>
  660. * In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to
  661. * send the keystroke events corresponding to what you just typed.
  662. * </p>
  663. *
  664. * @access public
  665. * @param string $locator an element locator
  666. * @param string $value the value to type
  667. */
  668. public function typeKeys($locator, $value)
  669. {
  670. $this->doCommand("typeKeys", array($locator, $value));
  671. }
  672. /**
  673. * Set execution speed (i.e., set the millisecond length of a delay which will follow each selenium operation). By default, there is no such delay, i.e.,
  674. * the delay is 0 milliseconds.
  675. *
  676. * @access public
  677. * @param string $value the number of milliseconds to pause after operation
  678. */
  679. public function setSpeed($value)
  680. {
  681. $this->doCommand("setSpeed", array($value));
  682. }
  683. /**
  684. * Get execution speed (i.e., get the millisecond length of the delay following each selenium operation). By default, there is no such delay, i.e.,
  685. * the delay is 0 milliseconds.
  686. *
  687. * See also setSpeed.
  688. *
  689. * @access public
  690. * @return string the execution speed in milliseconds.
  691. */
  692. public function getSpeed()
  693. {
  694. return $this->getString("getSpeed", array());
  695. }
  696. /**
  697. * Check a toggle-button (checkbox/radio)
  698. *
  699. * @access public
  700. * @param string $locator an element locator
  701. */
  702. public function check($locator)
  703. {
  704. $this->doCommand("check", array($locator));
  705. }
  706. /**
  707. * Uncheck a toggle-button (checkbox/radio)
  708. *
  709. * @access public
  710. * @param string $locator an element locator
  711. */
  712. public function uncheck($locator)
  713. {
  714. $this->doCommand("uncheck", array($locator));
  715. }
  716. /**
  717. * Select an option from a drop-down using an option locator.
  718. *
  719. * <p>
  720. *
  721. * Option locators provide different ways of specifying options of an HTML
  722. * Select element (e.g. for selecting a specific option, or for asserting
  723. * that the selected option satisfies a specification). There are several
  724. * forms of Select Option Locator.
  725. *
  726. * </p>
  727. * <ul>
  728. *
  729. * <li>
  730. * <b>label</b>=<i>labelPattern</i>:
  731. * matches options based on their labels, i.e. the visible text. (This
  732. * is the default.)
  733. *
  734. * <ul>
  735. *
  736. * <li>
  737. * label=regexp:^[Oo]ther
  738. * </li>
  739. * </ul>
  740. * </li>
  741. * <li>
  742. * <b>value</b>=<i>valuePattern</i>:
  743. * matches options based on their values.
  744. *
  745. * <ul>
  746. *
  747. * <li>
  748. * value=other
  749. * </li>
  750. * </ul>
  751. * </li>
  752. * <li>
  753. * <b>id</b>=<i>id</i>:
  754. *
  755. * matches options based on their ids.
  756. *
  757. * <ul>
  758. *
  759. * <li>
  760. * id=option1
  761. * </li>
  762. * </ul>
  763. * </li>
  764. * <li>
  765. * <b>index</b>=<i>index</i>:
  766. * matches an option based on its index (offset from zero).
  767. *
  768. * <ul>
  769. *
  770. * <li>
  771. * index=2
  772. * </li>
  773. * </ul>
  774. * </li>
  775. * </ul><p>
  776. *
  777. * If no option locator prefix is provided, the default behaviour is to match on <b>label</b>.
  778. *
  779. * </p>
  780. *
  781. * @access public
  782. * @param string $selectLocator an element locator identifying a drop-down menu
  783. * @param string $optionLocator an option locator (a label by default)
  784. */
  785. public function select($selectLocator, $optionLocator)
  786. {
  787. $this->doCommand("select", array($selectLocator, $optionLocator));
  788. }
  789. /**
  790. * Add a selection to the set of selected options in a multi-select element using an option locator.
  791. *
  792. * @see #doSelect for details of option locators
  793. *
  794. * @access public
  795. * @param string $locator an element locator identifying a multi-select box
  796. * @param string $optionLocator an option locator (a label by default)
  797. */
  798. public function addSelection($locator, $optionLocator)
  799. {
  800. $this->doCommand("addSelection", array($locator, $optionLocator));
  801. }
  802. /**
  803. * Remove a selection from the set of selected options in a multi-select element using an option locator.
  804. *
  805. * @see #doSelect for details of option locators
  806. *
  807. * @access public
  808. * @param string $locator an element locator identifying a multi-select box
  809. * @param string $optionLocator an option locator (a label by default)
  810. */
  811. public function removeSelection($locator, $optionLocator)
  812. {
  813. $this->doCommand("removeSelection", array($locator, $optionLocator));
  814. }
  815. /**
  816. * Unselects all of the selected options in a multi-select element.
  817. *
  818. * @access public
  819. * @param string $locator an element locator identifying a multi-select box
  820. */
  821. public function removeAllSelections($locator)
  822. {
  823. $this->doCommand("removeAllSelections", array($locator));
  824. }
  825. /**
  826. * Submit the specified form. This is particularly useful for forms without
  827. * submit buttons, e.g. single-input "Search" forms.
  828. *
  829. * @access public
  830. * @param string $formLocator an element locator for the form you want to submit
  831. */
  832. public function submit($formLocator)
  833. {
  834. $this->doCommand("submit", array($formLocator));
  835. }
  836. /**
  837. * Opens an URL in the test frame. This accepts both relative and absolute
  838. * URLs.
  839. *
  840. * The "open" command waits for the page to load before proceeding,
  841. * ie. the "AndWait" suffix is implicit.
  842. *
  843. * <i>Note</i>: The URL must be on the same domain as the runner HTML
  844. * due to security restrictions in the browser (Same Origin Policy). If you
  845. * need to open an URL on another domain, use the Selenium Server to start a
  846. * new browser session on that domain.
  847. *
  848. * @access public
  849. * @param string $url the URL to open; may be relative or absolute
  850. */
  851. public function open($url)
  852. {
  853. $this->doCommand("open", array($url));
  854. }
  855. /**
  856. * Opens a popup window (if a window with that ID isn't already open).
  857. * After opening the window, you'll need to select it using the selectWindow
  858. * command.
  859. *
  860. * <p>
  861. * This command can also be a useful workaround for bug SEL-339. In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
  862. * In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
  863. * an empty (blank) url, like this: openWindow("", "myFunnyWindow").
  864. * </p>
  865. *
  866. * @access public
  867. * @param string $url the URL to open, which can be blank
  868. * @param string $windowID the JavaScript window ID of the window to select
  869. */
  870. public function openWindow($url, $windowID)
  871. {
  872. $this->doCommand("openWindow", array($url, $windowID));
  873. }
  874. /**
  875. * Selects a popup window using a window locator; once a popup window has been selected, all
  876. * commands go to that window. To select the main window again, use null
  877. * as the target.
  878. *
  879. * <p>
  880. *
  881. *
  882. * Window locators provide different ways of specifying the window object:
  883. * by title, by internal JavaScript "name," or by JavaScript variable.
  884. *
  885. * </p>
  886. * <ul>
  887. *
  888. * <li>
  889. * <b>title</b>=<i>My Special Window</i>:
  890. * Finds the window using the text that appears in the title bar. Be careful;
  891. * two windows can share the same title. If that happens, this locator will
  892. * just pick one.
  893. *
  894. * </li>
  895. * <li>
  896. * <b>name</b>=<i>myWindow</i>:
  897. * Finds the window using its internal JavaScript "name" property. This is the second
  898. * parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag)
  899. * (which Selenium intercepts).
  900. *
  901. * </li>
  902. * <li>
  903. * <b>var</b>=<i>variableName</i>:
  904. * Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current
  905. * application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using
  906. * "var=foo".
  907. *
  908. * </li>
  909. * </ul><p>
  910. *
  911. * If no window locator prefix is provided, we'll try to guess what you mean like this:
  912. * </p><p>
  913. * 1.) if windowID is null, (or the string "null") then it is assumed the user is referring to the original window instantiated by the browser).
  914. * </p><p>
  915. * 2.) if the value of the "windowID" parameter is a JavaScript variable name in the current application window, then it is assumed
  916. * that this variable contains the return value from a call to the JavaScript window.open() method.
  917. * </p><p>
  918. * 3.) Otherwise, selenium looks in a hash it maintains that maps string names to window "names".
  919. * </p><p>
  920. * 4.) If <i>that</i> fails, we'll try looping over all of the known windows to try to find the appropriate "title".
  921. * Since "title" is not necessarily unique, this may have unexpected behavior.
  922. * </p><p>
  923. * If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messages
  924. * which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages
  925. * like the following for each window as it is opened:
  926. * </p><p>
  927. * <code>debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"</code>
  928. * </p><p>
  929. * In some cases, Selenium will be unable to intercept a call to window.open (if the call occurs during or before the "onLoad" event, for example).
  930. * (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using
  931. * an empty (blank) url, like this: openWindow("", "myFunnyWindow").
  932. * </p>
  933. *
  934. * @access public
  935. * @param string $windowID the JavaScript window ID of the window to select
  936. */
  937. public function selectWindow($windowID)
  938. {
  939. $this->doCommand("selectWindow", array($windowID));
  940. }
  941. /**
  942. * Selects a frame within the current window. (You may invoke this command
  943. * multiple times to select nested frames.) To select the parent frame, use
  944. * "relative=parent" as a locator; to select the top frame, use "relative=top".
  945. * You can also select a frame by its 0-based index number; select the first frame with
  946. * "index=0", or the third frame with "index=2".
  947. *
  948. * <p>
  949. * You may also use a DOM expression to identify the frame you want directly,
  950. * like this: <code>dom=frames["main"].frames["subframe"]</code>
  951. * </p>
  952. *
  953. * @access public
  954. * @param string $locator an element locator identifying a frame or iframe
  955. */
  956. public function selectFrame($locator)
  957. {
  958. $this->doCommand("selectFrame", array($locator));
  959. }
  960. /**
  961. * Determine whether current/locator identify the frame containing this running code.
  962. *
  963. * <p>
  964. * This is useful in proxy injection mode, where this code runs in every
  965. * browser frame and window, and sometimes the selenium server needs to identify
  966. * the "current" frame. In this case, when the test calls selectFrame, this
  967. * routine is called for each frame to figure out which one has been selected.
  968. * The selected frame will return true, while all others will return false.
  969. * </p>
  970. *
  971. * @access public
  972. * @param string $currentFrameString starting frame
  973. * @param string $target new frame (which might be relative to the current one)
  974. * @return boolean true if the new frame is this code's window
  975. */
  976. public function getWhetherThisFrameMatchFrameExpression($currentFrameString, $target)
  977. {
  978. return $this->getBoolean("getWhetherThisFrameMatchFrameExpression", array($currentFrameString, $target));
  979. }
  980. /**
  981. * Determine whether currentWindowString plus target identify the window containing this running code.
  982. *
  983. * <p>
  984. * This is useful in proxy injection mode, where this code runs in every
  985. * browser frame and window, and sometimes the selenium server needs to identify
  986. * the "current" window. In this case, when the test calls selectWindow, this
  987. * routine is called for each window to figure out which one has been selected.
  988. * The selected window will return true, while all others will return false.
  989. * </p>
  990. *
  991. * @access public
  992. * @param string $currentWindowString starting window
  993. * @param string $target new window (which might be relative to the current one, e.g., "_parent")
  994. * @return boolean true if the new window is this code's window
  995. */
  996. public function getWhetherThisWindowMatchWindowExpression($currentWindowString, $target)
  997. {
  998. return $this->getBoolean("getWhetherThisWindowMatchWindowExpression", array($currentWindowString, $target));
  999. }
  1000. /**
  1001. * Waits for a popup window to appear and load up.
  1002. *
  1003. * @access public
  1004. * @param string $windowID the JavaScript window "name" of the window that will appear (not the text of the title bar)
  1005. * @param string $timeout a timeout in milliseconds, after which the action will return with an error
  1006. */
  1007. public function waitForPopUp($windowID, $timeout)
  1008. {
  1009. $this->doCommand("waitForPopUp", array($windowID, $timeout));
  1010. }
  1011. /**
  1012. * By default, Selenium's overridden window.confirm() function will
  1013. * return true, as if the user had manually clicked OK; after running
  1014. * this command, the next call to confirm() will return false, as if
  1015. * the user had clicked Cancel. Selenium will then resume using the
  1016. * default behavior for future confirmations, automatically returning
  1017. * true (OK) unless/until you explicitly call this command for each
  1018. * confirmation.
  1019. *
  1020. * @access public
  1021. */
  1022. public function chooseCancelOnNextConfirmation()
  1023. {
  1024. $this->doCommand("chooseCancelOnNextConfirmation", array());
  1025. }
  1026. /**
  1027. * Undo the effect of calling chooseCancelOnNextConfirmation. Note
  1028. * that Selenium's overridden window.confirm() function will normally automatically
  1029. * return true, as if the user had manually clicked OK, so you shouldn't
  1030. * need to use this command unless for some reason you need to change
  1031. * your mind prior to the next confirmation. After any confirmation, Selenium will resume using the
  1032. * default behavior for future confirmations, automatically returning
  1033. * true (OK) unless/until you explicitly call chooseCancelOnNextConfirmation for each
  1034. * confirmation.
  1035. *
  1036. * @access public
  1037. */
  1038. public function chooseOkOnNextConfirmation()
  1039. {
  1040. $this->doCommand("chooseOkOnNextConfirmation", array());
  1041. }
  1042. /**
  1043. * Instructs Selenium to return the specified answer string in response to
  1044. * the next JavaScript prompt [window.prompt()].
  1045. *
  1046. * @access public
  1047. * @param string $answer the answer to give in response to the prompt pop-up
  1048. */
  1049. public function answerOnNextPrompt($answer)
  1050. {
  1051. $this->doCommand("answerOnNextPrompt", array($answer));
  1052. }
  1053. /**
  1054. * Simulates the user clicking the "back" button on their browser.
  1055. *
  1056. * @access public
  1057. */
  1058. public function goBack()
  1059. {
  1060. $this->doCommand("goBack", array());
  1061. }
  1062. /**
  1063. * Simulates the user clicking the "Refresh" button on their browser.
  1064. *
  1065. * @access public
  1066. */
  1067. public function refresh()
  1068. {
  1069. $this->doCommand("refresh", array());
  1070. }
  1071. /**
  1072. * Simulates the user clicking the "close" button in the titlebar of a popup
  1073. * window or tab.
  1074. *
  1075. * @access public
  1076. */
  1077. public function close()
  1078. {
  1079. $this->doCommand("close", array());
  1080. }
  1081. /**
  1082. * Has an alert occurred?
  1083. *
  1084. * <p>
  1085. *
  1086. * This function never throws an exception
  1087. *
  1088. * </p>
  1089. *
  1090. * @access public
  1091. * @return boolean true if there is an alert
  1092. */
  1093. public function isAlertPresent()
  1094. {
  1095. return $this->getBoolean("isAlertPresent", array());
  1096. }
  1097. /**
  1098. * Has a prompt occurred?
  1099. *
  1100. * <p>
  1101. *
  1102. * This function never throws an exception
  1103. *
  1104. * </p>
  1105. *
  1106. * @access public
  1107. * @return boolean true if there is a pending prompt
  1108. */
  1109. public function isPromptPresent()
  1110. {
  1111. return $this->getBoolean("isPromptPresent", array());
  1112. }
  1113. /**
  1114. * Has confirm() been called?
  1115. *
  1116. * <p>
  1117. *
  1118. * This function never throws an exception
  1119. *
  1120. * </p>
  1121. *
  1122. * @access public
  1123. * @return boolean true if there is a pending confirmation
  1124. */
  1125. public function isConfirmationPresent()
  1126. {
  1127. return $this->getBoolean("isConfirmationPresent", array());
  1128. }
  1129. /**
  1130. * Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
  1131. *
  1132. * <p>
  1133. * Getting an alert has the same effect as manually clicking OK. If an
  1134. * alert is generated but you do not get/verify it, the next Selenium action
  1135. * will fail.
  1136. * </p><p>
  1137. * NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
  1138. * dialog.
  1139. * </p><p>
  1140. * NOTE: Selenium does NOT support JavaScript alerts that are generated in a
  1141. * page's onload() event handler. In this case a visible dialog WILL be
  1142. * generated and Selenium will hang until someone manually clicks OK.
  1143. * </p>
  1144. *
  1145. * @access public
  1146. * @return string The message of the most recent JavaScript alert
  1147. */
  1148. public function getAlert()
  1149. {
  1150. return $this->getString("getAlert", array());
  1151. }
  1152. /**
  1153. * Retrieves the message of a JavaScript confirmation dialog generated during
  1154. * the previous action.
  1155. *
  1156. * <p>
  1157. *
  1158. * By default, the confirm function will return true, having the same effect
  1159. * as manually clicking OK. This can be changed by prior execution of the
  1160. * chooseCancelOnNextConfirmation command. If an confirmation is generated
  1161. * but you do not get/verify it, the next Selenium action will fail.
  1162. *
  1163. * </p><p>
  1164. *
  1165. * NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
  1166. * dialog.
  1167. *
  1168. * </p><p>
  1169. *
  1170. * NOTE: Selenium does NOT support JavaScript confirmations that are
  1171. * generated in a page's onload() event handler. In this case a visible
  1172. * dialog WILL be generated and Selenium will hang until you manually click
  1173. * OK.
  1174. *
  1175. * </p>
  1176. *
  1177. * @access public
  1178. * @return string the message of the most recent JavaScript confirmation dialog
  1179. */
  1180. public function getConfirmation()
  1181. {
  1182. return $this->getString("getConfirmation", array());
  1183. }
  1184. /**
  1185. * Retrieves the message of a JavaScript question prompt dialog generated during
  1186. * the previous action.
  1187. *
  1188. * <p>
  1189. * Successful handling of the prompt requires prior execution of the
  1190. * answerOnNextPrompt command. If a prompt is generated but you
  1191. * do not get/verify it, the next Selenium action will fail.
  1192. * </p><p>
  1193. * NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
  1194. * dialog.
  1195. * </p><p>
  1196. * NOTE: Selenium does NOT support JavaScript prompts that are generated in a
  1197. * page's onload() event handler. In this case a visible dialog WILL be
  1198. * generated and Selenium will hang until someone manually clicks OK.
  1199. * </p>
  1200. *
  1201. * @access public
  1202. * @return string the message of the most recent JavaScript question prompt
  1203. */
  1204. public function getPrompt()
  1205. {
  1206. return $this->getString("getPrompt", array());
  1207. }
  1208. /**
  1209. * Gets the absolute URL of the current page.
  1210. *
  1211. * @access public
  1212. * @return string the absolute URL of the current page
  1213. */
  1214. public function getLocation()
  1215. {
  1216. return $this->getString("getLocation", array());
  1217. }
  1218. /**
  1219. * Gets the title of the current page.
  1220. *
  1221. * @access public
  1222. * @return string the title of the current page
  1223. */
  1224. public function getTitle()
  1225. {
  1226. return $this->getString("getTitle", array());
  1227. }
  1228. /**
  1229. * Gets the entire text of the page.
  1230. *
  1231. * @access public
  1232. * @return string the entire text of the page
  1233. */
  1234. public function getBodyText()
  1235. {
  1236. return $this->getString("getBodyText", array());
  1237. }
  1238. /**
  1239. * Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
  1240. * For checkbox/radio elements, the value will be "on" or "off" depending on
  1241. * whether the element is checked or not.
  1242. *
  1243. * @access public
  1244. * @param string $locator an element locator
  1245. * @return string the element value, or "on/off" for checkbox/radio elements
  1246. */
  1247. public function getValue($locator)
  1248. {
  1249. return $this->getString("getValue", array($locator));
  1250. }
  1251. /**
  1252. * Gets the text of an element. This works for any element that contains
  1253. * text. This command uses either the textContent (Mozilla-like browsers) or
  1254. * the innerText (IE-like browsers) of the element, which is the rendered
  1255. * text shown to the user.
  1256. *
  1257. * @access public
  1258. * @param string $locator an element locator
  1259. * @return string the text of the element
  1260. */
  1261. public function getText($locator)
  1262. {
  1263. return $this->getString("getText", array($locator));
  1264. }
  1265. /**
  1266. * Briefly changes the backgroundColor of the specified element yellow. Useful for debugging.
  1267. *
  1268. * @access public
  1269. * @param string $locator an element locator
  1270. */
  1271. public function highlight($locator)
  1272. {
  1273. $this->doCommand("highlight", array($locator));
  1274. }
  1275. /**
  1276. * Gets the result of evaluating the specified JavaScript snippet. The snippet may
  1277. * have multiple lines, but only the result of the last line will be returned.
  1278. *
  1279. * <p>
  1280. * Note that, by default, the snippet will run in the context of the "selenium"
  1281. * object itself, so <code>this</code> will refer to the Selenium object. Use <code>window</code> to
  1282. * refer to the window of your application, e.g. <code>window.document.getElementById('foo')</code>
  1283. * </p><p>
  1284. * If you need to use
  1285. * a locator to refer to a single element in your application page, you can
  1286. * use <code>this.browserbot.findElement("id=foo")</code> where "id=foo" is your locator.
  1287. * </p>
  1288. *
  1289. * @access public
  1290. * @param string $script the JavaScript snippet to run
  1291. * @return string the results of evaluating the snippet
  1292. */
  1293. public function getEval($script)
  1294. {
  1295. return $this->getString("getEval", array($script));
  1296. }
  1297. /**
  1298. * Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
  1299. *
  1300. * @access public
  1301. * @param string $locator an element locator pointing to a checkbox or radio button
  1302. * @return boolean true if the checkbox is checked, false otherwise
  1303. */
  1304. public function isChecked($locator)
  1305. {
  1306. return $this->getBoolean("isChecked", array($locator));
  1307. }
  1308. /**
  1309. * Gets the text from a cell of a table. The cellAddress syntax
  1310. * tableLocator.row.column, where row and column start at 0.
  1311. *
  1312. * @access public
  1313. * @param string $tableCellAddress a cell address, e.g. "foo.1.4"
  1314. * @return string the text from the specified cell
  1315. */
  1316. public function getTable($tableCellAddress)
  1317. {
  1318. return $this->getString("getTable", array($tableCellAddress));
  1319. }
  1320. /**
  1321. * Gets all option labels (visible text) for selected options in the specified select or multi-select element.
  1322. *
  1323. * @access public
  1324. * @param string $selectLocator an element locator identifying a drop-down menu
  1325. * @return array an array of all selected option labels in the specified select drop-down
  1326. */
  1327. public function getSelectedLabels($selectLocator)
  1328. {
  1329. return $this->getStringArray("getSelectedLabels", array($selectLocator));
  1330. }
  1331. /**
  1332. * Gets option label (visible text) for selected option in the specified select element.
  1333. *
  1334. * @access public
  1335. * @param string $selectLocator an element locator identifying a drop-down menu
  1336. * @return string the selected option label in the specified select drop-down
  1337. */
  1338. public function getSelectedLabel($selectLocator)
  1339. {
  1340. return $this->getString("getSelectedLabel", array($selectLocator));
  1341. }
  1342. /**
  1343. * Gets all option values (value attributes) for selected options in the specified select or multi-select element.
  1344. *
  1345. * @access public
  1346. * @param string $selectLocator an element locator identifying a drop-down menu
  1347. * @return array an array of all selected option values in the specified select drop-down
  1348. */
  1349. public function getSelectedValues($selectLocator)
  1350. {
  1351. return $this->getStringArray("getSelectedValues", array($selectLocator));
  1352. }
  1353. /**
  1354. * Gets option value (value attribute) for selected option in the specified select element.
  1355. *
  1356. * @access public
  1357. * @param string $selectLocator an element locator identifying a drop-down menu
  1358. * @return string the selected option value in the specified select drop-down
  1359. */
  1360. public function getSelectedValue($selectLocator)
  1361. {
  1362. return $this->getString("getSelectedValue", array($selectLocator));
  1363. }
  1364. /**
  1365. * Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
  1366. *
  1367. * @access public
  1368. * @param string $selectLocator an element locator identifying a drop-down menu
  1369. * @return array an array of all selected option indexes in the specified select drop-down
  1370. */
  1371. public function getSelectedIndexes($selectLocator)
  1372. {
  1373. return $this->getStringArray("getSelectedIndexes", array($selectLocator));
  1374. }
  1375. /**
  1376. * Gets option index (option number, starting at 0) for selected option in the specified select element.
  1377. *
  1378. * @access public
  1379. * @param string $selectLocator an element locator identifying a drop-down menu
  1380. * @return string the selected option index in the specified select drop-down
  1381. */
  1382. public function getSelectedIndex($selectLocator)
  1383. {
  1384. return $this->getString("getSelectedIndex", array($selectLocator));
  1385. }
  1386. /**
  1387. * Gets all option element IDs for selected options in the specified select or multi-select element.
  1388. *
  1389. * @access public
  1390. * @param string $selectLocator an element locator identifying a drop-down menu
  1391. * @return array an array of all selected option IDs in the specified select drop-down
  1392. */
  1393. public function getSelectedIds($selectLocator)
  1394. {
  1395. return $this->getStringArray("getSelectedIds", array($selectLocator));
  1396. }
  1397. /**
  1398. * Gets option element ID for selected option in the specified select element.
  1399. *
  1400. * @access public
  1401. * @param string $selectLocator an element locator identifying a drop-down menu
  1402. * @return string the selected option ID in the specified select drop-down
  1403. */
  1404. public function getSelectedId($selectLocator)
  1405. {
  1406. return $this->getString("getSelectedId", array($selectLocator));
  1407. }
  1408. /**
  1409. * Determines whether some option in a drop-down menu is selected.
  1410. *
  1411. * @access public
  1412. * @param string $selectLocator an element locator identifying a drop-down menu
  1413. * @return boolean true if some option has been selected, false otherwise
  1414. */
  1415. public function isSomethingSelected($selectLocator)
  1416. {
  1417. return $this->getBoolean("isSomethingSelected", array($selectLocator));
  1418. }
  1419. /**
  1420. * Gets all option labels in the specified select drop-down.
  1421. *
  1422. * @access public
  1423. * @param string $selectLocator an element locator identifying a drop-down menu
  1424. * @return array an array of all option labels in the specified select drop-down
  1425. */
  1426. public function getSelectOptions($selectLocator)
  1427. {
  1428. return $this->getStringArray("getSelectOptions", array($selectLocator));
  1429. }
  1430. /**
  1431. * Gets the value of an element attribute. The value of the attribute may
  1432. * differ across browsers (this is the case for the "style" attribute, for
  1433. * example).
  1434. *
  1435. * @access public
  1436. * @param string $attributeLocator an element locator followed by an @ sign and then the name of the attribute, e.g. "foo@bar"
  1437. * @return string the value of the specified attribute
  1438. */
  1439. public function getAttribute($attributeLocator)
  1440. {
  1441. return $this->getString("getAttribute", array($attributeLocator));
  1442. }
  1443. /**
  1444. * Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.
  1445. *
  1446. * @access public
  1447. * @param string $pattern a pattern to match with the text of the page
  1448. * @return boolean true if the pattern matches the text, false otherwise
  1449. */
  1450. public function isTextPresent($pattern)
  1451. {
  1452. return $this->getBoolean("isTextPresent", array($pattern));
  1453. }
  1454. /**
  1455. * Verifies that the specified element is somewhere on the page.
  1456. *
  1457. * @access public
  1458. * @param string $locator an element locator
  1459. * @return boolean true if the element is present, false otherwise
  1460. */
  1461. public function isElementPresent($locator)
  1462. {
  1463. return $this->getBoolean("isElementPresent", array($locator));
  1464. }
  1465. /**
  1466. * Determines if the specified element is visible. An
  1467. * element can be rendered invisible by setting the CSS "visibility"
  1468. * property to "hidden", or the "display" property to "none", either for the
  1469. * element itself or one if its ancestors. This method will fail if
  1470. * the element is not present.
  1471. *
  1472. * @access public
  1473. * @param string $locator an element locator
  1474. * @return boolean true if the specified element is visible, false otherwise
  1475. */
  1476. public function isVisible($locator)
  1477. {
  1478. return $this->getBoolean("isVisible", array($locator));
  1479. }
  1480. /**
  1481. * Determines whether the specified input element is editable, ie hasn't been disabled.
  1482. * This method will fail if the specified element isn't an input element.
  1483. *
  1484. * @access public
  1485. * @param string $locator an element locator
  1486. * @return boolean true if the input element is editable, false otherwise
  1487. */
  1488. public function isEditable($locator)
  1489. {
  1490. return $this->getBoolean("isEditable", array($locator));
  1491. }
  1492. /**
  1493. * Returns the IDs of all buttons on the page.
  1494. *
  1495. * <p>
  1496. * If a given button has no ID, it will appear as "" in this array.
  1497. * </p>
  1498. *
  1499. * @access public
  1500. * @return array the IDs of all buttons on the page
  1501. */
  1502. public function getAllButtons()
  1503. {
  1504. return $this->getStringArray("getAllButtons", array());
  1505. }
  1506. /**
  1507. * Returns the IDs of all links on the page.
  1508. *
  1509. * <p>
  1510. * If a given link has no ID, it will appear as "" in this array.
  1511. * </p>
  1512. *
  1513. * @access public
  1514. * @return array the IDs of all links on the page
  1515. */
  1516. public function getAllLinks()
  1517. {
  1518. return $this->getStringArray("getAllLinks", array());
  1519. }
  1520. /**
  1521. * Returns the IDs of all input fields on the page.
  1522. *
  1523. * <p>
  1524. * If a given field has no ID, it will appear as "" in this array.
  1525. * </p>
  1526. *
  1527. * @access public
  1528. * @return array the IDs of all field on the page
  1529. */
  1530. public function getAllFields()
  1531. {
  1532. return $this->getStringArray("getAllFields", array());
  1533. }
  1534. /**
  1535. * Returns every instance of some attribute from all known windows.
  1536. *
  1537. * @access public
  1538. * @param string $attributeName name of an attribute on the windows
  1539. * @return array the set of values of this attribute from all known windows.
  1540. */
  1541. public function getAttributeFromAllWindows($attributeName)
  1542. {
  1543. return $this->getStringArray("getAttributeFromAllWindows", array($attributeName));
  1544. }
  1545. /**
  1546. * deprecated - use dragAndDrop instead
  1547. *
  1548. * @access public
  1549. * @param string $locator an element locator
  1550. * @param string $movementsString offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
  1551. */
  1552. public function dragdrop($locator, $movementsString)
  1553. {
  1554. $this->doCommand("dragdrop", array($locator, $movementsString));
  1555. }
  1556. /**
  1557. * Configure the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
  1558. * <p>
  1559. * Setting this value to 0 means that we'll send a "mousemove" event to every single pixel
  1560. * in between the start location and the end location; that can be very slow, and may
  1561. * cause some browsers to force the JavaScript to timeout.
  1562. * </p><p>
  1563. * If the mouse speed is greater than the distance between the two dragged objects, we'll
  1564. * just send one "mousemove" at the start location and then one final one at the end location.
  1565. * </p>
  1566. *
  1567. * @access public
  1568. * @param string $pixels the number of pixels between "mousemove" events
  1569. */
  1570. public function setMouseSpeed($pixels)
  1571. {
  1572. $this->doCommand("setMouseSpeed", array($pixels));
  1573. }
  1574. /**
  1575. * Returns the number of pixels between "mousemove" events during dragAndDrop commands (default=10).
  1576. *
  1577. * @access public
  1578. * @return number the number of pixels between "mousemove" events during dragAndDrop commands (default=10)
  1579. */
  1580. public function getMouseSpeed()
  1581. {
  1582. return $this->getNumber("getMouseSpeed", array());
  1583. }
  1584. /**
  1585. * Drags an element a certain distance and then drops it
  1586. *
  1587. * @access public
  1588. * @param string $locator an element locator
  1589. * @param string $movementsString offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
  1590. */
  1591. public function dragAndDrop($locator, $movementsString)
  1592. {
  1593. $this->doCommand("dragAndDrop", array($locator, $movementsString));
  1594. }
  1595. /**
  1596. * Drags an element and drops it on another element
  1597. *
  1598. * @access public
  1599. * @param string $locatorOfObjectToBeDragged an element to be dragged
  1600. * @param string $locatorOfDragDestinationObject an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
  1601. */
  1602. public function dragAndDropToObject($locatorOfObjectToBeDragged, $locatorOfDragDestinationObject)
  1603. {
  1604. $this->doCommand("dragAndDropToObject", array($locatorOfObjectToBeDragged, $locatorOfDragDestinationObject));
  1605. }
  1606. /**
  1607. * Gives focus to the currently selected window
  1608. *
  1609. * @access public
  1610. */
  1611. public function windowFocus()
  1612. {
  1613. $this->doCommand("windowFocus", array());
  1614. }
  1615. /**
  1616. * Resize currently selected window to take up the entire screen
  1617. *
  1618. * @access public
  1619. */
  1620. public function windowMaximize()
  1621. {
  1622. $this->doCommand("windowMaximize", array());
  1623. }
  1624. /**
  1625. * Returns the IDs of all windows that the browser knows about.
  1626. *
  1627. * @access public
  1628. * @return array the IDs of all windows that the browser knows about.
  1629. */
  1630. public function getAllWindowIds()
  1631. {
  1632. return $this->getStringArray("getAllWindowIds", array());
  1633. }
  1634. /**
  1635. * Returns the names of all windows that the browser knows about.
  1636. *
  1637. * @access public
  1638. * @return array the names of all windows that the browser knows about.
  1639. */
  1640. public function getAllWindowNames()
  1641. {
  1642. return $this->getStringArray("getAllWindowNames", array());
  1643. }
  1644. /**
  1645. * Returns the titles of all windows that the browser knows about.
  1646. *
  1647. * @access public
  1648. * @return array the titles of all windows that the browser knows about.
  1649. */
  1650. public function getAllWindowTitles()
  1651. {
  1652. return $this->getStringArray("getAllWindowTitles", array());
  1653. }
  1654. /**
  1655. * Returns the entire HTML source between the opening and
  1656. * closing "html" tags.
  1657. *
  1658. * @access public
  1659. * @return string the entire HTML source
  1660. */
  1661. public function getHtmlSource()
  1662. {
  1663. return $this->getString("getHtmlSource", array());
  1664. }
  1665. /**
  1666. * Moves the text cursor to the specified position in the given input element or textarea.
  1667. * This method will fail if the specified element isn't an input element or textarea.
  1668. *
  1669. * @access public
  1670. * @param string $locator an element locator pointing to an input element or textarea
  1671. * @param string $position the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
  1672. */
  1673. public function setCursorPosition($locator, $position)
  1674. {
  1675. $this->doCommand("setCursorPosition", array($locator, $position));
  1676. }
  1677. /**
  1678. * Get the relative index of an element to its parent (starting from 0). The comment node and empty text node
  1679. * will be ignored.
  1680. *
  1681. * @access public
  1682. * @param string $locator an element locator pointing to an element
  1683. * @return number of relative index of the element to its parent (starting from 0)
  1684. */
  1685. public function getElementIndex($locator)
  1686. {
  1687. return $this->getNumber("getElementIndex", array($locator));
  1688. }
  1689. /**
  1690. * Check if these two elements have same parent and are ordered siblings in the DOM. Two same elements will
  1691. * not be considered ordered.
  1692. *
  1693. * @access public
  1694. * @param string $locator1 an element locator pointing to the first element
  1695. * @param string $locator2 an element locator pointing to the second element
  1696. * @return boolean true if element1 is the previous sibling of element2, false otherwise
  1697. */
  1698. public function isOrdered($locator1, $locator2)
  1699. {
  1700. return $this->getBoolean("isOrdered", array($locator1, $locator2));
  1701. }
  1702. /**
  1703. * Retrieves the horizontal position of an element
  1704. *
  1705. * @access public
  1706. * @param string $locator an element locator pointing to an element OR an element itself
  1707. * @return number of pixels from the edge of the frame.
  1708. */
  1709. public function getElementPositionLeft($locator)
  1710. {
  1711. return $this->getNumber("getElementPositionLeft", array($locator));
  1712. }
  1713. /**
  1714. * Retrieves the vertical position of an element
  1715. *
  1716. * @access public
  1717. * @param string $locator an element locator pointing to an element OR an element itself
  1718. * @return number of pixels from the edge of the frame.
  1719. */
  1720. public function getElementPositionTop($locator)
  1721. {
  1722. return $this->getNumber("getElementPositionTop", array($locator));
  1723. }
  1724. /**
  1725. * Retrieves the width of an element
  1726. *
  1727. * @access public
  1728. * @param string $locator an element locator pointing to an element
  1729. * @return number width of an element in pixels
  1730. */
  1731. public function getElementWidth($locator)
  1732. {
  1733. return $this->getNumber("getElementWidth", array($locator));
  1734. }
  1735. /**
  1736. * Retrieves the height of an element
  1737. *
  1738. * @access public
  1739. * @param string $locator an element locator pointing to an element
  1740. * @return number height of an element in pixels
  1741. */
  1742. public function getElementHeight($locator)
  1743. {
  1744. return $this->getNumber("getElementHeight", array($locator));
  1745. }
  1746. /**
  1747. * Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
  1748. *
  1749. * <p>
  1750. * Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
  1751. * return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as SEL-243.
  1752. * </p>
  1753. * This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
  1754. *
  1755. * @access public
  1756. * @param string $locator an element locator pointing to an input element or textarea
  1757. * @return number the numerical position of the cursor in the field
  1758. */
  1759. public function getCursorPosition($locator)
  1760. {
  1761. return $this->getNumber("getCursorPosition", array($locator));
  1762. }
  1763. /**
  1764. * Returns the specified expression.
  1765. *
  1766. * <p>
  1767. * This is useful because of JavaScript preprocessing.
  1768. * It is used to generate commands like assertExpression and waitForExpression.
  1769. * </p>
  1770. *
  1771. * @access public
  1772. * @param string $expression the value to return
  1773. * @return string the value passed in
  1774. */
  1775. public function getExpression($expression)
  1776. {
  1777. return $this->getString("getExpression", array($expression));
  1778. }
  1779. /**
  1780. * Returns the number of nodes that match the specified xpath, eg. "//table" would give
  1781. * the number of tables.
  1782. *
  1783. * @access public
  1784. * @param string $xpath the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
  1785. * @return number the number of nodes that match the specified xpath
  1786. */
  1787. public function getXpathCount($xpath)
  1788. {
  1789. return $this->getNumber("getXpathCount", array($xpath));
  1790. }
  1791. /**
  1792. * Temporarily sets the "id" attribute of the specified element, so you can locate it in the future
  1793. * using its ID rather than a slow/complicated XPath. This ID will disappear once the page is
  1794. * reloaded.
  1795. *
  1796. * @access public
  1797. * @param string $locator an element locator pointing to an element
  1798. * @param string $identifier a string to be used as the ID of the specified element
  1799. */
  1800. public function assignId($locator, $identifier)
  1801. {
  1802. $this->doCommand("assignId", array($locator, $identifier));
  1803. }
  1804. /**
  1805. * Specifies whether Selenium should use the native in-browser implementation
  1806. * of XPath (if any native version is available); if you pass "false" to
  1807. * this function, we will always use our pure-JavaScript xpath library.
  1808. * Using the pure-JS xpath library can improve the consistency of xpath
  1809. * element locators between different browser vendors, but the pure-JS
  1810. * version is much slower than the native implementations.
  1811. *
  1812. * @access public
  1813. * @param string $allow boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
  1814. */
  1815. public function allowNativeXpath($allow)
  1816. {
  1817. $this->doCommand("allowNativeXpath", array($allow));
  1818. }
  1819. /**
  1820. * Specifies whether Selenium will ignore xpath attributes that have no
  1821. * value, i.e. are the empty string, when using the non-native xpath
  1822. * evaluation engine. You'd want to do this for performance reasons in IE.
  1823. * However, this could break certain xpaths, for example an xpath that looks
  1824. * for an attribute whose value is NOT the empty string.
  1825. *
  1826. * The hope is that such xpaths are relatively rare, but the user should
  1827. * have the option of using them. Note that this only influences xpath
  1828. * evaluation when using the ajaxslt engine (i.e. not "javascript-xpath").
  1829. *
  1830. * @access public
  1831. * @param string $ignore boolean, true means we'll ignore attributes without value at the expense of xpath "correctness"; false means we'll sacrifice speed for correctness.
  1832. */
  1833. public function ignoreAttributesWithoutValue($ignore)
  1834. {
  1835. $this->doCommand("ignoreAttributesWithoutValue", array($ignore));
  1836. }
  1837. /**
  1838. * Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
  1839. * The snippet may have multiple lines, but only the result of the last line
  1840. * will be considered.
  1841. *
  1842. * <p>
  1843. * Note that, by default, the snippet will be run in the runner's test window, not in the window
  1844. * of your application. To get the window of your application, you can use
  1845. * the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
  1846. * run your JavaScript in there
  1847. * </p>
  1848. *
  1849. * @access public
  1850. * @param string $script the JavaScript snippet to run
  1851. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1852. */
  1853. public function waitForCondition($script, $timeout)
  1854. {
  1855. $this->doCommand("waitForCondition", array($script, $timeout));
  1856. }
  1857. /**
  1858. * Specifies the amount of time that Selenium will wait for actions to complete.
  1859. *
  1860. * <p>
  1861. * Actions that require waiting include "open" and the "waitFor*" actions.
  1862. * </p>
  1863. * The default timeout is 30 seconds.
  1864. *
  1865. * @access public
  1866. * @param string $timeout a timeout in milliseconds, after which the action will return with an error
  1867. */
  1868. public function setTimeout($timeout)
  1869. {
  1870. $this->doCommand("setTimeout", array($timeout));
  1871. }
  1872. /**
  1873. * Waits for a new page to load.
  1874. *
  1875. * <p>
  1876. * You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
  1877. * (which are only available in the JS API).
  1878. * </p><p>
  1879. * Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
  1880. * flag when it first notices a page load. Running any other Selenium command after
  1881. * turns the flag to false. Hence, if you want to wait for a page to load, you must
  1882. * wait immediately after a Selenium command that caused a page-load.
  1883. * </p>
  1884. *
  1885. * @access public
  1886. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1887. */
  1888. public function waitForPageToLoad($timeout)
  1889. {
  1890. $this->doCommand("waitForPageToLoad", array($timeout));
  1891. }
  1892. /**
  1893. * Waits for a new frame to load.
  1894. *
  1895. * <p>
  1896. * Selenium constantly keeps track of new pages and frames loading,
  1897. * and sets a "newPageLoaded" flag when it first notices a page load.
  1898. * </p>
  1899. *
  1900. * See waitForPageToLoad for more information.
  1901. *
  1902. * @access public
  1903. * @param string $frameAddress FrameAddress from the server side
  1904. * @param string $timeout a timeout in milliseconds, after which this command will return with an error
  1905. */
  1906. public function waitForFrameToLoad($frameAddress, $timeout)
  1907. {
  1908. $this->doCommand("waitForFrameToLoad", array($frameAddress, $timeout));
  1909. }
  1910. /**
  1911. * Return all cookies of the current page under test.
  1912. *
  1913. * @access public
  1914. * @return string all cookies of the current page under test
  1915. */
  1916. public function getCookie()
  1917. {
  1918. return $this->getString("getCookie", array());
  1919. }
  1920. /**
  1921. * Returns the value of the cookie with the specified name, or throws an error if the cookie is not present.
  1922. *
  1923. * @access public
  1924. * @param string $name the name of the cookie
  1925. * @return string the value of the cookie
  1926. */
  1927. public function getCookieByName($name)
  1928. {
  1929. return $this->getString("getCookieByName", array($name));
  1930. }
  1931. /**
  1932. * Returns true if a cookie with the specified name is present, or false otherwise.
  1933. *
  1934. * @access public
  1935. * @param string $name the name of the cookie
  1936. * @return boolean true if a cookie with the specified name is present, or false otherwise.
  1937. */
  1938. public function isCookiePresent($name)
  1939. {
  1940. return $this->getBoolean("isCookiePresent", array($name));
  1941. }
  1942. /**
  1943. * Create a new cookie whose path and domain are same with those of current page
  1944. * under test, unless you specified a path for this cookie explicitly.
  1945. *
  1946. * @access public
  1947. * @param string $nameValuePair name and value of the cookie in a format "name=value"
  1948. * @param string $optionsString options for the cookie. Currently supported options include 'path', 'max_age' and 'domain'. the optionsString's format is "path=/path/, max_age=60, domain=.foo.com". The order of options are irrelevant, the unit of the value of 'max_age' is second. Note that specifying a domain that isn't a subset of the current domain will usually fail.
  1949. */
  1950. public function createCookie($nameValuePair, $optionsString)
  1951. {
  1952. $this->doCommand("createCookie", array($nameValuePair, $optionsString));
  1953. }
  1954. /**
  1955. * Delete a named cookie with specified path and domain. Be careful; to delete a cookie, you
  1956. * need to delete it using the exact same path and domain that were used to create the cookie.
  1957. * If the path is wrong, or the domain is wrong, the cookie simply won't be deleted. Also
  1958. * note that specifying a domain that isn't a subset of the current domain will usually fail.
  1959. *
  1960. * Since there's no way to discover at runtime the original path and domain of a given cookie,
  1961. * we've added an option called 'recurse' to try all sub-domains of the current domain with
  1962. * all paths that are a subset of the current path. Beware; this option can be slow. In
  1963. * big-O notation, it operates in O(n*m) time, where n is the number of dots in the domain
  1964. * name and m is the number of slashes in the path.
  1965. *
  1966. * @access public
  1967. * @param string $name the name of the cookie to be deleted
  1968. * @param string $optionsString options for the cookie. Currently supported options include 'path', 'domain' and 'recurse.' The optionsString's format is "path=/path/, domain=.foo.com, recurse=true". The order of options are irrelevant. Note that specifying a domain that isn't a subset of the current domain will usually fail.
  1969. */
  1970. public function deleteCookie($name, $optionsString)
  1971. {
  1972. $this->doCommand("deleteCookie", array($name, $optionsString));
  1973. }
  1974. /**
  1975. * Calls deleteCookie with recurse=true on all cookies visible to the current page.
  1976. * As noted on the documentation for deleteCookie, recurse=true can be much slower
  1977. * than simply deleting the cookies using a known domain/path.
  1978. *
  1979. * @access public
  1980. */
  1981. public function deleteAllVisibleCookies()
  1982. {
  1983. $this->doCommand("deleteAllVisibleCookies", array());
  1984. }
  1985. /**
  1986. * Sets the threshold for browser-side logging messages; log messages beneath this threshold will be discarded.
  1987. * Valid logLevel strings are: "debug", "info", "warn", "error" or "off".
  1988. * To see the browser logs, you need to
  1989. * either show the log window in GUI mode, or enable browser-side logging in Selenium RC.
  1990. *
  1991. * @access public
  1992. * @param string $logLevel one of the following: "debug", "info", "warn", "error" or "off"
  1993. */
  1994. public function setBrowserLogLevel($logLevel)
  1995. {
  1996. $this->doCommand("setBrowserLogLevel", array($logLevel));
  1997. }
  1998. /**
  1999. * Creates a new "script" tag in the body of the current test window, and
  2000. * adds the specified text into the body of the command. Scripts run in
  2001. * this way can often be debugged more easily than scripts executed using
  2002. * Selenium's "getEval" command. Beware that JS exceptions thrown in these script
  2003. * tags aren't managed by Selenium, so you should probably wrap your script
  2004. * in try/catch blocks if there is any chance that the script will throw
  2005. * an exception.
  2006. *
  2007. * @access public
  2008. * @param string $script the JavaScript snippet to run
  2009. */
  2010. public function runScript($script)
  2011. {
  2012. $this->doCommand("runScript", array($script));
  2013. }
  2014. /**
  2015. * Defines a new function for Selenium to locate elements on the page.
  2016. * For example,
  2017. * if you define the strategy "foo", and someone runs click("foo=blah"), we'll
  2018. * run your function, passing you the string "blah", and click on the element
  2019. * that your function
  2020. * returns, or throw an "Element not found" error if your function returns null.
  2021. *
  2022. * We'll pass three arguments to your function:
  2023. *
  2024. * <ul>
  2025. *
  2026. * <li>
  2027. * locator: the string the user passed in
  2028. * </li>
  2029. * <li>
  2030. * inWindow: the currently selected window
  2031. * </li>
  2032. * <li>
  2033. * inDocument: the currently selected document
  2034. * </li>
  2035. * </ul>
  2036. * The function must return null if the element can't be found.
  2037. *
  2038. * @access public
  2039. * @param string $strategyName the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation.
  2040. * @param string $functionDefinition a string defining the body of a function in JavaScript. For example: <code>return inDocument.getElementById(locator);</code>
  2041. */
  2042. public function addLocationStrategy($strategyName, $functionDefinition)
  2043. {
  2044. $this->doCommand("addLocationStrategy", array($strategyName, $functionDefinition));
  2045. }
  2046. /**
  2047. * Saves the entire contents of the current window canvas to a PNG file.
  2048. * Currently this only works in Mozilla and when running in chrome mode.
  2049. * Contrast this with the captureScreenshot command, which captures the
  2050. * contents of the OS viewport (i.e. whatever is currently being displayed
  2051. * on the monitor), and is implemented in the RC only. Implementation
  2052. * mostly borrowed from the Screengrab! Firefox extension. Please see
  2053. * http://www.screengrab.org for details.
  2054. *
  2055. * @access public
  2056. * @param string $filename the path to the file to persist the screenshot as. No filename extension will be appended by default. Directories will not be created if they do not exist, and an exception will be thrown, possibly by native code.
  2057. */
  2058. public function captureEntirePageScreenshot($filename)
  2059. {
  2060. $this->doCommand("captureEntirePageScreenshot", array($filename));
  2061. }
  2062. /**
  2063. * Writes a message to the status bar and adds a note to the browser-side
  2064. * log.
  2065. *
  2066. * @access public
  2067. * @param string $context the message to be sent to the browser
  2068. */
  2069. public function setContext($context)
  2070. {
  2071. $this->doCommand("setContext", array($context));
  2072. }
  2073. /**
  2074. * Sets a file input (upload) field to the file listed in fileLocator
  2075. *
  2076. * @access public
  2077. * @param string $fieldLocator an element locator
  2078. * @param string $fileLocator a URL pointing to the specified file. Before the file can be set in the input field (fieldLocator), Selenium RC may need to transfer the file to the local machine before attaching the file in a web page form. This is common in selenium grid configurations where the RC server driving the browser is not the same machine that started the test. Supported Browsers: Firefox ("*chrome") only.
  2079. */
  2080. public function attachFile($fieldLocator, $fileLocator)
  2081. {
  2082. $this->doCommand("attachFile", array($fieldLocator, $fileLocator));
  2083. }
  2084. /**
  2085. * Captures a PNG screenshot to the specified file.
  2086. *
  2087. * @access public
  2088. * @param string $filename the absolute path to the file to be written, e.g. "c:\blah\screenshot.png"
  2089. */
  2090. public function captureScreenshot($filename)
  2091. {
  2092. $this->doCommand("captureScreenshot", array($filename));
  2093. }
  2094. /**
  2095. * Kills the running Selenium Server and all browser sessions. After you run this command, you will no longer be able to send
  2096. * commands to the server; you can't remotely start the server once it has been stopped. Normally
  2097. * you should prefer to run the "stop" command, which terminates the current browser session, rather than
  2098. * shutting down the entire server.
  2099. *
  2100. * @access public
  2101. */
  2102. public function shutDownSeleniumServer()
  2103. {
  2104. $this->doCommand("shutDownSeleniumServer", array());
  2105. }
  2106. /**
  2107. * Simulates a user pressing a key (without releasing it yet) by sending a native operating system keystroke.
  2108. * This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
  2109. * a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
  2110. * metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
  2111. * element, focus on the element first before running this command.
  2112. *
  2113. * @access public
  2114. * @param string $keycode an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
  2115. */
  2116. public function keyDownNative($keycode)
  2117. {
  2118. $this->doCommand("keyDownNative", array($keycode));
  2119. }
  2120. /**
  2121. * Simulates a user releasing a key by sending a native operating system keystroke.
  2122. * This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
  2123. * a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
  2124. * metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
  2125. * element, focus on the element first before running this command.
  2126. *
  2127. * @access public
  2128. * @param string $keycode an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
  2129. */
  2130. public function keyUpNative($keycode)
  2131. {
  2132. $this->doCommand("keyUpNative", array($keycode));
  2133. }
  2134. /**
  2135. * Simulates a user pressing and releasing a key by sending a native operating system keystroke.
  2136. * This function uses the java.awt.Robot class to send a keystroke; this more accurately simulates typing
  2137. * a key on the keyboard. It does not honor settings from the shiftKeyDown, controlKeyDown, altKeyDown and
  2138. * metaKeyDown commands, and does not target any particular HTML element. To send a keystroke to a particular
  2139. * element, focus on the element first before running this command.
  2140. *
  2141. * @access public
  2142. * @param string $keycode an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
  2143. */
  2144. public function keyPressNative($keycode)
  2145. {
  2146. $this->doCommand("keyPressNative", array($keycode));
  2147. }
  2148. protected function doCommand($verb, $args = array())
  2149. {
  2150. $url = sprintf('http://%s:%s/selenium-server/driver/?cmd=%s', $this->host, $this->port, urlencode($verb));
  2151. for ($i = 0; $i < count($args); $i++) {
  2152. $argNum = strval($i + 1);
  2153. $url .= sprintf('&%s=%s', $argNum, urlencode(trim($args[$i])));
  2154. }
  2155. if (isset($this->sessionId)) {
  2156. $url .= sprintf('&%s=%s', 'sessionId', $this->sessionId);
  2157. }
  2158. if (!$handle = fopen($url, 'r')) {
  2159. throw new Testing_Selenium_Exception('Cannot connected to Selenium RC Server');
  2160. }
  2161. stream_set_blocking($handle, false);
  2162. $response = stream_get_contents($handle);
  2163. fclose($handle);
  2164. if (!preg_match('/^OK/', $response)) {
  2165. throw new Testing_Selenium_Exception('The Response of the Selenium RC is invalid: ' . $response);
  2166. }
  2167. return $response;
  2168. }
  2169. private function getNumber($verb, $args = array())
  2170. {
  2171. $result = $this->getString($verb, $args);
  2172. if (!is_numeric($result)) {
  2173. throw new Testing_Selenium_Exception('result is not numeric.');
  2174. }
  2175. return $result;
  2176. }
  2177. private function getString($verb, $args = array())
  2178. {
  2179. try {
  2180. $result = $this->doCommand($verb, $args);
  2181. } catch (Testing_Selenium_Exception $e) {
  2182. return $e;
  2183. }
  2184. return (strlen($result) > 3) ? substr($result, 3) : '';
  2185. }
  2186. private function getStringArray($verb, $args = array())
  2187. {
  2188. $csv = $this->getString($verb, $args);
  2189. $token = '';
  2190. $tokens = array();
  2191. $letters = preg_split('//', $csv, -1, PREG_SPLIT_NO_EMPTY);
  2192. for ($i = 0; $i < count($letters); $i++) {
  2193. $letter = $letters[$i];
  2194. switch($letter) {
  2195. case '\\':
  2196. $i++;
  2197. $letter = $letters[$i];
  2198. $token = $token . $letter;
  2199. break;
  2200. case ',':
  2201. array_push($tokens, $token);
  2202. $token = '';
  2203. break;
  2204. default:
  2205. $token = $token . $letter;
  2206. break;
  2207. }
  2208. }
  2209. array_push($tokens, $token);
  2210. return $tokens;
  2211. }
  2212. private function getBoolean($verb, $args = array())
  2213. {
  2214. $result = $this->getString($verb, $args);
  2215. switch ($result) {
  2216. case 'true':
  2217. return true;
  2218. case 'false':
  2219. return false;
  2220. default:
  2221. throw new Testing_Selenium_Exception('result is neither "true" or "false": ' . $result);
  2222. }
  2223. }
  2224. }
  2225. ?>