Explorar el Código

Use TestHarness to set up test fixtures

Daniel Gempesaw hace 11 años
padre
commit
0d200146d6
Se han modificado 5 ficheros con 40 adiciones y 118 borrados
  1. 7 23
      t/01-driver.t
  2. 8 23
      t/02-webelement.t
  3. 8 23
      t/10-switch-to-window.t
  4. 10 24
      t/Firefox-Profile.t
  5. 7 25
      t/Test-Selenium-Remote-Driver-google.t

+ 7 - 23
t/01-driver.t

@@ -10,31 +10,18 @@ use Selenium::Remote::Driver;
 use Selenium::Remote::Mock::Commands;
 use Selenium::Remote::Mock::RemoteConnection;
 
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use TestHarness;
 
-my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
-my $os  = $^O;
-if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
-    $os = 'linux';
-}
-my %selenium_args = (
-    browser_name => 'firefox'
+my $harness = TestHarness->new(
+    this_file => $FindBin::Script
 );
-
-
-my $mock_file = "01-driver-mock-$os.json";
-if (!$record && !(-e "t/mock-recordings/$mock_file")) {
+my %selenium_args = %{ $harness->base_caps };
+unless ($harness->mocks_exist_for_platform) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) {
-    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
-}
-else {
-    $selenium_args{remote_conn} =
-      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
-        replay_file => "t/mock-recordings/$mock_file" );
-}
-
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
 my $website = 'http://localhost:63636';
 my $ret;
@@ -477,8 +464,5 @@ NO_SERVER_ERROR_MESSAGE: {
     };
     unlike($@, qr/Use of uninitialized value/, "Error message for no server at host/port combination is helpful");
 }
-if ($record) {
-    $driver->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
-}
 
 done_testing;

+ 8 - 23
t/02-webelement.t

@@ -5,27 +5,16 @@ use Test::More;
 use Selenium::Remote::Driver;
 use Selenium::Remote::Mock::RemoteConnection;
 
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use TestHarness;
 
-
-my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
-my $os  = $^O;
-if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
-    $os = 'linux';
-}
-my $mock_file = "02-webelement-mock-$os.json";
-if (!$record && !(-e "t/mock-recordings/$mock_file")) {
-    plan skip_all => "Mocking of tests is not been enabled for this platform";
-}
-my %selenium_args = (
-    browser_name => 'firefox'
+my $harness = TestHarness->new(
+    this_file => $FindBin::Script
 );
-if ($record) {
-    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
-}
-else {
-    $selenium_args{remote_conn} =
-      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
-        replay_file => "t/mock-recordings/$mock_file" );
+my %selenium_args = %{ $harness->base_caps };
+unless ($harness->mocks_exist_for_platform) {
+    plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
@@ -128,8 +117,4 @@ QUIT: {
     ok((not defined $driver->{'session_id'}), 'Killed the remote session');
 }
 
-if ($record) {
-    $driver->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
-}
-
 done_testing;

+ 8 - 23
t/10-switch-to-window.t

@@ -6,33 +6,22 @@ use Test::More;
 use Test::Selenium::Remote::Driver;
 use Selenium::Remote::Mock::RemoteConnection;
 
-my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
-my $os  = $^O;
-if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
-    $os = 'linux';
-}
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use TestHarness;
 
+my $harness = TestHarness->new(
+    this_file => $FindBin::Script
+);
 my %selenium_args = (
-    browser_name => 'firefox',
     default_finder => 'css',
     javascript     => 1,
+    %{ $harness->base_caps }
 );
-
-my $mock_file = "10-switch-to-window-mock-$os.json";
-if (!$record && !(-e "t/mock-recordings/$mock_file")) {
+unless ($harness->mocks_exist_for_platform) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) {
-    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
-}
-else {
-    $selenium_args{remote_conn} =
-      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
-        replay_file => "t/mock-recordings/$mock_file" );
-}
-
-
 plan tests => 9;
 
 my $s = Test::Selenium::Remote::Driver->new(
@@ -71,7 +60,3 @@ $s->title_is($cpan_title);
 
 $s->switch_to_window('perlorg');
 $s->title_is($perl_title);
-
-if ($record) {
-    $s->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
-}

+ 10 - 24
t/Firefox-Profile.t

@@ -13,30 +13,18 @@ use JSON;
 use Selenium::Remote::Mock::RemoteConnection;
 use Selenium::Remote::Driver::Firefox::Profile;
 
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use TestHarness;
 
-my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
-my $os  = $^O;
-if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
-    $os = 'linux';
-}
-my $mock_file = "firefox-profile-mock-$os.json";
-if (!$record && !(-e "t/mock-recordings/$mock_file")) {
-    plan skip_all => "Mocking of tests is not been enabled for this platform";
-}
-
-my %selenium_args = (
-    browser_name => 'firefox'
+my $harness = TestHarness->new(
+    this_file => $FindBin::Script
 );
-if ($record) {
-    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
-}
-else {
-    $selenium_args{remote_conn} =
-      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
-        replay_file => "t/mock-recordings/$mock_file" );
+my %selenium_args = %{ $harness->base_caps };
+unless ($harness->mocks_exist_for_platform) {
+    plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-
 CUSTOM_EXTENSION_LOADED: {
     my $profile = Selenium::Remote::Driver::Firefox::Profile->new;
     my $website = 'http://localhost:63636';
@@ -46,7 +34,7 @@ CUSTOM_EXTENSION_LOADED: {
     # Set this to true to re-encode the profile. This should not need
     # to happen often.
     my $create_new_profile = 0;
-    if ($record && $create_new_profile) {
+    if ($create_new_profile) {
         $profile->set_preference(
             'browser.startup.homepage' => $website
         );
@@ -193,7 +181,5 @@ CROAKING: {
         ok ($@ =~ /coercion.*failed/, "caught invalid extension in driver constructor");
     }
 }
-if ($record) {
-    $selenium_args{remote_conn}->dump_session_store("t/mock-recordings/$mock_file");
-}
+
 done_testing;

+ 7 - 25
t/Test-Selenium-Remote-Driver-google.t

@@ -5,31 +5,18 @@ use Test::More;
 use Test::Selenium::Remote::Driver;
 use Selenium::Remote::Mock::RemoteConnection;
 
-my $record = (defined $ENV{'WD_MOCKING_RECORD'} && ($ENV{'WD_MOCKING_RECORD'}==1))?1:0;
-my $os  = $^O;
-if ($os =~ m/(aix|freebsd|openbsd|sunos|solaris)/) {
-    $os = 'linux';
-}
+use FindBin;
+use lib $FindBin::Bin . '/lib';
+use TestHarness;
 
-my %selenium_args = (
-    browser_name => 'firefox',
-    javascript => 1
+my $harness = TestHarness->new(
+    this_file => $FindBin::Script
 );
-
-my $mock_file = "test-selenium-remote-driver-google-$os.json";
-if (!$record && !(-e "t/mock-recordings/$mock_file")) {
+my %selenium_args = %{ $harness->base_caps };
+unless ($harness->mocks_exist_for_platform) {
     plan skip_all => "Mocking of tests is not been enabled for this platform";
 }
 
-if ($record) {
-    $selenium_args{remote_conn} = Selenium::Remote::Mock::RemoteConnection->new(record => 1);
-}
-else {
-    $selenium_args{remote_conn} =
-      Selenium::Remote::Mock::RemoteConnection->new( replay => 1,
-        replay_file => "t/mock-recordings/$mock_file" );
-}
-
 # Try to find
 my $t = Test::Selenium::Remote::Driver->new(
     %selenium_args
@@ -38,9 +25,4 @@ $t->get_ok('http://www.google.com');
 $t->title_like(qr/Google/);
 $t->body_like(qr/Google/);
 
-if ($record) {
-    $t->remote_conn->dump_session_store("t/mock-recordings/$mock_file");
-}
-
-
 done_testing();