user4779384
user4779384

Reputation:

Selenium Grid and RemoteWebDriver

I have an application written in Java that creates an email account on a specific website. For certain reasons, I need to run each iteration of the program under a different windows user account.

I'm using Selenium Grid (RemoteWebDriver) to connect to a remote server (Grid) from a hub server.

Assuming I have multiple windows user accounts set up on a remote windows server (such as "account639", "account729", "account889" etc) and I want my hub to connect to each account separately and execute Java code

My question is: How do I specify which windows user account the code should be executed on in the Grid server?

As far as I can tell, the two parameters I can add to RemoteWebDriver is the hostname (or IP) of the remote server and the port. I don't see any option to specify which windows user account it should run under.

Since the hostname (IP) is the same for all windows user accounts under the remote server how would I tell the "hub" to execute the section of code under a different windows user account each time?

The only possibility I see is to run each instance of Selenium Grid under a different port and use the port number as a way to differentiate between two windows user accounts (and make sure I'm logged into both user accounts at the same time).

For example, I could setup Selenium Grid on "account639" to listen on port 6399 for example and "account729" to listen on port "7299" for example - this way I know the code is being executed under the appropriate windows account.

Is this feasible? And is there a more direct way of doing this without using ports (i.e, is it possible to specify which windows user account the hub should connect to just like I specify the ports?)

Upvotes: 1

Views: 2219

Answers (2)

peetya
peetya

Reputation: 3628

Log in with every windows user and run a selenium node under every account on different ports (for example: 5555, 5556, 5557). If every node has the same setup, I mean the same browser, same browser versions, etc... you can use "applicationName", which is a supported but not documented extra capability. With this capability, you can distinguish your nodes. For example in your nodeConfig:

...
{
    "applicationName":"account639",
    "platform":"WINDOWS",
    "browserName":"chrome",
    "maxInstances":5,
    "version":"40",
    "seleniumProtocol":"WebDriver"
},
...

After that you can set up your RemoteWebDriver to run your tests on a specific node which belongs to a specific widows user account. For example:

DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("applicationName", "account639");
...
WebDriver driver = new RemoteWebDriver(new URL(this.getHubUrl()), dc);

If you want to use more extra capability, you can create your own custom Capability Matcher (search for it in Google: "selenium grid custom capability matcher"), but if you need only one extra capability, I recommend to use the mentioned one.

Hope this helps.

Upvotes: 1

Michiel Bugher
Michiel Bugher

Reputation: 1065

This is not technically possible with Selenium Grid. However, you could create a windows service that wraps selenium grid.

Once you have installed the windows service, you can select who you want the service to run as.

Here's an article on how to run a windows service as an account: https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sys_srv_logon_user.mspx?mfr=true

I guess you could accomplish what you want by installing multiple windows services on separate ports, as different users.

Upvotes: 0

Related Questions