Giter Club home page Giter Club logo

test_automation_firefox_password_manager's Introduction

Test Automation Firefox Password Manager

A very basic Firefox plugin that allows updating the Password Manager at runtime using Javascript. When used in concert with the AuthoAuth plugin (https://addons.mozilla.org/en-US/firefox/addon/autoauth/ ), ActiveDirectory authentication dialogs will no longer cause your tests to fail.

Why it's awesome

Until this plugin arrived, it has been impossible to dynamically add passwords to Firefox's Password Manager at runtime. This prevents using Firefox for testing websites that authenticate against ActiveDirectory. There are work arounds (as documented here: http://watirmelon.com/2012/06/27/automatic-firefox-authentication-when-using-selenium-webdriver-with-autoauth/ ) but you are then stuck with the burden of having to maintain a Firefox profile. Now, instead, you can go back to using dynamically created profiles at runtime and by calling a simple javascript function you can add as many host/username/password combinations as you like.

Why it's rubbish

Javascript can only be injected and executed into a page that has already been loaded. This is frustrating because you can only update the Password Manager once the first page has loaded. The implications of this are that you need to first navigate to a page that doesn't present a password prompt, update the Password Manager from that page and only then should you navigate to the page that presents the password prompt. I'd love for someone to replace this plugin with something that doesn't require this extra step.

How to use it

(NB: the following examples demonstrate how to use this plugin with capybara and ruby but the principles should carry across to anything else that can inject javascript into Firefox at runtime)

Download the plugins

First, you'll need to download test-automation-password-manager.xpi from https://addons.mozilla.org/en-us/firefox/addon/test-automation-password-ma/, and you'll also need to download the latest AutoAuth plugin file (autoauth-2.1-fx+fn.xpi at time of writing) from https://addons.mozilla.org/en-US/firefox/addon/autoauth/ . Add both of them to a directory in your test project called ff_plugins.

Direct links here:

Add the plugins to a dynamically created Firefox profile

When you create your Firefox Profile at runtime, you'll need to add this plugin and the AutoAuth plugin:

Capybara.register_driver :selenium_firefox do |app|
  #create the profile:
  profile = Selenium::WebDriver::Firefox::Profile.new

  #add the 2 plugins
  profile.add_extension(File.expand_path("ff_plugins/autoauth-2.1-fx+fn.xpi"))
  profile.add_extension(File.expand_path("ff_plugins/test-automation-password-manager.xpi"))

  Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end

Update Password Manager

The following code shows how to add details to the Password Manager at runtime:

#navigate to a page that won't prompt you for a password:
visit 'http://www.google.com'

#create the javascript that will send the relevant details to the password manager:
pass_man_update_script = <<-SCRIPT
var addCredentialsEvent = new CustomEvent("add_credentials_to_passman", {
  detail: {
    host: 'http://secure.example.com',
    username: 'bob',
    password: 'P45sword',
    realm: 'realm'
  }
});
window.dispatchEvent(addCredentialsEvent);
SCRIPT

#inject the script into the browser:
page.execute_script pass_man_update_script

#navigate to the page that prompts you for a password:
visit 'http://super_secure.example.com' 
#This used to present a password dialog that would cause the test to
#fail, but now it doesn't! Woo!

Disclaimer

  • I am not a javascript dev
  • I am not a Firefox Addon dev
  • I only tested this against my current set up as I don't have anything else to test it against
  • I developed it against Firefox 15.0.1 and haven't tested it against anything else

Please feel free to send me pull requests, or even better, make a better version of this plugin. The sooner I can retire this, the happier I'll be.

test_automation_firefox_password_manager's People

Contributors

natritmeyer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.