Get Browser Information with Intern

By  on  

You know how you can't remember something your spouse feels is really important but you can remember every funny line from that movie you saw when you were 17?  That's how I feel after months of writing selenium tests using the Intern framework -- I've forgotten lots of important front-end stuff but I've uncovered loads of selenium issues and techniques to hack around them.

I initially wrote my tests using Firefox as the test browser.  Then I opened up my testing to Chrome and needed to adjust a whole bunch of stuff because Chrome doesn't reliably do things like Firefox, like element `click` vs. `enter` key press.  And don't ask me about concurrency issues.  Then today I had the bright idea of adding Safari to the mix.  In a word....f*ck.  A whole new world of issues cropped up.

One issue that Selenium + Safari has (one of dozens) is history / URL issues.  After doing loads of research and implementing every hack I could think of, I had this moment:

Fuck It

If there's a Selenium issue in a given browser that makes it impossible for a test to complete properly, there's no point in fighting it -- this case calls for simply passing the test instead of dealing with the annoyance of seeing a failure due to Selenium error.   But how do you get browser information within a test?


// From within a test function
console.log(this.remote.session.capabilities);

{
  'webdriver.remote.sessionid': 'f4dffffc-8d40-4e21-a862-459109ffabfc',
  browserName: 'safari',
  takesScreenshot: true,
  javascriptEnabled: true,
  version: '8.0.8',
  cssSelectorsEnabled: true,
  platform: 'MAC',
  secureSsl: true,
  remoteFiles: true,
  nativeEvents: false,
  rotatable: false,
  locationContextEnabled: false,
  webStorageEnabled: false,
  applicationCacheEnabled: false,
  supportsNavigationDataUris: true,
  supportsCssTransforms: true,
  supportsExecuteAsync: true,
  mouseEnabled: true,
  touchEnabled: false,
  dynamicViewport: true,
  shortcutKey: '',
  brokenDeleteCookie: false,
  brokenExecuteElementReturn: false,
  brokenExecuteUndefinedReturn: false,
  brokenElementDisplayedOpacity: false,
  brokenElementDisplayedOffscreen: false,
  brokenSubmitElement: true,
  brokenWindowSwitch: true,
  brokenDoubleClick: false,
  brokenCssTransformedSize: true,
  fixedLogTypes: false,
  brokenHtmlTagName: false,
  brokenNullGetSpecAttribute: false,
  brokenNavigation: true,
  brokenMouseEvents: true,
  brokenWindowPosition: true,
  brokenSendKeys: true,
  brokenCookies: true 
}

The session object on the remote provides information about the browser session, including the name (most important) as well as fixes provided by Intern.

In an ideal world you can write all of your Selenium tests in one format and it works within each browser....but we don't live in an ideal world, the same way we need browser hacks within our client side JavaScript.  Being able to get browser name and other information within a test, however, is just another super useful bit of information exposed by Intern!

Recent Features

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

Incredible Demos

  • By
    TextboxList for MooTools and jQuery by Guillermo Rauch

    I'll be honest with you: I still haven't figured out if I like my MooTools teammate Guillermo Rauch. He's got a lot stacked up against him. He's from Argentina so I get IM'ed about 10 times a day about how great Lionel...

  • By
    WebKit Marquee CSS:  Bringin’ Sexy Back

    We all joke about the days of Web yesteryear.  You remember them:  stupid animated GIFs (flames and "coming soon" images, most notably), lame counters, guestbooks, applets, etc.  Another "feature" we thought we had gotten rid of was the marquee.  The marquee was a rudimentary, javascript-like...

Discussion

  1. Pablo

    Nice to hear that I’m not the only one that feels that way at times. Make sure you get back to delivering awesome content in due time though! :D

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!