2016-11-03 7 views
0

だから私はすべてのファイルと、このスクリプトセレンスタンドアロンサーバー、クロムwebdriverをとthis PHP Web Driverを使用してfile_get_contentsは、ブラウザのキャッシュされたイメージを、セレンでURLに移動すると使用しますか?

<?php 
    require_once('../_libTest/__init__.php'); 

    class cacheTest 
    { 
     private $driver; 

     function __construct() 
     { 

      $host = 'http://localhost:4444/wd/hub'; // this is the default 
      //$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'chrome'); 

      $capabilities = DesiredCapabilities::chrome(); 
      $options = new ChromeOptions(); 
      /*$options->addExtensions(array(
             '3.2.1_0.crx' 
            ));*/ 
      $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); 

      $this->driver = RemoteWebDriver::create($host, $capabilities,86400000,86400000); 

     } 



     function run() 
     { 
      $url = "https://www.google.com.au/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"; 
      $this->driver->get($url); 
      $filename = explode("/",$url); 
      $filename = end($filename); 
      $image = file_get_contents($url); 
      file_put_contents($filename,$image); 

      //$this->driver->quit(); 
     } 
    } 


    $app = new cacheTest(); 


    $app->run(); 
?> 

は、(すべての名前空間を削除するために編集した)私はChromeブラウザウィンドウを開くことができ__init__.phpファイルに含まれていキャッシュ画像(Chromeの閲覧履歴におけるので、オプションをofternする時間ブラウザを保存するために、画像やファイルをキャッシュ」、file_get_contentsおよびしかし

私は疑問に思ってfile_put_contentsを使用して、それをダウンロードして、Googleのロゴ画像のURLに移動します。 ")i ru nセレニウムを使用して画像に直接ナビゲートすると、file_get_contentsはブラウザのキャッシュされた画像を取得していますか、サーバーから新鮮な画像が得られますか?答えherehereによると、答えは何しかし、私の場合は、->get($url)最初

答えて

0

を経由して最初のページをアップロードしていないかもしれません

私はこれを達成するための最良の方法は、カスタムブラウザプロファイルを作成することだと思います、キャッシングが無効になっていて、あなたが起動したときにそのプロファイルを使用するようセレンに指示します。どのような場合でも、テストのためのカスタムプロファイルを使用する方が、設定をより詳細に制御できるため、デフォルトを開くよりも優れています。 Firefoxの(ウィンドウボックス)用

例:

1. In a shell, run firefox.exe -p, name profile selenium_tester and place in a folder of choice 
2. start firefox with profile 
3. about:config 
4. network.automatic-ntlm-auth.trusted-uris AND network.negotiate-auth.trusted-uris -- URLs of sites to bypass for selenium (localhost, etc) 
5. network.automatic-ntlm-auth.allow-non-fqdn TRUE 
6. browser.cache.disk.enable SET TO FALSE 

その後、セレンを起動:

IE、ChromeとFirefoxの(私は読みやすくするために、\で分割するが、実行しているときに、これらを削除しましたプロンプトウィンドウ)クロムでプロファイルを作成する方法の

START java -DfirefoxProfileTemplate=E:\FIREFOX_PROFILE_FOLDER\selenium_tester \ 
-Dwebdriver.firefox.profile=selenium_tester \ 
-Dwebdriver.ie.driver=E:\DRIVERS_FOLDER\IEDriverServer.exe \ 
-Dwebdriver.chrome.driver=E:\DRIVERS_FOLDER\chromedriver.exe \ 
-Dwebdriver.gecko.driver=E:\DRIVERS_FOLDER\geckodriver.exe -jar \ 
E:\SELENIUM_LOCATION\selenium-server-standalone-3.0.1.jar 

リソース:http://www.labnol.org/software/create-family-profiles-in-google-chrome/4394/

クロムのキャッシュを無効にする:(FirefoxよりもPITAのほうが多いように見える) Disabling Chrome cache for website development

関連する問題