PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/new/seleniumrc/selenium-remote-control-1.0-beta-2/selenium-php-client-driver-1.0-beta-2/PEAR/Testing/Selenium.php

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