0

I'm using protractor for some of my end to end tests. We want to perform a set of actions based on which selenium node we are running on so that we avoid having some tests interfere with each other if they are running at the same time. How would I be able to get the selenium node which my selenium hub assigns for my test to run?

With the possible solution of the duplicate question i tried the following to see what testsession api would give me

browser.getSession().then(function (session) {
    var hub = "http://localhost:4444"; //IP or hostname of GRID

    var url = hub + "/grid/api/testsession?session=" + session.getId();
    console.log(url);
});

and then while my test is running I would then hit the url manually from the browser which got printed out

http://localhost:4444/grid/api/testsession?session=17e14d0e-38da-4269-b23c-3b2d52569383

however the response I get back is

{"success":false,"msg":"Cannot find test slot running session 8ca57382-d7d8-44ae-b3bc-8c1223c86805 in the registry."}

Should I be getting the session a different way now?

user3626708
  • 727
  • 2
  • 8
  • 24
  • I didn't down vote your question but it is a duplicate of [this](http://stackoverflow.com/questions/6898735/selenium-2-grid-knowing-which-node-your-test-is-using). Google **selenium grid get node id** – MikeJRamsey56 Apr 14 '16 at 14:32
  • @MikeJRamsey56 for some reason this didn't work. Will update my question with what I did so far – user3626708 Apr 22 '16 at 04:18
  • Did you look at the 2nd answer? – MikeJRamsey56 Apr 22 '16 at 15:21
  • Yes that is how I got the code I did so far. It seems the session being returned isn't any of node's session because when I do http://localhost:4444/wd/hub/static/resource/hub.html I see the session there which is '08de5d7d-980d-472c-89e5-d06ef6d158a5' – user3626708 Apr 22 '16 at 15:47
  • var runOptions = new RemoteRunnerOptions(); var sessionId = runOptions.getSessionId(); I am looking [here](https://github.com/SeleniumHQ/selenium/blob/master/javascript/selenium-core/scripts/selenium-remoterunner.js) – MikeJRamsey56 Apr 22 '16 at 17:27
  • This might be a dumb question but how would I get access to that from protractor? I don't see it in the protractor api https://angular.github.io/protractor/#/api. Can I do a 'require' to get it? Javascript isn't really my strong language. – user3626708 Apr 23 '16 at 19:40
  • Actually got this working now. Posting my code above – user3626708 Apr 26 '16 at 18:02

1 Answers1

2

So positing my code snippet to help others find the solution as well

browser.driver.getCapabilities().then(function (capabilities) {
        var hub = "http://localhost:4444"; //IP or hostname of GRID

        var url = hub + "/grid/api/testsession?session=" + capabilities.caps_['webdriver.remote.sessionid'];

        var res = request('GET', url);
        var testSession = JSON.parse(res.getBody().toString());
        var URL = new urlParse(testSession.proxyId);
        console.log(URL.host);
    });
user3626708
  • 727
  • 2
  • 8
  • 24