Просмотр исходного кода

Refactor Firefox Profile tests and add os x recordings

Daniel Gempesaw 11 лет назад
Родитель
Сommit
e0c4080615

+ 16 - 27
t/Firefox-Profile.t

@@ -39,33 +39,31 @@ if (!$record && !(-e "t/mock-recordings/$mock_file"))
 }
 t::lib::MockSeleniumWebDriver::register($record,"t/mock-recordings/$mock_file");
 
-# Start our local http server
-if ($^O eq 'MSWin32' && $record)
-{
-    system("start \"TEMP_HTTP_SERVER\" /MIN perl t/http-server.pl");
-} elsif ($record)
-{
-    system("perl t/http-server.pl > /dev/null &");
-}
-
 CUSTOM_EXTENSION_LOADED: {
     my $profile = Selenium::Remote::Driver::Firefox::Profile->new();
+
+    my $website = 'http://localhost:63636';
     $profile->set_preferences(
-        "browser.startup.homepage" => "http://www.google.com"
+        'browser.startup.homepage' => $website
     );
 
-    # This extension rewrites any page url that matches *.com to a
-    # single <h1>. The following javascript is in redisplay.xpi's
+    # This extension rewrites any page url to a single <h1>. The
+    # following javascript is in redisplay.xpi's
     # resources/gempesaw/lib/main.js:
 
     # var pageMod = require("sdk/page-mod");
     # pageMod.PageMod({
-    #     include: "*.com",
+    #     include: "*",
     #     contentScript: 'document.body.innerHTML = ' +
     #         ' "<h1>Page matches ruleset</h1>";'
     # });
     $profile->add_extension('t/www/redisplay.xpi');
 
+    my $filename = "test";
+    open (my $fh, ">", $filename);
+    print $fh $profile->_encode;
+    close ($fh);
+
     my $driver = Selenium::Remote::Driver->new(
         extra_capabilities => {
             firefox_profile => $profile
@@ -74,14 +72,15 @@ CUSTOM_EXTENSION_LOADED: {
 
     ok(defined $driver, "made a driver without dying");
 
-    # the initial automatic homepage load isn't blocking, so we need
-    # to wait until the page is loaded (when we can find elements)
+    # the initial automatic homepage load found in the preference
+    # 'browser.startup.homepage' isn't blocking, so we need to wait
+    # until the page is loaded (when we can find elements)
     $driver->set_implicit_wait_timeout(30000);
     $driver->find_element("h1", "tag_name");
-    cmp_ok($driver->get_title, '=~', qr/google/i,
+    cmp_ok($driver->get_current_url, '=~', qr/localhost/i,
            "profile loaded and preference respected!");
 
-    $driver->get("http://www.google.com");
+    $driver->get($website . '/index.html');
     cmp_ok($driver->get_text("body", "tag_name"), "=~", qr/ruleset/,
            "custom profile with extension loaded");
 }
@@ -161,14 +160,4 @@ CROAKING: {
     }
 }
 
-# Kill our HTTP Server
-if ($^O eq 'MSWin32' && $record)
-{
-   system("taskkill /FI \"WINDOWTITLE eq TEMP_HTTP_SERVER\"");
-}
-elsif ($record)
-{
-    `ps aux | grep http-server\.pl | grep perl | awk '{print \$2}' | xargs kill`;
-}
-
 done_testing;

+ 11 - 4
t/bin/generate-recordings.pl

@@ -2,22 +2,29 @@
 
 use strict;
 use warnings;
-use IPC::Open2;
 
 unless (-d "t" && -f "dist.ini" && -f "t/01-driver.t" && -f "t/02-webelement.t") {
     die "Please run this from the root of the repo.";
 }
 
 startServer();
+
+print `dzil build`;
+
 if ($^O eq 'linux') {
     print "Headless and need a webdriver server started? Try\n\n\tDISPLAY=:1 xvfb-run --auto-servernum java -jar /usr/lib/node_modules/protractor/selenium/selenium-server-standalone-2.40.0.jar\n\n";
 }
 
-my $export = $^O eq 'MSWin32' ? 'set' : 'export';
 my $srdLib = glob('Selenium-Remote-Driver*/lib');
+my @files = (
+    't/01-driver.t',
+    't/02-webelement.t',
+    't/Firefox-Profile.t'
+);
 
-print `dzil build`;
-print `$export WD_MOCKING_RECORD=1 && perl -I$srdLib t/01-driver.t && perl -I$srdLib t/02-webelement.t`;
+my $export = $^O eq 'MSWin32' ? 'set' : 'export';
+my $executeTests = join( ' && ', map { 'perl -I' . $srdLib . ' ' . $_ } @files);
+print `$export WD_MOCKING_RECORD=1 && $executeTests`;
 killServer();
 
 sub startServer {

+ 5 - 0
t/lib/MockSeleniumWebDriver.pm

@@ -61,6 +61,11 @@ sub psgi_app {
     $expected = $expected eq "" ? $expected : decode_json($expected);
     my $actual = $content eq "" ? $content : decode_json($content);
 
+    # ugly hack because the profile is encoded differently every time.
+    if ($actual ne "" && defined $actual->{desiredCapabilities}->{firefox_profile}) {
+        $expected->{desiredCapabilities}->{firefox_profile} = $actual->{desiredCapabilities}->{firefox_profile};
+    }
+
     if (  $self->{req_resp}->[$$req_index]->{request}->{verb} eq $env->{REQUEST_METHOD}
       and $self->{req_resp}->[$$req_index]->{request}->{uri} eq $uri
       and (   $self->{req_resp}->[$$req_index]->{request}->{content} eq $content

Разница между файлами не показана из-за своего большого размера
+ 0 - 0
t/mock-recordings/firefox-profile-mock-darwin.json


Некоторые файлы не были показаны из-за большого количества измененных файлов