Jelajahi Sumber

Move the test website and domain up into TestHarness.pm

This will make it easier to change our test fixture website, if we ever
need to, like for the saucelabs branch.
Daniel Gempesaw 11 tahun lalu
induk
melakukan
feb250fbe4
4 mengubah file dengan 24 tambahan dan 5 penghapusan
  1. 3 2
      t/01-driver.t
  2. 3 1
      t/02-webelement.t
  3. 3 2
      t/Firefox-Profile.t
  4. 15 0
      t/lib/TestHarness.pm

+ 3 - 2
t/01-driver.t

@@ -21,7 +21,8 @@ my $harness = TestHarness->new(
 my %selenium_args = %{ $harness->base_caps };
 
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
-my $website = 'http://localhost:63636';
+my $domain = $harness->domain;
+my $website = $harness->website;
 my $ret;
 
 my $chrome;
@@ -217,7 +218,7 @@ COOKIES: {
     pass('Deleting cookies...');
     $ret = $driver->get_all_cookies();
     is(@{$ret}, 0, 'Deleted all cookies.');
-    $ret = $driver->add_cookie('foo', 'bar', '/', 'localhost', 0);
+    $ret = $driver->add_cookie('foo', 'bar', '/', $domain, 0);
     pass('Adding cookie foo...');
     $ret = $driver->get_all_cookies();
     is(@{$ret}, 1, 'foo cookie added.');

+ 3 - 1
t/02-webelement.t

@@ -15,7 +15,9 @@ my $harness = TestHarness->new(
 my %selenium_args = %{ $harness->base_caps };
 
 my $driver = Selenium::Remote::Driver->new(%selenium_args);
-my $website = 'http://localhost:63636';
+my $domain = $harness->domain;
+my $website = $harness->website;
+
 $driver->get("$website/formPage.html");
 my $ret;
 my $elem;

+ 3 - 2
t/Firefox-Profile.t

@@ -26,7 +26,8 @@ my $fixture_dir = $FindBin::Bin . '/www/';
 
 CUSTOM_EXTENSION_LOADED: {
     my $profile = Selenium::Remote::Driver::Firefox::Profile->new;
-    my $website = 'http://localhost:63636';
+    my $domain = $harness->domain;
+    my $website = $harness->website;
     my $mock_encoded_profile = $fixture_dir . 'encoded_profile.b64';
     my $encoded;
 
@@ -74,7 +75,7 @@ CUSTOM_EXTENSION_LOADED: {
     # elements)
     $driver->set_implicit_wait_timeout(30000);
     $driver->find_element("h1", "tag_name");
-    cmp_ok($driver->get_current_url, '=~', qr/localhost/i,
+    cmp_ok($driver->get_current_url, '=~', qr/$domain/i,
            "profile loaded and preference respected!");
 
     $driver->get($website . '/index.html');

+ 15 - 0
t/lib/TestHarness.pm

@@ -129,6 +129,21 @@ has mock_file => (
     }
 );
 
+has website => (
+    is => 'ro',
+    default => sub {
+        my ($self) = @_;
+        my $port = 63636;
+
+        return 'http://' . $self->domain . ':' . $port;
+    }
+);
+
+has domain => (
+    is => 'ro',
+    default => sub { 'localhost' }
+);
+
 sub DEMOLISH {
     my ($self) = @_;
     if ($self->record) {