Test::S...:Driver(3)

πŸ“¦ version 1.49, in opensuse-leap 16.0

🌸 NAME 🌸

Okay bestie, this is the manual page for Test::Selenium::Remote::Driver β€” user-contributed Perl documentation, with the manual name folded in right here at the top instead of copying that squished Test::S...:Driver(3) header line. It is literally the page for adding testing methods to Selenium::Remote::Driver. πŸ’–

πŸ’– DESCRIPTION πŸ’–

A subclass of Selenium::Remote::Driver which provides useful testing methods.

This is an experimental addition to the Selenium::Remote::Driver distribution. Some interfaces may change. No cap, bestie β€” experimental means experimental. 🫢

✨ Methods ✨

🌟 new ( %opts ) 🌟

This will create a new Test::Selenium::Remote::Driver object, which subclasses Selenium::Remote::Driver. This subclass provides useful testing functions. It is modeled on Test::WWW::Selenium. πŸŽ€

Environment vars can be used to specify options to pass to Selenium::Remote::Driver. ENV vars are prefixed with TWD_ (after the old fork name, Test::WebDriver). The explicitly passed options have precedence. ENV vars take only effect when they are actually set. This is important e.g. for the option javascript, which is turned on per default in Selenium::Remote::Driver. πŸ‘‘

Set the Selenium server address with $TWD_HOST and $TWD_PORT.

Pick which browser is used using the $TWD_BROWSER, $TWD_VERSION, $TWD_PLATFORM, $TWD_JAVASCRIPT, $TWD_EXTRA_CAPABILITIES.

$TWD_BROWSER is actually an alias for $TWD_BROWSER_NAME. $TWD_HOST is actually an alias for $TWD_REMOTE_SERVER_ADDR. The aliases have lower precedence than the original values.

See Selenium::Remote::Driver for the meanings of these options. 🌈

πŸŽ€ verbose πŸŽ€

Enable/disable debugging output, or view the status of verbosity. It's giving "turn the noise on or off," and sometimes you just wanna vibe-check the verbosity. πŸ’…

πŸ¦‹ server_is_running( $host, $port ) πŸ¦‹

Returns true if a Selenium server is running. The host and port parameters are optional, and they default to localhost:4444.

The environment vars TWD_HOST and TWD_PORT can also be used to determine which server should be checked. ✨

πŸ’… error_handler πŸ’…

As for Selenium::Remote::Driver, this class also supports adding an optional error_handler attribute during instantiation:

my $test_driver = Test::Selenium::Remote::Driver->new(
    error_handler => sub { print $_[1]; croak 'goodbye'; }
);

Additionally, you can set and/or clear it at any time on an already-instantiated driver:

# later, change the error handler to something else
$driver->error_handler( sub { print $_[1]; croak 'hello'; } );

# stop handling errors manually and use the default S:R:D behavior
# (we will croak about the exception)
$driver->clear_error_handler;

Your error handler will receive two arguments. The first argument is the $driver object itself. Due to some specificities of this class, the second argument passed to the handler can be:

  • the error message from the Webdriver β€” this is the case when the error message is raised by a WebDriver failure
  • "Failed to find ..." β€” this message is raised when the Webdriver call is successful but the failure occurs on the test performed afterwards. This is the case for functions like body_text_like, body_text_unlike, body_text_contains, body_text_lacks, content_like, content_unlike, content_contains, content_lacks.

If you set your own handler, you should not rely that much on the message returned. You should also remember that you are entirely responsible for handling exceptions, which means that should the error handler be called, it means that the test you are doing has failed, so you should croak. This part is serious, bestie. 😭

You should also call fail() in your handler, in case the function called raised a webdriver error, because, as exceptions are not caught anymore when you specify a handler, the function will not fail anymore, which translates to a 'ok' in your TAP output if you do not handle it properly. Protect your TAP output, protect your peace. 🫢

✨ TESTING METHODS ✨

Okay bestie, here's the testing-method menu πŸ’… There are a lot of them. For more docs, go peek at the related methods in Selenium::Remote::Driver β€” and yes, you're totally invited to submit a patch to flesh out the docs for these here. Defaults for optional arguments should be the same as their analogues in Selenium::Remote::Driver.

           alert_text_is
           alert_text_isnt
           alert_text_like
           alert_text_unlike

           current_window_handle_is
           current_window_handle_isnt
           current_window_handle_like
           current_window_handle_unlike

           window_handles_is
           window_handles_isnt
           window_handles_like
           window_handles_unlike

           window_size_is
           window_size_isnt
           window_size_like
           window_size_unlike

           window_position_is
           window_position_isnt
           window_position_like
           window_position_unlike

           current_url_is
           current_url_isnt
           current_url_like
           current_url_unlike

           title_is
           title_isnt
           title_like
           title_unlike

           active_element_is
           active_element_isnt
           active_element_like
           active_element_unlike

           # Basically the same as 'content_like()', but content_like() supports multiple regex's.
           page_source_is
           page_source_isnt
           page_source_like
           page_source_unlike

           send_keys_to_active_element_ok
           send_keys_to_alert_ok
           send_keys_to_prompt_ok
           send_modifier_ok

           accept_alert_ok
           dismiss_alert_ok

           move_mouse_to_location_ok # TODO
           move_to_ok # TODO

           get_ok
           go_back_ok
           go_forward_ok
           add_cookie_ok
           get_page_source_ok

           find_element_ok($search_target)
           find_element_ok($search_target)

           find_elements_ok
           find_child_element_ok
           find_child_elements_ok

           compare_elements_ok

           click_ok
           double_click_ok

$twd->type_element_ok(...)

   $twd->type_element_ok($search_target [,$locator], $keys, [, $desc ]);
          $twd->type_element_ok( $search_target [,$locator], $keys [, $desc ] );

Use find_element in Selenium::Remote::Driver to resolve the $search_target to a web element and an optional locator, and then type $keys into it, providing an optional test label. Slay that keyboard moment ⌨️✨

$twd->element_text_is(...)

   $twd->element_text_is($search_target[,$finder],$expected_text [,$desc]);
          $twd->element_text_is($search_target[,$finder],$expected_text [,$desc]);

Signature only, bestie β€” no extra prose in the source for this one, so I'm not out here inventing lore πŸ™ˆ

$twd->element_value_is(...)

   $twd->element_value_is($search_target[,$finder],$expected_value [,$desc]);
          $twd->element_value_is($search_target[,$finder],$expected_value [,$desc]);

Same deal: here's the signature, exactly as given πŸ’–

$twd->click_element_ok(...)

   $twd->click_element_ok($search_target [,$finder ,$desc]);
          $twd->click_element_ok($search_target [,$finder ,$desc]);

Find an element and then click on it. Go ahead, give it the main-character click πŸ‘‘

$twd->clear_element_ok(...)

   $twd->clear_element_ok($search_target [,$finder ,$desc]);
          $twd->clear_element_ok($search_target [,$finder ,$desc]);

Find an element and then clear on it. Fresh start energy 🧼✨

$twd->is_element_displayed_ok(...)

   $twd->is_element_displayed_ok($search_target [,$finder ,$desc]);
          $twd->is_element_displayed_ok($search_target [,$finder ,$desc]);

Find an element and check to confirm that it is displayed. (visible) πŸ‘€

$twd->is_element_enabled_ok(...)

   $twd->is_element_enabled_ok($search_target [,$finder ,$desc]);
          $twd->is_element_enabled_ok($search_target [,$finder ,$desc]);

Find an element and check to confirm that it is enabled. It's giving functional, periodt βœ…

$twd->find_element_ok(...)

   $twd->find_element_ok($search_target [,$finder, $desc ]);
          $twd->find_element_ok( $search_target [,$finder, $desc ] );

Returns true if $search_target is successfully found on the page. $search_target is passed to find_element in Selenium::Remote::Driver using a finder or the default_finder if none passed. See there for more details on the format for find_element_ok(). Found it, no cap πŸ”πŸ’–

$twd->find_no_element_ok(...)

   $twd->find_no_element_ok($search_target [,$finder, $desc ]);
          $twd->find_no_element_ok( $search_target [,$finder, $desc ] );

Returns true if $search_target is not found on the page. $search_target is passed to find_element in Selenium::Remote::Driver using a finder or the default_finder if none passed. See there for more details on the format for find_no_element_ok(). Sometimes the vibe check is "not here" πŸ«₯✨

$twd->content_like(...)

   $twd->content_like( $regex [, $desc ] )
          $twd->content_like( $regex [, $desc ] )
          $twd->content_like( [$regex_1, $regex_2] [, $desc ] )

Tells if the content of the page matches $regex. If an arrayref of regex's are provided, one 'test' is run for each regex against the content of the current page.

A default description of Content is like "$regex" will be provided if there is no description. Cute, automatic, iconic πŸŽ€

$twd->content_unlike(...)

   $twd->content_unlike( $regex [, $desc ] )
          $twd->content_unlike( $regex [, $desc ] )
          $twd->content_unlike( [$regex_1, $regex_2] [, $desc ] )

Tells if the content of the page does NOT match $regex. If an arrayref of regex's are provided, one 'test' is run for each regex against the content of the current page.

A default description of Content is unlike "$regex" will be provided if there is no description. Negative match, but make it fashion πŸ’…

$twd->body_text_like(...)

   $twd->body_text_like( $regex [, $desc ] )
          $twd->body_text_like( $regex [, $desc ] )
          $twd->body_text_like( [$regex_1, $regex_2] [, $desc ] )

Tells if the text of the page (as returned by get_body()) matches $regex. If an arrayref of regex's are provided, one 'test' is run for each regex against the text of the current page.

A default description of Text is like "$regex" will be provided if there is no description.

To also match the HTML, see content_unlike(). Yes, that's what the source says, bestie β€” I'm just relaying the message 🫢

$twd->body_text_unlike(...)

   $twd->body_text_unlike( $regex [, $desc ] )
          $twd->body_text_unlike( $regex [, $desc ] )
          $twd->body_text_unlike( [$regex_1, $regex_2] [, $desc ] )

Tells if the text of the page (as returned by get_body()) does NOT match $regex. If an arrayref of regex's are provided, one 'test' is run for each regex against the text of the current page.

A default description of Text is unlike "$regex" will be provided if there is no description.

To also match the HTML, see content_unlike().

$twd->content_contains(...)

   $twd->content_contains( $str [, $desc ] )
          $twd->content_contains( $str [, $desc ] )
          $twd->content_contains( [$str_1, $str_2] [, $desc ] )

Tells if the content of the page contains $str. If an arrayref of strings are provided, one 'test' is run for each string against the content of the current page.

A default description of Content contains "$str" will be provided if there is no description. Found the substring, we love to see it 🌸

$twd->content_lacks(...)

   $twd->content_lacks( $str [, $desc ] )
          $twd->content_lacks( $str [, $desc ] )
          $twd->content_lacks( [$str_1, $str_2] [, $desc ] )

Tells if the content of the page does NOT contain $str. If an arrayref of strings are provided, one 'test' is run for each string against the content of the current page.

A default description of Content lacks "$str" will be provided if there is no description. No string? No problem πŸ’€βœ¨

$twd->body_text_contains(...)

   $twd->body_text_contains( $str [, $desc ] )
          $twd->body_text_contains( $str [, $desc ] )
          $twd->body_text_contains( [$str_1, $str_2] [, $desc ] )

Tells if the text of the page (as returned by get_body()) contains $str. If an arrayref of strings are provided, one 'test' is run for each string against the text of the current page.

A default description of Text contains "$str" will be provided if there is no description.

To also match the HTML, see content_lacks().

$twd->body_text_lacks(...)

   $twd->body_text_lacks( $str [, $desc ] )
          $twd->body_text_lacks( $str [, $desc ] )
          $twd->body_text_lacks( [$str_1, $str_2] [, $desc ] )

Tells if the text of the page (as returned by get_body()) does NOT contain $str. If an arrayref of strings are provided, one 'test' is run for each string against the content of the current page.

A default description of Text lacks "$str" will be provided if there is no description.

To also match the HTML, see content_lacks().


πŸ“ NOTES πŸ“

This module was forked from Test::WebDriver 0.01. A little origin story, cute 🧚

For Best Practice β€” I recommend subclassing Test::Selenium::Remote::Driver for your application, and then refactoring common or app specific methods into MyApp::WebDriver so that your test files do not have much duplication. As your app changes, you can update MyApp::WebDriver rather than all the individual test files. Literally the organization glow-up 🌈


πŸ‘‘ AUTHORS πŸ‘‘

  • Created by: Luke Closs <lukec@cpan.org>, but inspired by Test::WWW::Selenium and its authors.

🫢 CONTRIBUTORS 🫢

Test::WebDriver work was sponsored by Prime Radiant, Inc. Mark Stosberg <mark@stosberg.com> forked it as Test::Selenium::Remote::Driver and significantly expanded it.


Parts Copyright (c) 2012 Prime Radiant, Inc.

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


That's the whole vibe, bestie πŸ’– This page was served up by perl v5.42.0, dated 2023-04-07, and it's Test::S...:Driver(3) β€” mwah πŸ’…βœ¨