Search code examples
seleniumselenium-webdriverprotractorselenium-gridselenium-grid2

How to run test on specific browser by selenium grid


I have register two platform with chrome browser on windows 7 and windows 10 into selenium grid server.

I want to run a test at Chrome browser on Windows 10 but when i run the test, the test randomly run on Windows 7 and randomly run on Windows 10 on chrome.

Do you have an idea how to do the configuration to run the test on specific browser and platform when we have registered multiple platform?

hub:

java -jar selenium-server-standalone-3.7.1.jar -role hub

register node on windows 7:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444

register node on windows 10:

java -Dwebdriver.chrome.driver=chromedriver_2.33.exe -jar selenium-server-standalone-3.7.1.jar -role node -hub http://localhost:4444

protractor.conf.js

exports.config = {

    specs: [
        '**/*.mytest.e2e-spec.ts'
    ],
    multiCapabilities: [
        {
            browserName: 'chrome',
            platform: 'WIN10',
        }
    ],
    seleniumAddress: 'http://localhost:4444/wd/hub',
    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        print: function () {
        }
    },
    onPrepare: function () {
        require('ts-node').register({
            project: 'e2e/tsconfig.e2e.json'
        });
    }
};

Solution

  • I would suggest that you do the following

    • Create a node configuration file as seen here, wherein for the WINDOWS7 node, you specify the appropriate platform (make sure you pick a value from here)
    • Now you start off the node by specifying this newly created nodeConfig json using the command line parameter -nodeConfig node.json ( For more details refer to my blog post here )

    Now based on the PLATFORM capabilities specified by your test, it would be routed to the appropriate node.