Selenium-Remote-Driver

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

    - Encode Firefox profiles without newlines for Sel 3.0 compatibility
    - #272: Remove unnecessary sleeps for successful waits
    - #270: Fix bug in find_child_element default finder
    - #263, #275: Address various documentation issues
    - #253: Fix error_handler being called incorrectly

0.2701 2016-11-01
    (firefox driver version: 2.48.2)

    [BUG FIXES]
    - #239: Respect existing prefs when using custom profile with Selenium::Firefox
    - #238: Update firefox driver extension to latest 2.48.2
    - #21: Update docs about using child finders with xpath

0.27   2015-30-08
    [NEW FEATURES]
    - #219: Add `startup_timeout` to CanStartBinary role
    - #211: @peroumal1: Document locator usage for Test::SRD functions

    [BUG FIXES]
    - #215: Replace Time::Mock with the more reliable & tested Test::Time

lib/Selenium/Firefox/Profile.pm  view on Meta::CPAN

    my %args  = @_;

    my $profile_dir;
    if ( $args{profile_dir} && -d $args{profile_dir} ) {
        $profile_dir = $args{profile_dir};
    }
    else {
        $profile_dir = File::Temp->newdir();
    }

    # TODO: accept user prefs, boolean prefs, and extensions in
    # constructor
    my $self = {
        profile_dir => $profile_dir,
        user_prefs  => {},
        extensions  => []
    };
    bless $self, $class or die "Can't bless $class: $!";

    return $self;
}


sub set_preference {
    my ( $self, %prefs ) = @_;

    foreach ( keys %prefs ) {
        my $value       = $prefs{$_};
        my $clean_value = '';

        if ( JSON::is_bool($value) ) {
            $self->set_boolean_preference( $_, $value );
            next;
        }
        elsif ( $value =~ /^(['"]).*\1$/ or looks_like_number($value) ) {

            # plain integers: 0, 1, 32768, or integers wrapped in strings:
            # "0", "1", "20140204". in either case, there's nothing for us
            # to do.
            $clean_value = $value;
        }
        else {
            # otherwise it's hopefully a string that we'll need to
            # quote on our own
            $clean_value = '"' . $value . '"';
        }

        $self->{user_prefs}->{$_} = $clean_value;
    }
}


sub set_boolean_preference {
    my ( $self, %prefs ) = @_;

    foreach ( keys %prefs ) {
        my $value = $prefs{$_};

        $self->{user_prefs}->{$_} = $value ? 'true' : 'false';
    }
}


sub get_preference {
    my ( $self, $pref ) = @_;

    return $self->{user_prefs}->{$pref};
}


sub add_extension {
    my ( $self, $xpi ) = @_;

    croak 'File not found: ' . $xpi unless -e $xpi;
    my $xpi_abs_path = abs_path($xpi);
    croak '$xpi_abs_path: extensions must be in .xpi format'
      unless $xpi_abs_path =~ /\.xpi$/;

    push( @{ $self->{extensions} }, $xpi_abs_path );
}


sub add_webdriver {
    my ( $self, $port, $is_marionette ) = @_;

    my $current_user_prefs = $self->{user_prefs};

    $self->set_preference(
        # having the user prefs here allows them to overwrite the
        # mutable loaded prefs
        %{$current_user_prefs},

        # but the frozen ones cannot be overwritten
        'webdriver_firefox_port' => $port
    );

    if ( !$is_marionette ) {
        $self->_add_webdriver_xpi;
    }

    return $self;

lib/Selenium/Firefox/Profile.pm  view on Meta::CPAN

    return $self->{profile_dir};
}

sub _write_preferences {
    my $self = shift;

    my $userjs = $self->{profile_dir} . "/user.js";
    open( my $fh, ">>", $userjs )
      or die "Cannot open $userjs for writing preferences: $!";

    foreach ( keys %{ $self->{user_prefs} } ) {
        print $fh 'user_pref("'
          . $_ . '", '
          . $self->get_preference($_) . ');' . "\n";
    }
    close($fh);
}

sub _install_extensions {
    my $self          = shift;
    my $extension_dir = $self->{profile_dir} . "/extensions/";

lib/Selenium/Remote/Driver.pm  view on Meta::CPAN

                                               'auto_close'         => 0);

    #or
    my $driver = Selenium::Remote::Driver->new('browser_name' =>'chrome',
                                               'extra_capabilities' => {
                                                   'goog:chromeOptions' => {
                                                       'args'  => [
                                                           'window-size=1260,960',
                                                           'incognito'
                                                       ],
                                                       'prefs' => {
                                                           'session' => {
                                                               'restore_on_startup' => 4,
                                                               'urls_to_restore_on_startup' => [
                                                                   'http://www.google.com',
                                                                   'http://docs.seleniumhq.org'
                                                               ]},
                                                           'first_run_tabs' => [
                                                               'http://www.google.com',
                                                               'http://docs.seleniumhq.org'
                                                           ]

t/01-webdriver3.t  view on Meta::CPAN

                sslProxy           => 'localhost:1234',
                socksProxy         => 'localhost:1234',
                socksVersion       => 2,
                noProxy            => ['http://localhost'],
            },
            extra_capabilities => { #TODO these need to be translated as moz:firefoxOptions => {} automatically, and then to be put in the main hash
                binary  => '/usr/bin/firefox',
                args    => ['-profile', '~/.mozilla/firefox/vbdgri9o.default'], #gotta check this gets overridden
                profile => 'some Base64 string of a zip file. I should really make this a feature',
                log     => 'trace', #trace|debug|config|info|warn|error|fatal
                prefs   => {}, #TODO check that this is auto-set above by the Selenium::Firefox::Profile stuff
                webdriverClick => 0, #This option is OP, *must* be set to false 24/7
            },
        },
    };

    no warnings qw{redefine once};
    local *Selenium::Remote::RemoteConnection::request = sub {return { sessionId => 'zippy', cmd_status => 'OK', cmd_return => {capabilities => 'eee'} }};
    local *File::Temp::Dir::dirname = sub { return '/tmp/zippy' };
    use warnings;

t/01-webdriver3.t  view on Meta::CPAN

    my $expected = {
        'alwaysMatch' => {
            'browserVersion'     => 666,
            'moz:firefoxOptions' => {
                'args' => [
                    '-profile',
                    '/tmp/zippy'
                ],
                'binary'  => '/usr/bin/firefox',
                'log'     => 'trace',
                'prefs'   => {},
                'profile' => 'some Base64 string of a zip file. I should really make this a feature',
                'webdriverClick' => 0
            },
            'platformName' => 'ANY',
            'proxy'        => {
                'ftpProxy'           => 'localhost:1234',
                'httpProxy'          => 'localhost:1234',
                'noProxy'            => [
                    'http://localhost'
                ],

t/Firefox-Profile.t  view on Meta::CPAN

}

PREFERENCES: {
    my $profile = Selenium::Firefox::Profile->new();
    # We're keeping the expected values together as we accumulate them
    # so we can validate them all at the end in the pack_and_unpack
    # section
    my $expected = {};

  STRINGS_AND_INTEGERS: {
        my $prefs = {
            'string' => "howdy, there",
            'integer' => 12345,
            'string.like.integer' => '"12345"',
        };

        foreach (keys %$prefs) {
            my $q = $_ eq 'string' ? '"' : '';
            $expected->{$_} = $q . $prefs->{$_} . $q;
        }

        $profile->set_preference(%$prefs);

        foreach (keys %$prefs) {
            cmp_ok($profile->get_preference($_), "eq", $expected->{$_},
                   "$_ preference is formatted properly");
        }
    }

  BOOLEANS: {
        my $prefs = {
            'boolean.true' => 1,
            'boolean.false' => 0,
        };

        foreach (keys %$prefs) {
            $expected->{$_} = $prefs->{$_} ? 'true' : 'false';
        }

        $profile->set_boolean_preference(%$prefs);

        foreach (keys %$prefs) {
            cmp_ok($profile->get_preference($_), "eq", $expected->{$_},
                   "$_ pref is formatted correctly");
        }

        $profile->set_preference(
            'boolean.true.2' => JSON::true,
            'boolean.false.2' => JSON::false
        );
        is($profile->get_preference('boolean.true.2'), 'true',
           'format true booleans via set_preference & JSON::true');

t/Firefox-Profile.t  view on Meta::CPAN

          or die "unzip failed: $UnzipError\n";

        foreach (keys %$expected) {
            my $value = $expected->{$_};
            cmp_ok($userjs, "=~", qr/$value\);/,
                   "$_ preference is formatted properly after packing and unpacking");
        }
    }

  MUTABLE_WEBDRIVER: {
        my $prefs = {
            'browser.startup.homepage' => 'mutable!'
        };

        my $profile = Selenium::Firefox::Profile->new;
        $profile->set_preference(%$prefs);
        $profile->add_webdriver('port');

        my $homepage_pref = $profile->get_preference('browser.startup.homepage');
        is($homepage_pref, '"mutable!"', 'can mutate webdriver.json preferences');
    }
}

CROAKING: {
    my $profile = Selenium::Firefox::Profile->new;



( run in 2.274 seconds using v1.01-cache-2.11-cpan-8f98c5d2c55 )