mirror of
https://github.com/appium/appium.git
synced 2026-11-15 15:17:58 +08:00
Allow to connect an Appium node to Selenium Grid 3
This commit is contained in:
committed by
Isaac Murchie
parent
e5ca5b55fc
commit
657a83bdcb
+22
-13
@@ -26,7 +26,7 @@ async function registerToGrid (options_post, jsonObject) {
|
||||
if (response === undefined || response.statusCode !== 200) {
|
||||
throw new Error('Request failed');
|
||||
}
|
||||
let logMessage = `Appium successfully registered with the grid on ${jsonObject.configuration.hubHost}:${jsonObject.configuration.hubPort}`;
|
||||
let logMessage = `Appium successfully registered with the grid on ${jsonObject.hubHost}:${jsonObject.hubPort}`;
|
||||
logger.debug(logMessage);
|
||||
} catch (err) {
|
||||
logger.error(`Request to register with grid was unsuccessful: ${err.message}`);
|
||||
@@ -42,19 +42,28 @@ async function postRequest (data, addr, port) {
|
||||
logger.errorAndThrow(`Syntax error in node configuration file: ${err.message}`);
|
||||
}
|
||||
|
||||
// backward compatibility with Selenium 2 config files
|
||||
if (jsonObject.hasOwnProperty('configuration')) {
|
||||
for (var property in jsonObject.configuration) {
|
||||
if (jsonObject.configuration.hasOwnProperty(property)) {
|
||||
jsonObject[property] = jsonObject.configuration[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the node config does not have the appium/webdriver url, host, and port,
|
||||
// automatically add it based on how appium was initialized
|
||||
// otherwise, we will take whatever the user setup
|
||||
// because we will always set localhost/127.0.0.1. this won't work if your
|
||||
// node and grid aren't in the same place
|
||||
if (!jsonObject.configuration.url || !jsonObject.configuration.host || !jsonObject.configuration.port) {
|
||||
jsonObject.configuration.url = `http://${addr}:${port}/wd/hub`;
|
||||
jsonObject.configuration.host = addr;
|
||||
jsonObject.configuration.port = port;
|
||||
if (!jsonObject.url || !jsonObject.host || !jsonObject.port) {
|
||||
jsonObject.url = `http://${addr}:${port}/wd/hub`;
|
||||
jsonObject.host = addr;
|
||||
jsonObject.port = port;
|
||||
}
|
||||
// if the node config does not have id automatically add it
|
||||
if (!jsonObject.configuration.id) {
|
||||
jsonObject.configuration.id = `http://${jsonObject.configuration.host}:${jsonObject.configuration.port}`;
|
||||
if (!jsonObject.id) {
|
||||
jsonObject.id = `http://${jsonObject.host}:${jsonObject.port}`;
|
||||
}
|
||||
|
||||
// re-serialize the configuration with the auto populated data
|
||||
@@ -67,19 +76,19 @@ async function postRequest (data, addr, port) {
|
||||
};
|
||||
// the post options
|
||||
let post_options = {
|
||||
url: `http://${jsonObject.configuration.hubHost}:${jsonObject.configuration.hubPort}/grid/register`,
|
||||
url: `http://${jsonObject.hubHost}:${jsonObject.hubPort}/grid/register`,
|
||||
method: 'POST',
|
||||
body: data,
|
||||
headers: post_headers,
|
||||
resolveWithFullResponse: true // return the full response, not just the body
|
||||
};
|
||||
|
||||
if (jsonObject.configuration.register !== true) {
|
||||
logger.debug(`No registration sent (${jsonObject.configuration.register} = false)`);
|
||||
if (jsonObject.register !== true) {
|
||||
logger.debug(`No registration sent (${jsonObject.register} = false)`);
|
||||
return;
|
||||
}
|
||||
|
||||
let registerCycleTime = jsonObject.configuration.registerCycle;
|
||||
let registerCycleTime = jsonObject.registerCycle;
|
||||
if (registerCycleTime !== null && registerCycleTime > 0) {
|
||||
// initiate a new Thread
|
||||
let first = true;
|
||||
@@ -101,10 +110,10 @@ async function postRequest (data, addr, port) {
|
||||
|
||||
async function isAlreadyRegistered (jsonObject) {
|
||||
//check if node is already registered
|
||||
let id = jsonObject.configuration.id;
|
||||
let id = jsonObject.id;
|
||||
try {
|
||||
let response = await request({
|
||||
uri: `http://${jsonObject.configuration.hubHost}:${jsonObject.configuration.hubPort}/grid/api/proxy?id=${id}`,
|
||||
uri: `http://${jsonObject.hubHost}:${jsonObject.hubPort}/grid/api/proxy?id=${id}`,
|
||||
method : 'GET',
|
||||
timeout : 10000,
|
||||
resolveWithFullResponse: true // return the full response, not just the body
|
||||
|
||||
Reference in New Issue
Block a user