Wednesday, August 27, 2014

Bookmarklet for Switching Users

Here is a neat bookmarklet for switching users for testing purposes.  It requires the user id and password to be the same, this is pretty common testing scenario.

Had to make some modifications to the orginal posting to allow it to work with IE, but leaving my original bookmarklet below that works well with Firefox and Chrome.  Use the Click to Copy button to copy the bookmarklet to your clipboard.

javascript:var pswd = prompt("Enter TestUser", "");if (pswd!= null) {var1=window.top.location.pathname.match(/^\/ps[pc]\/(.+?\/)(.+?\/)(.+?\/)/);l=window.top.location.origin;l=l+"/psp/"+var1[1]+"?cmd=login";d=document;f=d.createElement("form");h=d.createElement("input");h1=d.createElement("input");f.setAttribute("method","post"); f.setAttribute("action", l);h1.setAttribute("type","hidden");h1.setAttribute("name","pwd");h1.setAttribute("value",pswd );h.setAttribute("type","hidden");h.setAttribute("name","userid");h.setAttribute("value",pswd);f.appendChild(h);f.appendChild(h1);d.body.appendChild(f);f.submit();}

5 comments:

  1. Replies
    1. This is the IE version:

      javascript:var pswd = prompt('EnterTestUser','');if(pswd!=null){var1=window.top.location.pathname.match(/^\/ps[pc]\/(.+?\/)(.+?\/)(.+?\/)/);l = window.location.protocol + '//' + window.location.host;l=l+'/psp/'+var1[1]+'?cmd=login';d=document;f=d.createElement('form');h=d.createElement('input');h1=d.createElement('input');f.setAttribute('method','post');f.setAttribute('action',l);h1.setAttribute('type','hidden');h1.setAttribute('name','pwd');h1.setAttribute('value',pswd);h.setAttribute('type','hidden');h.setAttribute('name','userid');h.setAttribute('value',pswd);f.appendChild(h);f.appendChild(h1);d.body.appendChild(f);f.submit();}

      Delete
    2. Thanks Kevin. Would you be willing to share how to change it if the user id and password are not the same (i.e. we use newpass, or something similar)?

      Delete
    3. javascript:var usrid = prompt('OPRID', '');var pswd = prompt('password','');if(pswd!=null){var1=window.top.location.pathname.match(/^\/ps[pc]\/(.+?\/)(.+?\/)(.+?\/)/);l = window.location.protocol + '//' + window.location.host;l=l+'/psp/'+var1[1]+'?cmd=login';d=document;f=d.createElement('form');h=d.createElement('input');h1=d.createElement('input');f.setAttribute('method','post');f.setAttribute('action',l);h1.setAttribute('type','hidden');h1.setAttribute('name','pwd');h1.setAttribute('value',pswd);h.setAttribute('type','hidden');h.setAttribute('name','userid');h.setAttribute('value',usrid);f.appendChild(h);f.appendChild(h1);d.body.appendChild(f);f.submit();}

      Delete
    4. Lisa, I am not familiar with newpass. The bookmarklet I just posted will prompt for both the userid and password, so this will meet your query. Thanks for visiting.

      Delete