Эх сурвалжийг харах

Move context switching code in Seleium::Firefox

Vangelis Katsikaros 9 жил өмнө
parent
commit
49aa3ebc86

+ 60 - 0
lib/Selenium/Firefox.pm

@@ -2,6 +2,7 @@ package Selenium::Firefox;
 
 # ABSTRACT: Use FirefoxDriver without a Selenium server
 use Moo;
+use Carp;
 use Selenium::Firefox::Binary qw/firefox_path/;
 use Selenium::CanStartBinary::FindBinary qw/coerce_simple_binary coerce_firefox_binary/;
 extends 'Selenium::Remote::Driver';
@@ -244,6 +245,65 @@ has 'firefox_binary' => (
     builder => 'firefox_path'
 );
 
+=head2 get_context
+
+ Description:
+    Firefox extension: Retrieve browser's scope (chrome or content).
+    Chrome is a privileged scope where you can access things like the
+    Firefox UI itself. Content scope is where things like webpages live.
+
+ Output:
+    STRING - context {CHROME|CONTENT}
+
+ Usage:
+    print $firefox_driver->get_context();
+
+=cut
+
+sub get_context {
+    my $self = shift;
+
+    if ( $self->_is_old_ff ) {
+        return 0;
+    }
+    my $res = { 'command' => 'getContext' };
+    return $self->_execute_command($res);
+}
+
+=head2 set_context
+
+ Description:
+    Firefox extension: Set browser's scope (chrome or content).
+    Chrome is a privileged scope where you can access things like the
+    Firefox UI itself. Content scope is where things like webpages live.
+
+ Input:
+    Required:
+        <STRING> - context {CHROME|CONTENT}
+
+ Usage:
+    $firefox_driver->set_context( $context );
+
+ Output:
+    BOOLEAN - success or failure
+
+=cut
+
+sub set_context {
+    my ( $self, $context ) = @_;
+
+    if ( $self->_is_old_ff ) {
+        return 0;
+    }
+    if ( not defined $context ) {
+        croak "Expecting context";
+    }
+    if ( $context !~ m/chrome|content/i ) {
+        croak "Expecting context value: chrome or content";
+    }
+    my $res = { 'command' => 'setContext' };
+    return $self->_execute_command( $res, { context => $context } );
+}
 
 with 'Selenium::CanStartBinary';
 

+ 0 - 61
lib/Selenium/Remote/Driver.pm

@@ -1188,67 +1188,6 @@ sub get_window_size {
     return $self->_execute_command($res);
 }
 
-=head2 get_context
-
- Description:
-    Firefox extension: Retrieve browser's scope (chrome or content).
-    Chrome is a privileged scope where you can access things like the
-    Firefox UI itself. Content scope is where things like webpages live.
-
- Output:
-    STRING - context (values: chrome or content)
-
- Usage:
-    print $firefox_driver->get_context();
-
-=cut
-
-sub get_context {
-    my $self = shift;
-
-    if ( $self->isa('Selenium::Firefox') && $self->_is_old_ff ) {
-        return 0;
-    }
-    my $res = { 'command' => 'getContext' };
-    return $self->_execute_command($res);
-}
-
-=head2 set_context
-
- Description:
-    Firefox extension: Set browser's scope (chrome or content).
-    Chrome is a privileged scope where you can access things like the
-    Firefox UI itself. Content scope is where things like webpages live.
-
- Input:
-    Required:
-        <STRING> - Orientation {CHROME|CONTENT}
-
- Usage:
-    $firefox_driver->set_context( $context  );
-
- Output:
-    BOOLEAN - success or failure
-
-=cut
-
-sub set_context {
-    my ( $self, $context ) = @_;
-
-    if ( $self->isa('Selenium::Firefox') && $self->_is_old_ff ) {
-		return 0;
-	}
-
-    if ( not defined $context ) {
-        croak "Expecting context";
-    }
-    if ( $context !~ m/chrome|content/i ) {
-        croak "Expecting context value: chrome or content";
-    }
-    my $res = { 'command' => 'setContext' };
-    return $self->_execute_command( $res, { context => $context } );
-}
-
 =head2 get_window_position
 
  Description: