Running selenium as a different user using c# Impersonation

3,770 views
Skip to first unread message

vinay pakyala

unread,
Oct 4, 2013, 6:21:32 AM10/4/13
to seleniu...@googlegroups.com
Hi All,
 
I am automating a web application which uses "windows intergrated authentication". So access the URL, based on the windows logged on user, the home page is displayed. There is no login page concept.
 
Now as with any web application, we have different user roles.
User  A
User  B
 
I need selenium script to run few tests with  User A & few with User B ( not with the user logged on to the server)
 
I am using Selenium C# Web Driver dlls & IE Driver(2.35version & 64-bit)
 
What I have done so far
==================
a) I have created Impersonator.cs file which uses C# Impersonation. Thanks to the following link
 
b) In the selenium script, I use the above class & set the logon to "User A" & then launch IE browser
 
 >> Private Impersonate _imp;
 >> _imp = new Impersonate("username","domain","pwd");
>> IwebDriver driver = new InternetExplorerDriver(); // Please assume I set the IEDriver.exe to the correct path
 
I get the following error
"Unexpected error launching Internet Explorer. Could not get document from window handle(NoSuchDriver)
 
Note: The same code works when I impersonate with the windows logged in user.
 
Appreciate if anyone would have a look at this

Vitali Samusik

unread,
Oct 17, 2013, 8:35:49 AM10/17/13
to seleniu...@googlegroups.com
Hi.

I'm experiencing just the same problem.

So far I can say, that there are some ways to run tests without user logged in, but not using IE.
For example - here is the link:
http://sqa.stackexchange.com/questions/2609/running-webdriver-without-opening-actual-browser-window

http://stackoverflow.com/questions/1418082/is-it-possible-to-hide-the-browser-in-selenium-rc
etc..

Vitali Samusik

unread,
Oct 17, 2013, 12:07:17 PM10/17/13
to seleniu...@googlegroups.com
Hi.

Just for your consideration

I've recently rewrote my scenario to use Firefox.
tried launching it with PsExec.exe (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) with -s option.
My command looked like PsExec.exe -s \\localhost <Path to my .exe which runs test>

It worked just fine.

As for the IE - as far as I've googled - it looks like IEDriverServer.exe still has some bugs..
Running with PsExec IE scenario - I received a mistake, that couldn't find an element by id, though the element existed. It's a different problem, cause the major idea worked (IE started up and started running the scenario without a user logged in.)

Pankaj Sukale

unread,
Jul 17, 2014, 2:40:40 AM7/17/14
to seleniu...@googlegroups.com
Hi,

Any one knows how we can do this in JAVA?

Regards,
Pankaj

Meghasri Kodaganti

unread,
Dec 14, 2015, 7:50:56 AM12/14/15
to Selenium Users
Hello,

Can anyone help me out the scripting in JAVA for ''Run as Different'' in Selenium. This would be a great thing for me. Thanks in advance.

Hi Pankaj,

Do you got the solution for your query?

Regards,
Megha

David

unread,
Dec 15, 2015, 1:03:15 AM12/15/15
to Selenium Users
Perhaps a straightforward solution is to deal with actual Windows logins and Selenium tests. Maybe using something like these might work:



The trick would be to use remote desktop to log in as the desired user and keep the session/desktop active (using the methods above), then run the matching Selenium test for the specific logged in user.

You can call remote desktop from the command line, so doing that with Selenium test code (in setup precondition step & logout/disconnect for teardown post condition) would allow for fully automated test solution - you don't have to manually open & close remote desktop session.

I haven't tried/tested this myself though. And you can only do this for one logged in user at a time (although multiple users can be logged in, but only one is active at a time).
Reply all
Reply to author
Forward
0 new messages