NAME
Mozilla::Mechanize::GUITester - enhances Mozilla::Mechanize with GUI testing.
SYNOPSIS
use Mozilla::Mechanize::GUITester;
# regular Mozilla::Mechanize initialization
my $mech = Mozilla::Mechanize::GUITester->new(%mechanize_args);
$mech->get_url($url);
# convenience wrapper over GetElementById and QueryInterface
my $elem = $mech->get_html_element_by_id("some_id");
# click mouse at the element position + (1, 1)
$mech->x_click($elem, 1, 1);
# play with the mouse relative to the element position
$mech->x_mouse_down($elem, 2, 2);
$mech->x_mouse_move($elem, 4, 4);
$mech->x_mouse_up($elem, 4, 4);
# send keystrokes to the application
$mech->x_send_keys('{DEL}');
# press and release left CTRL button. You can click in the middle.
$mech->x_press_key('LCT');
$mech->x_release_key('LCT');
# run some javascript code and print its result
print $mech->run_js('return "js: " + 2');
# find out element style using its id
print $mech->get_element_style_by_id('the_elem_id', 'background-color');
# are there any javascript errors?
print Dumper($mech->console_messages);
# find out HTTP response status (works only for HTTP protocol)
print $mech->status;
DESCRIPTION
This module enhances Mozilla::Mechanize with convenience functions allowing testing of DHTML/JavaScript rich pages.
It uses X11::GUITest to emulate mouse clicking, dragging and moving over elements in DOM tree.
It also allows running of arbitrary javascript code in the page context and getting back the results.
CONSTRUCTION
Mozilla::Mechanize::GUITester->new(%options);
This constructor delegates to Mozilla::Mechanize::new function. See Mozilla::Mechanize manual for its description.
ACCESSORS
$mech->status
Returns last response status using Mozilla::ObserverService and nsIHTTPChannel:responseStatus function.
Note that it works only for HTTP requests.
$mech->last_alert
Returns last alert contents intercepted through Mozilla::PromptService.
It is useful for communication from javascript.
$mech->console_messages
Returns arrayref of all console messages (e.g. javascript errors) aggregated so far.
See Mozilla nsIConsoleService documentation for more details.
METHODS
$mech->pull_alerts
Pulls all alerts aggregated so far and resets alerts stash. Useful for JS debugging.
$mech->run_js($js_code)
Wraps $js_code with JavaScript function and invokes it. Its result is returned as string and intercepted through alert()
.
See last_alert
accessor above.
$mech->get_element_style_by_id($element_id, $style_attribute)
Uses Mozilla's getComputedStyle to return value of $style_attribute
for the element located with $element_id
.
$mech->get_html_element_by_id($html_id)
Uses GetElementById and QueryInterface to get Mozilla::DOM::HTMLElement.
See Mozilla::DOM documentation for more details.
$mech->x_click($element, $x, $y)
Emulates mouse click at ($element.left + $x, $element.top + $y) coordinates.
$mech->x_mouse_down($element, $x, $y)
Presses left mouse button at ($element.left + $x, $element.top + $y).
$mech->x_mouse_up($element, $x, $y)
Releases left mouse button at ($element.left + $x, $element.top + $y).
$mech->x_mouse_move($element, $x, $y)
Moves mouse to ($element.left + $x, $element.top + $y).
$mech->x_send_keys($keystroke)
Sends $keystroke to mozilla window. It uses X11::GUITest SendKeys function. Please see its documentation for possible $keystroke
values.
$mech->x_press_key($key)
Uses X11::GUITest PressKey function. Please see its documentation for possible $key
values.
$mech->x_release_key($keystroke)
Uses X11::GUITest ReleaseKey function to release previously pressed key. Please see its X11::GUITest documentation for possible $key
values.
AUTHOR
Boris Sukholitko <boriss@gmail.com>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.