Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How can I check how many nodes are registered to my Jenkins Selenium Hub? #129

Open
alinpa opened this issue Jun 13, 2018 · 1 comment

Comments

@alinpa
Copy link

alinpa commented Jun 13, 2018

Hello Guys and Girls,

Do you have any idea how can I verify programmatically how many nodes are registered to my selenium hub?

How can I have access to the jenkins selenium plugin instance?

Thank you!

@alinpa alinpa changed the title How can I check how many nodes are registered to my Jenkins Selenium Hub? [Question] How can I check how many nodes are registered to my Jenkins Selenium Hub? Jun 13, 2018
@alinpa
Copy link
Author

alinpa commented Aug 20, 2018

Hello,

If someone are interested to know how you can do it, please check the following method:

import groovy.json.JsonSlurper
def waitSeleniumNodes(int expectedNumberOfSeleniumNodes) {
int count = 600
def seleniumGridInfo = ["curl", "-k", "-X", "GET", "-H", "Content-Type: application/json", "http://your-jenkins-link:4444/grid/api/hub"].execute().text
int actualNumberOfSeleniumNodes = 0

while(!(actualNumberOfSeleniumNodes == expectedNumberOfSeleniumNodes) && (count >=0)) {
	sleep(2)
	def seleniumGridInfoJson = new JsonSlurper().parseText(["curl", "-k", "-X", "GET", "-H", "Content-Type: application/json", "http://your-jenkins-link:4444/grid/api/hub"].execute().text)
	actualNumberOfSeleniumNodes = (seleniumGridInfoJson.slotCounts.total as Integer)/5
	println('Selenium nodes already registered are ' + actualNumberOfSeleniumNodes + ' and should be '+ expectedNumberOfSeleniumNodes)
            println('Remaining ' + count*2 + ' seconds!')
            count--
}

 if (count == -1) {
            println('Not all selenium nodes are registered to master! Number of selenium nodes registered are ' + actualNumberOfSeleniumNodes +'and should be ' + expectedNumberOfSeleniumNodes)
            currentBuild.result = 'FAILURE'
    }

}

The previous method checks for a while if a number of nodes are registered to the selenium grid.
The previous method was written on groovy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant