2

Long explanation coming but the more I provide hopefully the better the chance someone has done something similar.

I'm currently working on a test solution to test a web app (Visual Studio, C#, Seleno, MSTest)that uses windows credentials to log into the application. These credentials can either be stored in the windows vault and internet options can be set to automatic login or by entering them into an alert box. Most tests use different users as they have different permissions within the application.

The alert box isnt a standard javascript alert but a windows prompt skinned by the browser. I've been dealing with this from my automation solution by pushing credentials into the windows vault and configuring internet options for automatic login using current username and password but I've recently been implementing Selenium Grid for parallel test running as part of a CI pipeline instead of our Distributed approach with Microsoft Test Manager

Sounds easy enough but turns out it isn't

Previously with MTM the dlls were distributed to each Test Agent and managed by a test controller. We have a class that pushes credentials into the windows vault so that worked for each machine. With Grid these are pushed into the master machines vault and not the nodes. I had planned on using PowerShell to add credentials on the nodes as this needs to happen before the browser instance is created but selenium grid doesn’t tell the user which nodes it’s executing tests on.

I tried using selenium to interact with the alert but when navigating to the app the page constantly loads until credentials are entered so the selenium GoToUrl() method gets caught in a loop. If you stop the method using a timeout the alert disappears. (Can recreate manually by pressing the X button in browser to stop page loading)

I changed approach and using the SessionID of the RemoteWebDriver I sent a rest request to the selenium hub to get the Host name of all the machines that are executing tests. Now that I have the nodes I can use remote PowerShell to update the credential store. As i said at the start most tests use different users so I also need grid to tell me which test is executing on the hosts too but I can't find a way to get the grid hub to tell me what tests it's running programatically

so in short I wanted to:

Get Nodes for current test session from Selenium grid

Get Test name running on each node

Once I have both of these I can send appropriate user details via remote PowerShell

If anyone has done anything similar or has any advice it would be much appreciated.

Thanks

G

Grimzy
  • 23
  • 7
  • Is there some reason you can't just push *all* the credentials into the Windows vault on every VM? Once that's done, you shouldn't ever need to worry about them again unless you add or update accounts. – JeffC Oct 05 '17 at 23:02
  • That was my first thought too. You can only have one credential for a specific server in the vault. So if you try to add 2 the first will be added then overridden by the second one – Grimzy Oct 06 '17 at 08:10
  • Have you tried creating the credentials programmatically using C# from inside say @BeforeTest (instead of remotely pushing them using PowerShell)? See [this](https://stackoverflow.com/a/32550674/2386774) – JeffC Oct 06 '17 at 14:00
  • I tried this too but the code still executed on master instead of node. Came up with a way of doing it USING a REST request, a context manager and remote Powershell – Grimzy Oct 07 '17 at 16:02

1 Answers1

0

Get Nodes for current test session from Selenium grid

For you to find out the node to which your test was routed to, you can do the following :

  • Retrieve the current session id after a new RemoteWebDriver instance has been created using driver.getSessionId() (This is how I do it in Java)
  • Once you have the session id, you can post to the end-point http://localhost:4444/grid/api/testsession?session=<SessionIdGoesHere> and extract the remote host and port number of the node from the response payload.

You can read more about this in my blog post here

Get Test name running on each node

I am not sure what you are referring to as Test name here. There is no notion of test names in the Selenium Grid world. It all boils down to just a session id, which indicates/represents a test that is running.

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
  • When I said test name I meant to say tests method name. I came up with a solution yesterday the same way you had done. Used session ID to get node once I had node I used a test context manager I had created to identify which test was executing and what credentials were needed. I then passed this to the node via Powershell which added the credentials and cleared the browser cache to prevent needing to create a new instance to recognise the credentials having been added and refreshed the browser which logged in – Grimzy Oct 07 '17 at 15:55