-
Notifications
You must be signed in to change notification settings - Fork 0
WebBrowserFlags
Web browsers are complex software applications. It is unsurprising that there are differences in functionality between them. WebDriver has a built-in mechanism which gets us some of the way toward recognising differences between browsers. That mechanism is 'Capabilities' but sometimes that's insufficient.
Browser flags are a collection of arbitrary binary feature/functionality indicators for web browsers. Each flag is a string and for a given WebDriver it is either present or not present.
At runtime, consuming code may query a WebDriver to determine whether a flag is, or is not present.
if(myWebDriver.HasFlag("MyFlag"))
// Code for browsers with 'MyFlag'
else
// Code for browsers without 'MyFlag'Flags may be added to a WebDriver instance arbitrarily at runtime. The mechanism comes into its own when flags are assigned from a flags configuration, based upon the exact browser and version in-use.
Consuming applications which use browser flags may create configuration mappings between browsers and the flags they should receive. These configuration files are written in a JSON format, identifying browsers via the following properties.
- Browser name
- Version number
- Platform
Here is a sample use-case for browser flags.
No version of Microsoft Internet Explorer provides 'native' support for the HTML 5 <input type="date"> element. In IE, an input-type-date behaves exactly like an <input type="text"> element.
On the other hand, Google Chrome renders an input-type-date using a built-in calendar component allowing users to interactively choose a date.
As you may imagine, the WebDriver logic to interact with the same input element, across these two different browsers differs wildly. Moreso, it would be painful to use browser-detection and subsequent feature-lookup deep within WebDriver logic.
Here, a series of browser flags would help.
RequiresPickingViaCalendarForHtmlInputTypeDateRequiresTreatingLikeTextForHtmlInputTypeDate
When the WebDriver is created, the browser is identified. This browser identification may be cross-referenced with a registry of which browsers should have which flags. Compatible versions of Google Chrome gain the RequiresPickingViaCalendarForHtmlInputTypeDate flag and all versions of Internet Explorer are assigned the RequiresTreatingLikeTextForHtmlInputTypeDate flag. Subsequent feature-detection within WebDriver logic is simple and clear.