瀏覽代碼

Fiddle with Firefox profile scope to keep temp dir around

Previously, when the $profile var in setup_firefox_env_vars went out of
scope at the end of the function, its File::Temp->newdir also went out
of scope and was getting automatically cleaned up. However, we need to
keep the profile directory around until the end of the script since
Firefox needs to be using it the entire time.

So, we've moved profile out of the function so it isn't DESTROY'd until
the end of the script's life time. However, we're running into a race
condition where the Firefox binary is still running while Perl is
DESTROYing everything - so the files in the tempdir are locked. We can't
delete them until after the Firefox process dies...
Daniel Gempesaw 10 年之前
父節點
當前提交
99eae0b979
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      lib/Selenium/Firefox/Binary.pm

+ 4 - 1
lib/Selenium/Firefox/Binary.pm

@@ -60,11 +60,14 @@ sub firefox_path {
     return $path;
 }
 
+# We want the profile to persist to the end of the session, not just
+# the end of this function.
+my $profile;
 sub setup_firefox_binary_env {
     my ($port) = @_;
 
     # TODO: respect the user's profile instead of overwriting it
-    my $profile = Selenium::Firefox::Profile->new;
+    $profile = Selenium::Firefox::Profile->new;
     $profile->add_webdriver($port);
 
     $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;