NAME

Weasel::Driver::Mock - Weasel driver for testing purposes

VERSION

0.02

SYNOPSIS

use Weasel;
use Weasel::Session;
use Weasel::Driver::Mock;

my %opts = (
  states => [
     { cmd => 'get', args => [ 'http://localhost/index' ] },
     { cmd => 'find', args => [ '//div[@id="your-id"]' ] },
  ],
);
my $weasel = Weasel->new(
     default_session => 'default',
     sessions => {
        default => Weasel::Session->new(
          driver => Weasel::Driver::Mock->new(%opts),
        ),
     });

$weasel->session->get('http://localhost/index');

DESCRIPTION

This module implements the Weasel::DriverRole protocol, mimicing a true web driver session. The concept has been very much inspired by DBD::Mock.

The states attribute of a Weasel::Driver::Mock object contains a reference to an array of hashes. Each hash describes a state.

[ {
     cmd => 'get', args => [ 'http://localhost/index' ]
  },
  {
     cmd => 'find', args => [ '//div[@id="help-me"]' ],
     ret => {
        id => 'abc',
     },
  },
  {
     cmd => 'find_all', args => [ '//div' ],
     ret_array => [
        { id => 'abc' },
        { id => 'def' },
     ],
  },
  {
      cmd => 'click', args => [ 'abc' ],
      err => 'Element not visible on the page',
  },
  ...
]

STATES

A state is a hash where its keys have the following meaning:

cmd (required)

The name of the function called (e.g. 'find', 'find_all' or 'get').

args (optional)

The expected list of arguments passed to the called function. When not provided, the arguments of the call are not validated.

Note that this list excludes any file handles passed in.

ret (or ret_array) (optional)

Specifies the value to be returned from the called function, or, in case of ret_array, the values to be returned.

err (optional)

When a state specifies an err key, the called function (if it is the correct one) die with the value as the argument to die.

content (optional)
content_base64 (optional)
content_from_file (optional)

Provides the content to be written to the file handle when the called function accepts a file handle argument.

The string provided as value of content will be printed to the handle. The string provided as the value of content_base64 will be passed to MIME::Base64::decode. The decoded content is then written to the handle. The string provided as the value of content_from_file is taken as a file name.

DEPENDENCIES

ATTRIBUTES

states

IMPLEMENTATION OF Weasel::DriverRole

For the documentation of the methods in this section, see Weasel::DriverRole.

implements
start

A few capabilities can be specified in t/.pherkin.yaml Some can even be specified as environment variables, they will be expanded here if present.

stop
find_all
get
wait_for
clear
click
dblclick
execute_script
get_attribute($id, $att_name)
get_page_source($fh)
get_text($id)
is_displayed($id)
set_attribute($id, $att_name, $value)
get_selected($id)
set_selected($id, $value)
screenshot($fh)
send_keys($element_id, @keys)
tag_name($elem)

SUBROUTINES/METHODS

This module implements the following methods in addition to the Weasel::DriverRole protocol methods:

set_wait_timeout

Sets the wait_timeut attribute of the object.

set_window_size

Sets the window_size attribute of the object.

AUTHOR

Erik Huelsmann

CONTRIBUTORS

Erik Huelsmann

MAINTAINERS

Erik Huelsmann

BUGS AND LIMITATIONS

Bugs can be filed in the GitHub issue tracker for the Weasel::Driver::Mock project: https://github.com/perl-weasel/weasel-driver-mock/issues

SOURCE

The source code repository for Weasel::Driver::Mock is at https://github.com/perl-weasel/weasel-driver-mock

SUPPORT

Community support is available through perl-weasel@googlegroups.com.

LICENSE AND COPYRIGHT

(C) 2019  Erik Huelsmann

Licensed under the same terms as Perl.