Procházet zdrojové kódy

First crack at #2, looks like I need to implement JSONWire support :(

George S. Baugh před 4 roky
rodič
revize
d9cc8c5de0
2 změnil soubory, kde provedl 80 přidání a 0 odebrání
  1. 25 0
      at/sanity.test
  2. 55 0
      lib/Selenium/Driver/WinApp.pm

+ 25 - 0
at/sanity.test

@@ -23,6 +23,31 @@ $extra = '/' if grep { $^O eq $_ } qw{msys MSWin32};
 my $sut  = 'file://' . $extra . abs_path("$FindBin::Bin/test.html");
 my $sut2 = 'file://' . $extra . abs_path("$FindBin::Bin/other.html");
 
+#Do WinAppDriver testing if we are on windows and have it installed at all
+
+my $winapp = eval { Selenium::Client->new( driver => 'WinApp', debug => $ENV{DEBUG} ) };
+if ($winapp) {
+    my $caps = {
+        app           => 'C:\\Windows\\System32\\notepad.exe',
+        platformName  => "WINDOWS",
+        platform      => "WINDOWS",
+        deviceName    => "WindowsPC",
+        appArguments  => "zippy.txt",
+        appWorkingDir => '.',
+        "ms:experimental-webdriver" => JSON::true,
+    };
+
+    #XXX the WC3 support is only "sorta" in that they don't support modern caps
+    my @ret = $winapp->NewSession( desiredCapabilities => $caps );
+    use Data::Dumper;
+    print Dumper(\@ret);
+    my $notepad;
+    my $input = $notepad->FindElement( using => 'css selector', value => 'Edit' );
+    $input->ElementSendKeys( text => 'tickle');
+    is($input->GetElementProperty( name => 'value' ), 'tickle', "Can clear and send keys to a text input");
+}
+die;
+
 my @browsers = qw{firefox chrome};
 push(@browsers, 'MicrosoftEdge') if grep { $^O eq $_ } qw{MSWin32 msys};
 push(@browsers, 'safari') if $^O eq 'darwin';

+ 55 - 0
lib/Selenium/Driver/WinApp.pm

@@ -0,0 +1,55 @@
+package Selenium::Driver::WinApp;
+
+use strict;
+use warnings;
+
+no warnings 'experimental';
+use feature qw/signatures/;
+
+use Carp qw{confess};
+use File::Which;
+
+#ABSTRACT: Tell Selenium::Client how to spawn the Windows Application Driver
+
+=head1 Mode of Operation
+
+Spawns a WinAppDriver server on the provided port (which the caller will assign randomly)
+Relies on WinAppDriver being in your $PATH (put in this to your user's PATH env var:)
+
+    %PROGRAMFILES(X86)%\Windows Application Driver
+
+Pipes log output to ~/.selenium/perl-client/$port.log
+
+=head1 SUBROUTINES
+
+=head2 build_spawn_opts($class,$object)
+
+Builds a command string which can run the driver binary.
+All driver classes must build this.
+
+=cut
+
+sub _driver {
+    return 'WinAppDriver.exe';
+}
+
+sub build_spawn_opts($class,$object) {
+    $object->{driver_class}       = $class;
+    $object->{driver_version}     //= '';
+    $object->{log_file}           //= "$object->{client_dir}/perl-client/selenium-$object->{port}.log";
+    $object->{driver_file} = File::Which::which($class->_driver());
+    die "Could not find driver!" unless $object->{driver_file};
+    #XXX appears that escaping from system() does not work correctly on win32 thanks to the join() I have? to do later, sigh
+    $object->{driver_file} = qq/"$object->{driver_file}"/;
+
+    my @config = ($object->{port});
+
+    # Build command string
+    $object->{command} //= [
+        $object->{driver_file},
+        @config,
+    ];
+    return $object;
+}
+
+1;