所以我有这个脚本
<?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();
?>
使用Selenium独立服务器,Chrome Webdriver和this PHP Web Driver(已编辑删除所有名称空间),并在__init__.php
文件中包含所有文件,我可以打开Chrome浏览器窗口,转到然后,使用file_get_contents
和file_put_contents
然而我想知道,因为为了节省时间,当我运行Selenium并直接导航到图像时,浏览器将实时缓存图像(因此Chrome浏览器清晰浏览历史记录中的选项“缓存图像和文件”) ,当我使用file_get_contents
时,这是获取浏览器的缓存图像,还是我从服务器获得一个新的图像海峡?
答案 0 :(得分:0)
我认为实现这一目标的最佳方法是创建一个自定义浏览器配置文件,该配置文件已禁用缓存,并告诉selenium在启动时使用该配置文件。在任何情况下使用自定义配置文件进行测试都比打开默认设置更好,因为您可以更好地控制它的设置。
firefox(Windows框)的示例:
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
在chrome中创建配置文件的资源:http://www.labnol.org/software/create-family-profiles-in-google-chrome/4394/
在chrome中禁用缓存:(看起来更像是PITA而不是firefox) Disabling Chrome cache for website development