9

I've seen (and actually answered) several selenium-specific questions where there is a need to set some particular browser preference to change it's behavior, for example:

In other words, there are tons of questions which can be grouped in two types:

  • I know how to set this preference in browser X, how to do the same in browser Y?
  • How to make browser X, Y and Z do something by configuring their preferences?

This is usually done via setting/configuring:

  • FirefoxProfile for Firefox
  • ChromeOptions for Chrome
  • DesiredCapabilities for Internet Explorer

What is a preferred and most efficient strategy to find browser-specific solutions for a particular problem? Is there a mapping between preferences across major browsers?

For example, I've found out that to disable cache in Firefox, I can set browser.cache.disk.enable, browser.cache.memory.enable, browser.cache.offline.enable and network.http.use-cache preferences to false. How can I know how to do the same in Chrome and IE?

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 2
    I guess this is not an easy thing to achieve. Selenium can try dealing with it at a higher level, but there are tons of capabilities. Different browsers support different sets of capabilities. For example, IE may have exposed only very limited ones. Also remember we have Safari, Opera and PhantomJS to worry about as well. In my opinion, if those browsers don't provide a well-maintained comprehensive list of all capabilities in the first place, then Selenium cannot do much about it. As Selenium users, we can maintain a list for everything we know, but that won't solve the problem completely. – Yi Zeng Sep 11 '14 at 02:06
  • 1
    @YiZeng yeah, this is what I was worried about. I guess it would be nice to have some sort of a code base, or code snippet service that would at least provide a set of browser-specific solutions for common use cases, or some sort of a mapping between capabilities/options across major browsers. You can post the comment as an answer - it raises a good point. Thank you. – alecxe Sep 11 '14 at 02:29
  • It's a good point but I wanted to mention that ultimately `FirefoxProfile` and `ChromeOptions` are just wrappers over `DesiredCapabilities`. (Similarly IE will have `InternetExplorerOptions`). Everything, in the end, is converted down to a dictionary of `DesiredCapabilities`. – Arran Sep 11 '14 at 08:55

1 Answers1

6

To highlight what I mean will crunch down Wikipedia article to 1 sentence :

Selenium WebDriver ... is implemented through a browser-specific browser driver, which ... aims to provide a basic set of building blocks from which developers can create their own Domain Specific Language.

What is a preferred and most efficient strategy to find browser-specific solutions for a particular problem?

Rather try to think it this way: If particular browser implements a feature then there is a good chance that selenium driver exposes it. You know if feature is implemented if you can solve it manually.

I decently effective problem solving algorithm for you: CS || RTM || UTSL

  1. [CS] Can you solve problem manually? Try to use same steps.
  2. [RTM] Can you find the manual or example? Chances are that others have solved you problem.
  3. [UTSL] If common sense and RTM did not work, then
    • Manual can tell you how stuff should work.
    • Source can tell you how stuff does work.

enter image description here Image is from Jeff Atwood blog post.

Is there a mapping between preferences across major browsers?

No, preferences are not consolidated across drivers. Drivers have their specifics and tradeoffs.

Different browsers or even browser versions support different sets of capabilities. Some of them lack even common things. Some of those features are covered by selenium in order for it to provide basic functionality that it has. Example of this would be older IE does not support xPath and Selenium has to simulate this behavior. You can not make assumption it adds behavior to take account for every quirk in every browser to create a common platform (that would be a wicked problem).

I suggest you read Wicked problem : Strategies to tackle wicked problems.

Knowing how to disable cache in Firefox, how can I know how to do the same in ...?

To do same in chrome you could run chrome driver with --disable-application-cache argument. To see what flags your current Chrome can set you can browse to chrome://flags/ inside chrome. Alternative way would be to look up available source.

Alternative name for IE would be mother lode of quirks. This is where you need to do research. One way would be to call RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess nr

Where nr is flag field:

  • 255 (Deletes ALL History)
  • 1 (Deletes History Only)
  • 2 (Deletes Cookies Only)
  • 8 (Deletes Temporary Internet Files Only)
  • 16 (Deletes Form Data Only)
  • 32 (Deletes Password History Only)

This source claims that as of May 2013 IE might have desiredCapabilities.ensureCleanSession to clear cache, however I have not tested it.

Community
  • 1
  • 1
Margus
  • 19,694
  • 14
  • 55
  • 103
  • I was afraid to believe that this is a wicked problem, but now I know how to tackle it. Very good (and sometimes funny) insight. Thank you! – alecxe Sep 23 '14 at 13:17
  • **--disable-application-cache** has deprecated. Regards, Evgeny https://code.google.com/p/chromium/issues/detail?id=447206 – zablotski Apr 28 '15 at 22:47
  • Would like to upvote this answer, but it fails to address the question. How does one "discover" all the settings, or even all the supported args, without reading the open source. Reading the source assumes everyone reading can tell apart deprecated code from live code. I'm game to assist with any brute force documentation efforts. –  Apr 07 '21 at 08:42