A large amount of any developer's time is spent testing. Well, hopefully that's the case. It's true for me at least.
Testing is tedious and boring. Anything that can make it less of a hassle is a godsend. Hopefully this tip will help you out if you do a lot of testing where you need to continuously login and out as different users. I know it's helped me no end since I started doing it.
I don't know how I managed to remain sane before I switched to this technique.
When you setup a new Domino server, enable session-based authentication and then create the domcfg.nsf database you will see this screen when you're required to login:
Apart from looking butt-ugly there's not much wrong with this per se. It works. I wouldn't ever use it on a live site but it normally suffices for the development server.
The problem is when you're doing intensive testing and logging in/out every couple of minutes. You soon get tired of having to type in the name/password of the test user every time.
This is made all the worse by the fact that the default login form that comes with domcfg.nsf has autocomplete="off" in the username and password fields. The means that b won't offer to remember passwords for the form.
You're forced to type the name and password of the user every time even if you use a browser which is able to store them.
One solution is to remove the autocomplete attribute from the fields on the $$LoginUserForm and let your browser store the passwords.
However, even with the browser auto-completing the fields it still requires keyboard use and takes longer than it needs to. What I'm after is the quickest way possible to switch from one user to another.
Before I describe my solution let's make the following assumptions:
- You test on a machine given over primarily to development and testing alone.
- You "own" the server and can make any changes you like to its configuration.
- It's not generally accessed by "normal" users.
- The NAB on the sever contains a set of test users, all of whom have the same HTTP password.
- These test users' credentials can't be used to access any sensitive date elsewhere.
If most of the above are true then why not hard code the usernames and password in to the login form?! Here's what the form could look like:
All you need to do here is change the dropdown to the user you want to login as and press "sign in" (password has already been pre-filled at the server).
Although I lived with this for a couple of days and it was a massive improvement over the original form I still felt it could be simpler and quicker to use. What I came up with is possibly as simple as a multi-user login form could get:
When required to login all you have to do is press the button with the name of the required user on it. Couldn't get much simpler than that. No need to worry about the password as it's pre-filled and hidden using type="hidden".
How Does It Work
This technique makes use of the fact that the humble submit button is nothing more than an input field, which you can give a name and which is submitted with the form as a name/value pair, just like an ordinary field. In this case I've called the button "Username" and removed the actual "username" field from the login form.
The other trick used is that you can have multiple inputs of the same name. When there are lotus of submit buttons with the same name it's the one pressed which sends its value (the text displayed on the button) to the server as the field value. Make sense? The HTML looks something like this:
<td><input type="submit" name="UserName" value="Jordan Quinones"></td> <td><input type="submit" name="UserName" value="Keith Moore"></td> <td><input type="submit" name="UserName" value="Margarito Yarbrough"></td>
Simple! To create the HTML for these buttons all we need is a simple Computed Value on the form. The formula for which is along the lines of:
names:=@Trim(@Sort( "Administrator":"Deandre Hoyt":"Caitlin Hudson":"Allie Jarrett":"Charlie Jacobson": "Reyna McCarthy":"Eliza Mayo":"Dick Mayfield":"Keith Moore": "Jordan Quinones":"Alexander Welch":"Margarito Yarbrough":"":"" )); @Implode("<input type=\"submit\" name=\"UserName\" value=\""+names+"\">"; @NewLine);
In the form I showed you I've used a formula to put them in a nicely-laid-out table though. Download the demo database to see how.
As you can see I've used a hard-coded set of usernames taken at random from the "fakenames" NAB, which I use on most test servers and which contains 40,000 users all with the password of "password".
If your test server's NAB is more normal and just has a handful of "Test One", "Test Two" users then you could even have the formula above do a lookup to get all the usernames for you. For me a handful of users normally suffices.
If you want to use this method in your dev environment then download the modified version of domcfg.nsf now and copy the $$LoginForm over. What will you do with al the time you save...