WWW::Selenium - Perl Client for the Selenium Remote Control test tool
use WWW::Selenium; my $sel = WWW::Selenium->new( host => "localhost", port => 4444, browser => "*iexplore", browser_url => "http://www.google.com", ); $sel->start; $sel->open("http://www.google.com"); $sel->type("q", "hello world"); $sel->click("btnG"); $sel->wait_for_page_to_load(5000); print $sel->get_title; $sel->stop;
Selenium Remote Control (SRC) is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. SRC provides a Selenium Server, which can automatically start/stop/control any supported browser. It works by using Selenium Core, a pure-HTML+JS library that performs automated tasks in JavaScript; the Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest).
http://www.openqa.org/selenium-rc/
This module sends commands directly to the Server using simple HTTP GET/POST requests. Using this module together with the Selenium Server, you can automatically control any supported browser.
To use this module, you need to have already downloaded and started the Selenium Server. (The Selenium Server is a Java application.)
Element Locators tell Selenium which HTML element a command refers to.The format of a locator is:
locatorType=argument
We support the following strategies for locating elements:
The name may optionally be followed by one or more element-filters, separated from the name by whitespace. If the filterType is not specified, value is assumed.
foo()
{ return document.links[1]; }; foo();
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).
Without an explicit locator prefix, Selenium uses the following defaultstrategies:
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.
Filters look much like locators, ie.
filterType=argument
Supported element-filters are:
value=valuePattern
Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.
index=index
Selects a single element based on its position in the list (offset from zero).
Various Pattern syntaxes are available for matching string values:
If no pattern prefix is specified, Selenium assumes that it's a ``glob''pattern.
For commands that return multiple values (such as verifySelectOptions),the string being matched is a comma-separated list of the return values,where both commas and backslashes in the values are backslash-escaped.When providing a pattern, the optional matching syntax (i.e. glob,regexp, etc.) is specified once, as usual, at the beginning of thepattern.
The following methods are available:
WWW::Selenium
object, specifying a Selenium Server
host/port, a command to launch the browser, and a starting URL for the
browser.
Options:
host
port
browser_url
browser
or browser_start_command
This option may be any one of the following:
*firefox [absolute path]
firefoxDefaultPath
to the correct
path to Firefox.
*iexplore [absolute path]
iexploreDefaultPath
to the correct
path to Internet Explorer.
/path/to/my/browser [other arguments]
auto_stop
pause($timeout)
click($locator)
$locator is an element locator
double_click($locator)
$locator is an element locator
context_menu($locator)
$locator is an element locator
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
$locator is an element locator
$event_name is the event name, e.g. ``focus'' or ``blur''
focus($locator)
$locator is an element locator
$locator is an element locator
$key_sequence is 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''.
shift_key_down()
doShiftUp()
is called or a new page is loaded.
shift_key_up()
meta_key_down()
doMetaUp()
is called or a new page is loaded.
meta_key_up()
alt_key_down()
doAltUp()
is called or a new page is loaded.
alt_key_up()
control_key_down()
doControlUp()
is called or a new page is loaded.
control_key_up()
$locator is an element locator
$key_sequence is 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''.
$locator is an element locator
$key_sequence is 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''.
mouse_over($locator)
$locator is an element locator
mouse_out($locator)
$locator is an element locator
mouse_down($locator)
$locator is an element locator
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
mouse_up($locator)
$locator is an element locator
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
mouse_move($locator)
$locator is an element locator
$locator is an element locator
$coord_string is specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.
$locator is an element locator
$value is the value to type
Unlike the simple ``type'' command, which forces the specified value into the page directly, this commandmay or may not have any visible effect, even in cases where typing keys would normally have a visible effect.For example, if you use ``typeKeys'' on a form element, you may or may not see the results of what you typed inthe field.
In some cases, you may need to use the simple ``type'' command to set the value of the field and then the ``typeKeys'' command tosend the keystroke events corresponding to what you just typed.
$locator is an element locator
$value is the value to type
set_speed($value)
$value is the number of milliseconds to pause after operation
get_speed()
Returns the execution speed in milliseconds.
check($locator)
$locator is an element locator
uncheck($locator)
$locator is an element locator
If no option locator prefix is provided, the default behaviour is to match on label.
$select_locator is an element locator identifying a drop-down menu
$option_locator is an option locator (a label by default)
$locator is an element locator identifying a multi-select box
$option_locator is an option locator (a label by default)
$locator is an element locator identifying a multi-select box
$option_locator is an option locator (a label by default)
remove_all_selections($locator)
$locator is an element locator identifying a multi-select box
submit($form_locator)
$form_locator is an element locator for the form you want to submit
open($url)
$url is the URL to open; may be relative or absolute
$url is the URL to open, which can be blank
$window_id is the JavaScript window ID of the window to select
select_window($window_id)
If no window locator prefix is provided, we'll try to guess what you mean like this:
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).
2.) if the value of the ``windowID'' parameter is a JavaScript variable name in the current application window, then it is assumedthat this variable contains the return value from a call to the JavaScript window.open() method.
3.) Otherwise, selenium looks in a hash it maintains that maps string names to window ``names''.
4.) If that fails, we'll try looping over all of the known windows to try to find the appropriate ``title''.Since ``title'' is not necessarily unique, this may have unexpected behavior.
If you're having trouble figuring out the name of a window that you want to manipulate, look at the Selenium log messageswhich identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messageslike the following for each window as it is opened:
debug: window.open call intercepted; window ID (which you can use with selectWindow()) is "myNewWindow"
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).(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, usingan empty (blank) url, like this: openWindow(``'', ``myFunnyWindow'').
$window_id is the JavaScript window ID of the window to select
select_frame($locator)
dom=frames["main"].frames["subframe"]
$locator is an element locator identifying a frame or iframe
$current_frame_string is starting frame
$target is new frame (which might be relative to the current one)
Returns true if the new frame is this code's window
$current_window_string is starting window
$target is new window (which might be relative to the current one, e.g., ``_parent'')
Returns true if the new window is this code's window
$window_id is the JavaScript window ``name'' of the window that will appear (not the text of the title bar)
$timeout is a timeout in milliseconds, after which the action will return with an error
choose_cancel_on_next_confirmation()
confirm()
will return false, as ifthe user had clicked Cancel. Selenium will then resume using thedefault behavior for future confirmations, automatically returning true (OK) unless/until you explicitly call this command for eachconfirmation.
choose_ok_on_next_confirmation()
answer_on_next_prompt($answer)
$answer is the answer to give in response to the prompt pop-up
go_back()
refresh()
close()
is_alert_present()
Returns true if there is an alert
is_prompt_present()
Returns true if there is a pending prompt
is_confirmation_present()
confirm()
been called?
This function never throws an exception
Returns true if there is a pending confirmation
get_alert()
NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alertdialog.
NOTE: Selenium does NOT support JavaScript alerts that are generated in apage's onload()
event handler. In this case a visible dialog WILL begenerated and Selenium will hang until someone manually clicks OK.
Returns The message of the most recent JavaScript alert
get_confirmation()
NOTE: under Selenium, JavaScript confirmations will NOT pop up a visibledialog.
NOTE: Selenium does NOT support JavaScript confirmations that aregenerated in a page's onload()
event handler. In this case a visibledialog WILL be generated and Selenium will hang until you manually clickOK.
Returns the message of the most recent JavaScript confirmation dialog
get_prompt()
NOTE: under Selenium, JavaScript prompts will NOT pop up a visibledialog.
NOTE: Selenium does NOT support JavaScript prompts that are generated in apage's onload()
event handler. In this case a visible dialog WILL begenerated and Selenium will hang until someone manually clicks OK.
Returns the message of the most recent JavaScript question prompt
get_location()
Returns the absolute URL of the current page
get_title()
Returns the title of the current page
get_body_text()
Returns the entire text of the page
get_value($locator)
$locator is an element locator
Returns the element value, or ``on/off'' for checkbox/radio elements
get_text($locator)
$locator is an element locator
Returns the text of the element
highlight($locator)
$locator is an element locator
get_eval($script)
this
will refer to the Selenium object. Use window
torefer to the window of your application, e.g. window.document.getElementById('foo')
If you need to usea locator to refer to a single element in your application page, you canuse this.browserbot.findElement("id=foo")
where ``id=foo'' is your locator.
$script is the JavaScript snippet to run
Returns the results of evaluating the snippet
is_checked($locator)
$locator is an element locator pointing to a checkbox or radio button
Returns true if the checkbox is checked, false otherwise
get_table($table_cell_address)
$table_cell_address is a cell address, e.g. ``foo.1.4''
Returns the text from the specified cell
get_selected_labels($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns an array of all selected option labels in the specified select drop-down
get_selected_label($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns the selected option label in the specified select drop-down
get_selected_values($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns an array of all selected option values in the specified select drop-down
get_selected_value($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns the selected option value in the specified select drop-down
get_selected_indexes($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns an array of all selected option indexes in the specified select drop-down
get_selected_index($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns the selected option index in the specified select drop-down
get_selected_ids($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns an array of all selected option IDs in the specified select drop-down
get_selected_id($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns the selected option ID in the specified select drop-down
is_something_selected($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns true if some option has been selected, false otherwise
get_select_options($select_locator)
$select_locator is an element locator identifying a drop-down menu
Returns an array of all option labels in the specified select drop-down
get_attribute($attribute_locator)
$attribute_locator is an element locator followed by an @ sign and then the name of the attribute, e.g. ``foo@bar''
Returns the value of the specified attribute
is_text_present($pattern)
$pattern is a pattern to match with the text of the page
Returns true if the pattern matches the text, false otherwise
is_element_present($locator)
$locator is an element locator
Returns true if the element is present, false otherwise
is_visible($locator)
$locator is an element locator
Returns true if the specified element is visible, false otherwise
is_editable($locator)
$locator is an element locator
Returns true if the input element is editable, false otherwise
get_all_buttons()
Returns the IDs of all buttons on the page
get_all_links()
Returns the IDs of all links on the page
get_all_fields()
Returns the IDs of all field on the page
get_attribute_from_all_windows($attribute_name)
$attribute_name is name of an attribute on the windows
Returns the set of values of this attribute from all known windows.
$locator is an element locator
$movements_string is offset in pixels from the current location to which the element should be moved, e.g., ``+70,-300''
set_mouse_speed($pixels)
If the mouse speed is greater than the distance between the two dragged objects, we'lljust send one ``mousemove'' at the start location and then one final one at the end location.
$pixels is the number of pixels between ``mousemove'' events
get_mouse_speed()
Returns the number of pixels between ``mousemove'' events during dragAndDrop commands (default=10)
$locator is an element locator
$movements_string is offset in pixels from the current location to which the element should be moved, e.g., ``+70,-300''
$locator_of_object_to_be_dragged is an element to be dragged
$locator_of_drag_destination_object is an element whose location (i.e., whose center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
window_focus()
window_maximize()
get_all_window_ids()
Returns the IDs of all windows that the browser knows about.
get_all_window_names()
Returns the names of all windows that the browser knows about.
get_all_window_titles()
Returns the titles of all windows that the browser knows about.
get_html_source()
Returns the entire HTML source
$locator is an element locator pointing to an input element or textarea
$position is 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.
get_element_index($locator)
$locator is an element locator pointing to an element
Returns of relative index of the element to its parent (starting from 0)
$locator1 is an element locator pointing to the first element
$locator2 is an element locator pointing to the second element
Returns true if element1 is the previous sibling of element2, false otherwise
get_element_position_left($locator)
$locator is an element locator pointing to an element OR an element itself
Returns of pixels from the edge of the frame.
get_element_position_top($locator)
$locator is an element locator pointing to an element OR an element itself
Returns of pixels from the edge of the frame.
get_element_width($locator)
$locator is an element locator pointing to an element
Returns width of an element in pixels
get_element_height($locator)
$locator is an element locator pointing to an element
Returns height of an element in pixels
get_cursor_position($locator)
$locator is an element locator pointing to an input element or textarea
Returns the numerical position of the cursor in the field
get_expression($expression)
$expression is the value to return
Returns the value passed in
get_xpath_count($xpath)
$xpath is the xpath expression to evaluate. do NOT wrap this expression in a 'count()' function; we will do that for you.
Returns the number of nodes that match the specified xpath
$locator is an element locator pointing to an element
$identifier is a string to be used as the ID of the specified element
allow_native_xpath($allow)
$allow is boolean, true means we'll prefer to use native XPath; false means we'll only use JS XPath
ignore_attributes_without_value($ignore)
$ignore is boolean, true means we'll ignore attributes without value at the expense of xpath ``correctness''; false means we'll sacrifice speed for correctness.
selenium.browserbot.getCurrentWindow()
, and thenrun your JavaScript in there
$script is the JavaScript snippet to run
$timeout is a timeout in milliseconds, after which this command will return with an error
set_timeout($timeout)
$timeout is a timeout in milliseconds, after which the action will return with an error
wait_for_page_to_load($timeout)
Selenium constantly keeps track of new pages loading, and sets a ``newPageLoaded''flag when it first notices a page load. Running any other Selenium command afterturns the flag to false. Hence, if you want to wait for a page to load, you mustwait immediately after a Selenium command that caused a page-load.
$timeout is a timeout in milliseconds, after which this command will return with an error
$frame_address is FrameAddress from the server side
$timeout is a timeout in milliseconds, after which this command will return with an error
get_cookie()
Returns all cookies of the current page under test
get_cookie_by_name($name)
$name is the name of the cookie
Returns the value of the cookie
is_cookie_present($name)
$name is the name of the cookie
Returns true if a cookie with the specified name is present, or false otherwise.
$name_value_pair is name and value of the cookie in a format ``name=value''
$options_string is 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.
O(n*m)
time, where n is the number of dots in the domainname and m is the number of slashes in the path.
$name is the name of the cookie to be deleted
$options_string is 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.
delete_all_visible_cookies()
set_browser_log_level($log_level)
$log_level is one of the following: ``debug'', ``info'', ``warn'', ``error'' or ``off''
run_script($script)
$script is the JavaScript snippet to run
add_location_strategy($strategy_name)
The function must return null if the element can't be found.
$strategy_name is the name of the strategy to define; this should use only letters [a-zA-Z] with no spaces or other punctuation.
capture_entire_page_screenshot($filename)
$filename is 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.
set_context($context)
$context is the message to be sent to the browser
$field_locator is an element locator
$file_locator is 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.
capture_screenshot($filename)
$filename is the absolute path to the file to be written, e.g. ``c:\blah\screenshot.png''
shut_down_selenium_server()
key_down_native($keycode)
$keycode is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
key_up_native($keycode)
$keycode is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
key_press_native($keycode)
$keycode is an integer keycode number corresponding to a java.awt.event.KeyEvent; note that Java keycodes are NOT the same thing as JavaScript keycodes!
is_location($expected_location)
$expected_location is the location to match.
Note: This function is deprecated, use get_location()
instead.
get_checked($locator)
$locator is an element locator pointing to a checkbox or radio button.
Note: This function is deprecated, use is_checked()
instead.
See the select command for more information about option locators.
$locator is an element locator. $option_locator is an option locator, typically just an option label (e.g. ``John Smith'').
Note: This function is deprecated, use the get_selected_*() methods instead.
get_selected_options($locator)
$locator is an element locator.
Note: This function is deprecated, use get_selected_labels()
instead.
get_absolute_location()
Note: This function is deprecated, use get_location()
instead.
For more information about Selenium Remote Control, visit the website at http://www.openqa.org/selenium-rc/.
The Selenium Remote Control JIRA issue tracking system is available online at http://jira.openqa.org/browse/SRC.
Perl driver maintained by Luke Closs <selenium-rc@awesnob.com>
Selenium Remote Control maintained by Dan Fabulich <dfabulich@warpmail.net>
Copyright (c) 2006 ThoughtWorks, Inc
Licensed under the Apache License, Version 2.0 (the ``License''); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an ``AS IS'' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.