I want to run tests with Firefox/protractor with the cache feature disabled.
(Actually, I'm trying to prevent 304 HTTP responses).
There are multiple ways to do this:
Disable the cache from the backend-side by droping Etag headers -> I can't modify the backend
Drop the Etag header from the frontend-side -> I tried, it did not work
Disable the cache from firefox: I just have to set the flag network.http.use-cache to false
Manually it works. I receive only 200 responses and it's great.
I want to be able to set this flag through protractor configuration. After some search I found out that I had to create a custom profile and set it in protractor this way (https://code.google.com/p/selenium/wiki/DesiredCapabilities):
capabilities: {
browserName: 'firefox',
firefox_profile: 'support/firefox_profile'
}
The problem is that the firefox profile is not considered. Is it the right option?
Do you have a better idea?
Thanks for your help.
EDIT:
As someone (suggested
capabilities: {
prefs: {
'config.http.use-cache': false
}
}
It did not work - I checked in about:config, the flag was still enabled.
How do you know what options you can pass in the capabilities?
Here's an example of how to integrate firefox-profile with protractor: https://github.com/juliemr/protractor-demo/tree/master/howtos/setFirefoxProfile
EDIT: For those upgrading to protractor >=1.6, the old way of doing this was broken because 'browser' can no longer return a promise. The demo has been updated.
Related
I'm automating a website and sometimes it uses an ip address as url, that ip address generates a connection is not secure message in Firefox. Researching online I found out that for Firefox, the default in chimp is acceptInsecureCerts = False. That doesn't happen to Chrome as the default is acceptInsecureCerts = True.
How can I change that in Chimp to make it also work in Firefox? Do I need to create a profile? If so, how can I do that? Thanks!
This is more of a WebdriverIO config than Chimp. See here how you can set acceptInsecureCerts using the desiredCapabilities section of the config like this:
module.exports {
webdriverio: {
desiredCapabilities: {
browserName": "firefox",
acceptInsecureCerts": true
}
}
}
The config above goes in the Chimp config file. See here for details
See the full Chimp config here
See the Webdriver.io config here
See the desiredCapbilities support for webdriver here
Note that browsers have their own extra desiredCapabilities, like Chrome for example.
I am facing the cache issue whenever I do a new deployment, changes are not reflecting automatically. Always I have to go to the browser setting and clear the cache.
Is there a way to handle this issue automatically whenever I do the new deployment.
requirejs.config({
// Path mappings for the logical module names
paths: {
'knockout': 'libs/knockout/knockout-3.4.0',
'jquery': 'libs/jquery/jquery-3.1.1.min',
'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.0',
'promise': 'libs/es6-promise/es6-promise.min',
'ojs': 'libs/oj/v3.2.0/min',
'ojL10n': 'libs/oj/v3.2.0/ojL10n',
'ojtranslations': 'libs/oj/v3.2.0/resources',
'signals': 'libs/js-signals/signals.min',
'text': 'libs/require/text',
'hammerjs': 'libs/hammer/hammer-2.0.8.min',
'moment': 'libs/moment/moment.min',
'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0.min',
'customElements': 'libs/webcomponents/CustomElements'
},
waitSeconds: 0,
// urlArgs will be appended at end of .js files
urlArgs: "v=1.33",
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
},
config: {
ojL10n: {
merge: {
//'ojtranslations/nls/ojtranslations': 'resources/nls/menu'
}
}
}
});
You can update version (by changing urlArgs parameter in configuration) every time you deploy new code, thus every time new JavaScript file will be downloaded.
This can always be a problem during development. There are a couple of solutions.
1) Build into your app URL, a version string. Every time you publish a new version, change that number and the browser will pull new files
2) Set the cache control values on your server so that it doesn't cache anything from your app directory
3) Just do what you're doing with clearing browser cache. There are utilities that add a button on the browser bar to make it easier to get at.
I personally use the node http-server library to run my dev work and I use it's cache control arguments to make sure nothing is being cached.
http-server -c-1 -o
The above turns off caching and launches the browser from the current location (loading index.html if present)
With Chrome: if you open the Developer Tools (F12), on the Network tab you can check the Disable cache checkbox, which turns off caching, while the DevTools is open.
With Firefox: if you open the Developer Tools (F12), click the cogwheel icon ("Toolbox Options"), then in the "Advanced Settings" section, check the Disable Cache (when toolbox is open) checkbox.
Now there will be no caching in the browser. Might slow down stuff seriously...
I'm trying to turn of the Firefox native events on Linux. I tried to set the following in my protractor.conf.js file:
capabilities: {
browserName: 'firefox'
nativeEvents: true
}
.....
But it doesn't seem to work at all. This capability looks like a correct one because if I substitute its value to 'true' instead of true, the underlying WebDriver throws ClassCastExceptio: cannot cast String to Boolean.
I also tried to manually create the firefox profile (as described here) but still no luck.
Idea how to enable the native events in Firefox on Linux?
Is there any way to dynamically change the proxy being used by Firefox when using selenium webdriver?
Currently I have proxy support using a proxy profile but is there a way to change the proxy when the browser is alive and running?
My current code:
proxy = Proxy({
'proxyType': 'MANUAL',
'httpProxy': proxy_ip,
'ftpProxy': proxy_ip,
'sslProxy': proxy_ip,
'noProxy': '' # set this value as desired
})
browser = webdriver.Firefox(proxy=proxy)
Thanks in advance.
This is a slightly old question.
But it is actually possible to change the proxies dynamically thru a "hacky way"
I am going to use Selenium JS with Firefox but you can follow thru in the language you want.
Step 1: Visiting "about:config"
driver.get("about:config");
Step 2 : Run script that changes proxy
var setupScript=`var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.proxy.type", 1);
prefs.setCharPref("network.proxy.http", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.http_port", "${proxyUsed.port}");
prefs.setCharPref("network.proxy.ssl", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.ssl_port", "${proxyUsed.port}");
prefs.setCharPref("network.proxy.ftp", "${proxyUsed.host}");
prefs.setIntPref("network.proxy.ftp_port", "${proxyUsed.port}");
`;
//running script below
driver.executeScript(setupScript);
//sleep for 1 sec
driver.sleep(1000);
Where use ${abcd} is where you put your variables, in the above example I am using ES6 which handles concatenation as shown, you can use other concatenation methods of your choice , depending on your language.
Step 3: : Visit your site
driver.get("http://whatismyip.com");
Explanation:the above code takes advantage of Firefox's API to change the preferences using JavaScript code.
As far as I know there are only two ways to change the proxy setting, one via a profile (which you are using) and the other using the capabilities of a driver when you instantiate it as per here. Sadly neither of these methods do what you want as they both happen before as you create your driver.
I have to ask, why is it you want to change your proxy settings? The only solution I can easily think of is to point firefox to a proxy that you can change at runtime. I am not sure but that might be possible with browsermob-proxy.
One possible solution is to close the webdriver instance and create it again after each operation by passing a new configuration in the browser profile
Have a try selenium-wire, It can even override header field
from seleniumwire import webdriver
options = {
'proxy': {
"http": "http://" + IP_PORT,
"https": "http://" + IP_PORT,
'custom_authorization':AUTH
},
'connection_keep_alive': True,
'connection_timeout': 30,
'verify_ssl': False
}
# Create a new instance of the Firefox driver
driver = webdriver.Firefox(seleniumwire_options=options)
driver.header_overrides = {
'Proxy-Authorization': AUTH
}
# Go to the Google home page
driver.get("http://whatismyip.com")
driver.close()
It's not adding anything and it makes the page slower and I want it gone. Don't ask. There's little about the profiler on the website and nothing in the app config.
This setting is in app/config/config_dev.yml:
web_profiler:
toolbar: true
intercept_redirects: false
Additional: if you want to disable it for a special action in your controller than use this:
if ($this->container->has('profiler'))
{
$this->container->get('profiler')->disable();
}
If you set framework.profiler.collect to false in your config.yml, the profiler bar won't be shown (even if web_profiler.toolbar is set to true).
framework:
profiler:
collect: false
This then allows you to selectively activate collectors in your code manually, like this:
$this->container->get('profiler')->enable();
Documentation here: http://symfony.com/doc/current/reference/configuration/framework.html#collect
If you have created a new Symfony project since Symfony 2.5, these parameters are set in app/config/paramaters.yml
parameters:
# ...
debug_toolbar: true
debug_redirects: false
Just set debug_toolbar to false.
Symfony 5.3.7
I changed the toolbar value to false in the web_profiler.yaml and the toolbar was disabled.
{# [root_directory]/config/packages/dev/web_profiler.yaml #}
web_profiler:
toolbar: true --> Change to false
intercept_redirects: false
Try this
framework:
profiler: { only_exceptions: true }
in your app/config/config_dev.yml
To still get output in /_profiler but without the toolbar, you can cheat:
$request->headers->add(array('X-Requested-With' => 'XMLHttpRequest'));
That's because in WebProfilerBundle/EventListener/WebDebugToolbarListener.php there's an explicit check for this before injecting the toolbar.
If you are worried about performance - then you should not be running under dev. Dev also limits caching and can pull in additional bundles.
Run in prod mode and warm your cache before you run performance tests.
Another way that seems to disable it, is to not have _dev in the routing of the application.
So for me in a bitnami install of Symfony 2, simply by changing app/conf/httpd-app.conf slightly it would change the program:
RewriteBase /symfony/app_dev.php
to
RewriteBase /symfony/
and it would keep the toolbar from coming up.