开发者

Access browser session files or cache through Selenium/PHPunit

开发者 https://www.devze.com 2023-02-25 10:24 出处:网络
I am trying to download pictures from a site through Selenium. Examples I found so far advised to retrieve the pictures URL via selenium, then download the picture with an HTTP library such as cURL.

I am trying to download pictures from a site through Selenium. Examples I found so far advised to retrieve the pictures URL via selenium, then download the picture with an HTTP library such as cURL.

Since the pictures are already downloaded in the first place when running the Seleniu开发者_开发百科m test I found making another separate request for each picture not to be a good idea.

Is there a way I can get the pictures from the browser cache via Selenium/PHPunit (or maybe locally if the selenium server stored them locally in a temporary session folder)?

Thanks.


Its an old question, but since I've been working with Selenium recently, I figured I'd put this here for anyone that stumbles on this.

In my readings on Selenium and in practice, the issue here is that the browser cache is not handled directly by Selenium, so the code to access the cache would have to be on a per-browser basis, and very likely to be brittle.

Using the CURL method would guarantee getting the images needed.

It would be great if Selenium did allow access to the cached versions of files, just as it can take screenshots (would a screenshot suffice?)

You can do that in PHPUnit like so:

require_once 'PHPUnit/Extensions/SeleniumTestCase.php';

class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected $captureScreenshotOnFailure = FALSE;
    protected $screenshotPath = 'C:\selenium\screenshots';
    protected $screenshotUrl = 'http://localhost/screenshots';

... (write tests here)
}

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号