Brownie::Session - browser session class
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;
new(%args)
my $session = Brownie::Session->new(%args);
%args are:
%args
driver: loadable driver name or config
driver
app_host: external target application
app_host
app: PSGI application
app
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")');
click_link($locator)
Finds and clicks specified link.
$session->click_link($locator);
$locator: id or text of link
$locator
click_button($locator)
Finds and clicks specified buttons.
$session->click_button($locator);
$locator: id or value of button
click_on($locator)
Finds and clicks specified links or buttons.
$session->click_on($locator);
It combines click_link and click_button.
click_link
click_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"
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);
NAKAGAWA Masaki <masaki@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Brownie::Driver, Brownie::Node
To install Brownie, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Brownie
CPAN shell
perl -MCPAN -e shell install Brownie
For more information on module installation, please visit the detailed CPAN module installation guide.