Brownie::Session - browser session class


  use Test::More;
  use Brownie::Session;

  # external server
  my $session = Brownie::Session->new(
      driver   => 'Mechanize',
      app_host => '',

  # 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',

  is $session->title => 'Some Title';

  $session->fill_in('User Name' => 'brownie');
  $session->fill_in('Email Address' => '');
  like $session->source => qr/Welcome (.+)/;

  $session->fill_in(q => 'Brownie');
  like $session->title => qr/Search result of Brownie/i;



  • new(%args)

      my $session = Brownie::Session->new(%args);

    %args are:

    • driver: loadable driver name or config

    • app_host: external target application

    • app: PSGI application

Driver Delegation

  • visit($url)

    Go to $url.

  • 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.

  • execute_script($javascript)

    Executes snippet of JavaScript into current page.

  • 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.


    $locator: id or text of link

  • click_button($locator)

    Finds and clicks specified buttons.


    $locator: id or value of button

  • click_on($locator)

    Finds and clicks specified links or buttons.


    It combines click_link and 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.

  • check($locator)

    Sets a checkbox to "checked"

  • uncheck($locator)

    Unsets a checkbox from "checked"

  • select($locator)

    Selects an option.

  • unselect($locator)

    Unselects an option in multiple select.

  • attach_file($locator, $filename)

    Sets a path to file upload field.

      $session->attach_file($locator, $filename);


NAKAGAWA Masaki <>


This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Brownie::Driver, Brownie::Node