Integrating OpenID into your testing environment

Published on and tagged with cakephp  openid  selenium  testing

In my previous article I wrote about OpenID and CakePHP. What I didn’t knew at that time was how to integrate OpenID into my Selenium tests.

My first approach was to create an account on MyOpenID and to define the login sequence with Selenium. It worked the first time I tried to login. But as MyOpenID sets a cookie after the login, the login form was no longer shown in subsequent login approaches, and so the Selenium test failed… Maybe I could have solved this problem with Selenium, but as the entire process was rather slow I decided to look for another solution.

And so I found phpMyID, a single user OpenID Identity Provider. It uses HTTP digest authentication, which is a bit of a problem as you cannot fill out the login dialog shown by the browser with JavaScript (which is used by Selenium). To avoid this dialog you have to add the following snippet to the “authorize_mode” function in the MyID.php file (thanks to CJ Niemira for this tip):

// add this snippet after user_session();
$_SESSION['auth_username'] = $profile['auth_username'];
$_SESSION['auth_url'] = $profile['idp_url'];

To use this script with CakePHP I put it into app/webroot and use the following snippet in my Selenium test case to log into my application:

$this->type('name=data[User][openid]', 'http://myproject.localhost/MyID.php');
$this->waitForCondition('parent.myiframe.location.href == "http://myproject.localhost/projects"', '10000');

You can also rename the MyID.php file if you want a more descriptive name, and if you want to use multiple IDs simply copy MyID.php as often as you need.

Happy testing :)

Bake a comment

(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License