Automating BrowserID with Selenium

BrowserID is an awesome new approach to handling online identity. If you haven’t heard of it then I highly recommend reading this article, which explains what it is and how it works. Several Mozilla projects have already integrated with BrowserID, including Mozillians, Affiliates, and the Mozilla Developer Network.

With all of these sites now integrating with BrowserID (and more on their way) we needed to add support to our test automation to handle the new sign in process. Initially we started to do this independently in our projects, but the thought of updating all of our projects whenever a tweak was made to BrowserID was daunting to say the least! For this reason I have created a project that contains a page object model for BrowserID. This can be included in other projects as a submodule and then updated and maintained centrally.

The new project is called ‘BIDPOM’ (BrowserID Page Object Model) and can be found here. It currently only contains a page object for the Sign In page, however this currently meets the needs of the automation for projects that have integrated with BrowserID. As we have a mix of projects using Selenium’s two APIs (RC and WebDriver), it was necessary for BIDPOM to support both.

By adding BIDPOM as a submodule, we can easily pull the BrowserID page objects into our automation projects and reference them in a very similar way to the main project’s page objects. We can also update the version of BIDPOM simply by updating the git link and updating the submodule. What’s even better is that our continuous test builds running in Jenkins automatically initialise and update the submodule for us!

I hope that in addition to being a dependency for our own automation projects, this page object model can be utilised by others wanting to create or maintain automated tests using Selenium against sites that adopt BrowserID. If you would like to start using BIDPOM then I have provided below a guide to adding the project as a submodule to an existing git repository.

From within your project, add the BIDPOM project as a git submodule:

cd ~/workspace/automationproject
git submodule add git://github.com/davehunt/bidpom.git browserid

This will add an entry to .gitmodules and clone the BIDPOM project to the browserid subdirectory. It will also stage the new gitlink and .gitmodules items for commit.

You can now commit these changes to your project’s repository:

git commit -m 'Added BrowserID page object model as submodule.'

Before you can test the new submodule you will need to run the following command to copy the contents of .gitmodules into your .git/config file.

git submodule init

Now you can test the submodule by deleting the browserid directory and allowing it to be recreated:

rm -rf browserid
git submodule update

The BIDPOM project should be cloned to the browserid directory.

You will now be able to integrate your project with BrowserID! Here follow a few examples of how to integrate your project.

Example: Short sign-in using Selenium’s RC API

selenium.click('id=login')
from browserid import BrowserID
browser_id = BrowserID(selenium)
browser_id.sign_in('testaccount@example.com', 'password')
assert selenium.is_visible('id=logout')

Example: Long sign-in using Selenium’s RC API

selenium.click('id=login')
from browserid.pages.rc.sign_in import SignIn
signin = SignIn(self.selenium, self.timeout)
signin.email = 'testaccount@example.com'
signin.click_next()
signin.password = 'password'
signin.click_select_email()
signin.click_sign_in()
assert selenium.is_visible('id=logout')

Example: Short sign-in using Selenium’s WebDriver API

selenium.find_element_by_id('login').click()
from browserid import BrowserID
browser_id = BrowserID(selenium)
browser_id.sign_in('testaccount@example.com', 'password')
assert selenium.find_element_by_id('logout').is_displayed()

Example: Long sign-in using Selenium’s WebDriver API

selenium.find_element_by_id('login').click()
from browserid.pages.webdriver.sign_in import SignIn
signin = SignIn(self.selenium, self.timeout)
signin.email = 'testaccount@example.com'
signin.click_next()
signin.password = 'password'
signin.click_select_email()
signin.click_sign_in()
assert selenium.find_element_by_id('logout').is_displayed()

For the latest documentation on the BIDPOM project refer to the github wiki.

3 thoughts on “Automating BrowserID with Selenium”

  1. Pingback: A Smattering of Selenium #80 « Official Selenium Blog

  2. It strikes me that the really awkward/useful/fiddle bit of library code would be the piece which lets you use or create test users… Is there a common bit of code for saying “I want a user that exists/doesn’t exist/does or doesn’t have this password?

    1. We’ve raised an enhancement request against BrowserID to give us a way to create users via an API. This would allow tests to create suitable users as part of their setup. Of course, there would likely also be a need for the application under test to have a similar API.

Leave a Reply to dwh Cancel reply

Your email address will not be published. Required fields are marked *