Преглед изворни кода

Fix #4: make sure that the injection of child elements is done correctly

George S. Baugh пре 4 година
родитељ
комит
8951c57864
2 измењених фајлова са 32 додато и 25 уклоњено
  1. 26 24
      at/sanity.test
  2. 6 1
      lib/Selenium/Subclass.pm

+ 26 - 24
at/sanity.test

@@ -17,6 +17,9 @@ use Data::Dumper;
 
 use Selenium::Client;
 
+# SHUT UP WITH THE WARNINGS
+local $Test::Builder::Level = 0;
+
 my $extra = '';
 $extra = '/' if grep { $^O eq $_ } qw{msys MSWin32};
 
@@ -24,29 +27,30 @@ 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
+SKIP: {
+    skip("Need JSONWire support before we can test winappdriver",1);
+    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,
+        };
 
-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");
+        #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};
@@ -161,9 +165,7 @@ foreach my $browser (@browsers) {
 
             my $finder = $session->FindElement( using => 'css selector', value => 'form' );
             my $found  = $finder->FindElementFromElement( using => 'css selector', 'value' => 'label' );
-            todo "Property/Attribute get is broken in Selenium" => sub {
-                is($found->GetElementAttribute( name => 'for' ), 'text', "Can find child properly");
-            };
+            is($found->GetElementAttribute( name => 'for' ), 'text', "Can find child properly");
 
             my @radios = $finder->FindElementsFromElement( using => 'css selector', 'value' => 'input[type=radio]' );
             is(scalar(@radios), 2, "Can find child elements properly");

+ 6 - 1
lib/Selenium/Subclass.pm

@@ -35,6 +35,8 @@ sub _request ($self, $method, %params) {
     if ( $self->{sortfield} eq 'element-6066-11e4-a52e-4f735466cecf') {
         $self->{sortfield} = 'elementid';
         $self->{elementid} = delete $self->{'element-6066-11e4-a52e-4f735466cecf'};
+        # Ensure element childs don't think they are their parent
+        $self->{to_inject}{elementid} = $self->{elementid};
     }
 
     # Inject our sortField param, and anything else we need to
@@ -42,7 +44,10 @@ sub _request ($self, $method, %params) {
     my $inject = $self->{to_inject};
     @params{keys(%$inject)} = values(%$inject) if ref $inject eq 'HASH';
 
-    # and insure it is injected into child object requests
+    # and ensure it is injected into child object requests
+    # This is primarily to ensure that the session ID trickles down correctly.
+    # Some also need the element ID to trickle down.
+    # However, in the case of getting child elements, we wish to specifically prevent that, and do so above.
     $params{inject} = $self->{sortfield};
 
     $self->{callback}->($self,$method,%params) if $self->{callback};