George S. Baugh 4 anos atrás
pai
commit
734c8bcaed
3 arquivos alterados com 15 adições e 9 exclusões
  1. 3 0
      example.pl
  2. 2 1
      lib/Playwright.pm
  3. 10 8
      lib/Playwright/Base.pm

+ 3 - 0
example.pl

@@ -75,6 +75,9 @@ foreach my $input (@$inputs) {
 my $actual_input = $page->select('input[name=q]');
 $actual_input->fill('whee');
 
+# Ensure we can grab the parent (convenience)
+print "Got Parent: ISA ".ref($actual_input->{parent})."\n";
+
 # Take screen of said element
 $actual_input->screenshot({ path => 'test.jpg' });
 

+ 2 - 1
lib/Playwright.pm

@@ -255,7 +255,8 @@ sub _build_classes {
             return $class->new(
                 handle => $self,
                 id     => $res->{_guid},
-                type   => $class
+                type   => $class,
+                parent => $self,
             );
         };
 

+ 10 - 8
lib/Playwright/Base.pm

@@ -35,9 +35,10 @@ Creates a new page and returns a handle to interact with it.
 
 =head3 INPUT
 
-    handle (Playwright) : Playwright object.
-    id (STRING)         : _guid returned by a response from the Playwright server with the provided type.
-    type (STRING)       : Type to actually use
+    handle (Playwright)    : Playwright object.
+    id (STRING)            : _guid returned by a response from the Playwright server with the provided type.
+    type (STRING)          : Type to actually use
+    parent (Playwright::*) : Parent Object (such as a page)
 
 =cut
 
@@ -45,11 +46,12 @@ sub new ( $class, %options ) {
 
     my $self = bless(
         {
-            spec => $Playwright::spec->{ $options{type} }{members},
-            type => $options{type},
-            guid => $options{id},
-            ua   => $options{handle}{ua},
-            port => $options{handle}{port},
+            spec   => $Playwright::spec->{ $options{type} }{members},
+            type   => $options{type},
+            guid   => $options{id},
+            ua     => $options{handle}{ua},
+            port   => $options{handle}{port},
+            parent => $options{parent},
         },
         $class
     );