0

So i have this script

<?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();
?>

using the Selenium standalone server, the Chrome Webdriver and this PHP Web Driver (edited to remove all the namespaces) with all the file includes in the __init__.php file i can open up a Chrome Browser Window, go to the url of the google logo image then download it using file_get_contents and file_put_contents

however i am wondering, since to save time browsers will oftern cache images (thus the option in Chrome's clear browsing history "Caches images and files") when i run Selenium and navigate directly to an image, when i use file_get_contents is this then getting the browser's cached image or am i getting a fresh image strait from the server?

According to answers here and here the answer may be no however in my case i am loading up the page first via ->get($url) first

Community
  • 1
  • 1
Memor-X
  • 2,870
  • 6
  • 33
  • 57

1 Answers1

0

I think the best way to achieve this would be to create a custom browser profile, which has caching disabled, and tell selenium to use that profile when you fire it up. Using a custom profile for testing is better in any case than opening up the default as you have more control over it's settings.

Example for firefox (windows box):

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

Then, fire up selenium:

IE, Chrome and Firefox (I've split with \ for readability but remove these when running in the prompt window)

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

Resource on creating profiles in chrome: http://www.labnol.org/software/create-family-profiles-in-google-chrome/4394/

Disabling cache in chrome: (looks to be more of a PITA than in firefox) Disabling Chrome cache for website development

Community
  • 1
  • 1
John Joseph
  • 921
  • 5
  • 14