NAME
Brownie::Session - browser session class
SYNOPSIS
use Test::More;
use Brownie::Session;
# external server
my $session = Brownie::Session->new(
driver => 'Mechanize',
app_host => 'http://app.example.com:5000',
);
# PSGI app
my $session = Brownie::Session->new(
driver => 'Mechanize',
app => sub { ...(PSGI app)... },
);
# PSGI file
my $session = Brownie::Session->new(
driver => 'Mechanize',
app => 'app.psgi',
);
$session->visit('/');
is $session->title => 'Some Title';
$session->fill_in('User Name' => 'brownie');
$session->fill_in('Email Address' => 'brownie@example.com');
$session->click_button('Login');
like $session->source => qr/Welcome (.+)/;
$session->fill_in(q => 'Brownie');
$session->click_link_or_button('Search');
like $session->title => qr/Search result of Brownie/i;
done_testing;
METHODS
new(%args)
my $session = Brownie::Session->new(%args);
%args
are:driver
: loadable driver name or confighost
: external target applicationapp
: PSGI application
Driver Delegation
visit($url)
Go to $url.
$session->visit('http://example.com/');
current_url
Returns current page's URL.
my $url = $session->current_url;
current_path
Returns current page's path of URL.
my $path = $session->current_path;
title
Returns current page's <title> text.
my $title = $session->title;
source
Returns current page's HTML source.
my $source = $session->source;
screenshot($filename)
Takes current page's screenshot and saves to $filename as PNG.
$session->screenshot($filename);
execute_script($javascript)
Executes snippet of JavaScript into current page.
$session->execute_script('$("body").empty()');
evaluate_script($javascript)
Executes snipptes and returns result.
my $result = $session->evaluate_script('1 + 2');
If specified DOM element, it returns WebElement object.
my $node = $session->evaluate_script('document.getElementById("foo")');
Node Action
click_link($locator)
Finds and clicks specified link.
$session->click_link($locator);
$locator
: id or text of linkclick_button($locator)
Finds and clicks specified buttons.
$session->click_button($locator);
$locator
: id or value of buttonclick_on($locator)
Finds and clicks specified links or buttons.
$session->click_on($locator);
It combines
click_link
andclick_button
.fill_in($locator, $value)
Sets a value to located field (input or textarea).
$session->fill_in($locator, $value);
choose($locator)
Selects a radio button.
$session->choose($locator);
check($locator)
Sets a checkbox to "checked"
$session->check($locator);
uncheck($locator)
Unsets a checkbox from "checked"
$session->check($locator);
select($locator)
Selects an option.
$session->select($locator);
unselect($locator)
Unselects an option in multiple select.
$session->unselect($locator);
attach_file($locator, $filename)
Sets a path to file upload field.
$session->attach_file($locator, $filename);
AUTHOR
NAKAGAWA Masaki <masaki@cpan.org>
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.