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);

  # run some javascript code and print its result
  print $mech->run_js('return "js: " + 2');

  # 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->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_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).

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.

SEE ALSO

Mozilla::Mechanize