S::R::D

Daniel Gempesaw aa91d6327a Configure FF binary startup for geckodriver %!s(int64=9) %!d(string=hai) anos
lib aa91d6327a Configure FF binary startup for geckodriver %!s(int64=9) %!d(string=hai) anos
t a5ef784290 Encode the Firefox profile during binary startup %!s(int64=9) %!d(string=hai) anos
.gitignore 26888844e8 Fix issues with paths containing .. in upload path (see PR 194 for discussion) %!s(int64=10) %!d(string=hai) anos
.mailmap 89ed35e931 Add @peroumal to authors, spelling out authors section explicitly %!s(int64=10) %!d(string=hai) anos
.travis.yml 127b2623e3 Simplify travis testing configuration %!s(int64=10) %!d(string=hai) anos
Changes 9188a6c79e Start updating Changes file for v0.28 %!s(int64=9) %!d(string=hai) anos
INSTALL.md 59671f6678 Move installation documentation out of the readme %!s(int64=10) %!d(string=hai) anos
README.md 0ad7c754f2 Readme.md: Add Selenium IDE install instructions (#275) %!s(int64=9) %!d(string=hai) anos
TAGS 01f49fa04a Add ctags file %!s(int64=11) %!d(string=hai) anos
cpanfile ef13cafd87 Update generated cpanfile %!s(int64=9) %!d(string=hai) anos
dist.ini 89ed35e931 Add @peroumal to authors, spelling out authors section explicitly %!s(int64=10) %!d(string=hai) anos
driver-example.pl cf79170f72 replace #!.*perl with "#!/bin/env perl" in executables and docs, remove extranous #! lines in tests %!s(int64=10) %!d(string=hai) anos
ide-plugin.js 78aad2e016 implement selenium ide select (#273) %!s(int64=9) %!d(string=hai) anos
weaver.ini 89ed35e931 Add @peroumal to authors, spelling out authors section explicitly %!s(int64=10) %!d(string=hai) anos

README.md

Selenium::Remote::Driver

Build Status

Selenium WebDriver is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser. This module is a Perl implementation of the client for the Webdriver JSONWireProtocol that Selenium provides.

This module sends commands directly to the server using HTTP. Using this module together with the Selenium Server, you can automatically control any supported browser.

Installation

It's probably easiest to use the cpanm or CPAN commands:

$ cpanm Selenium::Remote::Driver

If you want to install from this repository, you have a few options; see the installation docs for more details.

Usage

You can either use this module with the standalone java server, or use it to directly start the webdriver binaries for you. Note that the latter option does not require the JRE/JDK to be installed, nor does it require the selenium standalone server (despite the name of the main module!).

with a standalone server

Download the standalone server and have it running on port 4444:

$ java -jar selenium-server-standalone-X.XX.X.jar

Then the following should start up Firefox for you:

Locally

use strict;
use warnings;
use Selenium::Remote::Driver;

my $driver = Selenium::Remote::Driver->new;
$driver->get('http://www.google.com');
print $driver->get_title . "\n"; # "Google"

my $query = $driver->find_element('q', 'name');
$query->send_keys('CPAN Selenium Remote Driver');

my $send_search = $driver->find_element('btnG', 'name');
$send_search->click;

# make the find_element blocking for a second to allow the title to change
$driver->set_implicit_wait_timeout(2000);
my $results = $driver->find_element('search', 'id');

print $driver->get_title . "\n"; # CPAN Selenium Remote Driver - Google Search
$driver->quit;

Saucelabs

If using Saucelabs, there's no need to have the standalone server running on a local port, since Saucelabs provides it.

use Selenium::Remote::Driver;

my $user = $ENV{SAUCE_USERNAME};
my $key = $ENV{SAUCE_ACCESS_KEY};

my $driver = Selenium::Remote::Driver->new(
    remote_server_addr => $user . ':' . $key . '@ondemand.saucelabs.com',
    port => 80
);

$driver->get('http://www.google.com');
print $driver->get_title();
$driver->quit();

There are additional usage examples on metacpan, and also in this project's wiki, including setting up the standalone server, running tests on Internet Explorer, Chrome, PhantomJS, and other useful example snippets.

no standalone server

  • Firefox: simply have the browser installed in the normal place for your OS.

  • Chrome: install the Chrome browser, download Chromedriver and get chromedriver in your $PATH:

  • PhantomJS: install the PhantomJS binary and get phantomjs in your $PATH

As long as the proper binary is available in your path, you should be able to do the following:

my $firefox = Selenium::Firefox->new;
$firefox->get('http://www.google.com');

my $chrome = Selenium::Chrome->new;
$chrome->get('http://www.google.com');

my $ghost = Selenium::PhantomJS->new;
$ghost->get('http://www.google.com');

Note that you can also pass a binary argument to any of the above classes to manually specify what binary to start:

my $chrome = Selenium::Chrome->new(binary => '~/Downloads/chromedriver');

See the pod for the different modules for more details.

Selenium IDE Plugin

ide-plugin.js is a Selenium IDE Plugin which allows you to export tests recorded in Selenium IDE to a perl script.

Installation in Selenium IDE

  1. Open Selenium IDE
  2. Options >> Options
  3. Formats Tab
  4. Click Add at the bottom
  5. In the name field call it 'Perl-Webdriver'
  6. Paste this entire source in the main textbox
  7. Click 'Save'
  8. Click 'Ok'
  9. Close Selenium IDE and open it again.

Support and Documentation

There is a mailing list available at

https://groups.google.com/forum/#!forum/selenium-remote-driver

for usage questions and ensuing discussions. If you've come across a bug, please open an issue in the Github issue tracker. The POD is available in the usual places, including metacpan, and in your shell via perldoc.

$ perldoc Selenium::Remote::Driver
$ perldoc Selenium::Remote::WebElement

Contributing

Thanks for considering contributing! The contributing guidelines are in the wiki. The documentation there also includes information on generating new Linux recordings for Travis.

Copyright and License

Copyright (c) 2010-2011 Aditya Ivaturi, Gordon Child

Copyright (c) 2014-2016 Daniel Gempesaw

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.