prevent external content to be loaded in selenium webdriver test

前端 未结 2 975
别那么骄傲
别那么骄傲 2020-12-09 06:55

The question:

Is is possible to tell a browser that is controlled by selenium webdriver to not load any content from external sources, or alternatively, not

2条回答
  •  独厮守ぢ
    2020-12-09 07:41

    You can chain the proxy, there isn't much documentation out there about doing so:

    http://www.nerdnuts.com/2014/10/browsermob-behind-a-corporate-proxy/

    We were able to use browsermob behind a corporate proxy using the following code:

    // start the proxy
    server = new ProxyServer(9090);
    server.start();
    
    server.setCaptureContent(true);
    server.setCaptureHeaders(true);
    server.addHeader(“accept-encoding”, “”);//turn off gzip
    
    // Configure proxy server to use our network proxy
    server.setLocalHost(InetAddress.getByName(“127.0.0.1″));
    
    /**
     * THIS IS THE MAJICK!
     **/
    HashMap options = new HashMap();
    options.put(“httpProxy”, “172.20.4.115:8080″);
    server.setOptions(options);
    server.autoBasicAuthorization(“172.20.4.115″, “username”, “password”);
    
    // get the Selenium proxy object
    Proxy proxy = server.seleniumProxy();
    DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
    capabilities.setCapability(CapabilityType.PROXY, proxy);
    

提交回复
热议问题