如何使用wdio.conf.js中的WebdriverIO启动两个Appium服务器以使用Selenium Grid

时间:2019-04-28 12:47:43

标签: appium webdriver-io

这是我的Wdio.conf.js文件,无法在两个不同的端口中启动两个appium服务器。

var appiumCmd = /^win32/.test(process.platform) ? 'appium.cmd' : 'appium';
var sleep = require('sleep').sleep;
var netstat = require('node-netstat');
var homeFeatureCommand = require("./test/apiServices/commands/getHomeFeatureStatusCommand");
var promptForTeacherAttendanceFeatureToggle = require('./test/apiServices/commands/togglePromptForTeacherAttendanceCommand');
var devConfig = require("./test/data/devConfig");
var testType = process.env.TEST_TYPE || devConfig.user.testType;
var amAppPath = process.env.APP_PATH || './app-nigeria-uat-release.apk';
var ttAppPath = process.env.TT_APP_PATH || './app-teachertech-uat-release.apk';
var deviceUDID = process.env.DEVICE_ID || devConfig.user.deviceID;
var appiumPort1 = process.env.APPIUM_PORT || devConfig.user.port1;
var appiumPort2 = process.env.APPIUM_PORT || devConfig.user.port2;
var downloadApkAM = require('./test/utils/downloadApkAM');
var downloadApkTT = require('./test/utils/downloadApkTT');
var soapServices = require('./test/apiServices/soapServices/AcademyManagerConfigurationRequest');
var giftCode = require('./test/apiServices/commands/getGiftCode');
var toggleGiftCodeCommand = require('./test/apiServices/commands/toggleEnableGiftcodeCommand');


console.log('App Path is set to :: ' + amAppPath);
console.log('App Path is set to :: ' + ttAppPath);
exports.config = {

  specs: [
    './test/specs/**/*.js'
  ],
  // Patterns to exclude.
  exclude: [

  ],
  suites: {
    login: [
      './test/specs/01-login.spec.js',
      './test/specs/02-login.manual.spec.js'
    ],
    admit: [
      './test/specs/01-login.spec.js',
      './test/specs/05-admit.pupil.spec.js',
    ],
  },

  maxInstances: 2,
capabilities:
  // https://docs.saucelabs.com/reference/platforms-configurator
  //
  capabilities: {
    AcademyManager: {
      port:appiumPort1,
      desiredCapabilities: {
        'browserName': '',
        'appiumVersion': '1.7.2',
        'udid': deviceUDID,
        'deviceName': 'HUAWAI Y330-U01',
        'deviceOrientation': 'portrait',
        'platformName': 'android',
        'maxInstances': 1,
        'platformVersion': '4.2.2',
        'app': amAppPath,
        'waitforTimeout': 600000,
        'commandTimeout': 600000,
        'androidDeviceReadyTimeout': 60,
        'readyTimeout': 120000,
        'launchTimeout': 120000,
        'appPackage': 'com.bia.bridgedroid.am',
        'appActivity': 'com.bridge.academymanager.activity.LandingActivity',
        'noReset': true
      }
    },

    TeacherTech: {
      port:appiumPort2,
      desiredCapabilities: {
        'browserName': '',
        'appiumVersion': '1.7.2',
        'udid': '380129d13562c200',
        'deviceName': 'SM-T231',
        'deviceOrientation': 'portrait',
        'platformName': 'android',
        'maxInstances': 1,
        'platformVersion': '4.4.2',
        'app': ttAppPath,
        'waitforTimeout': 600000,
        'commandTimeout': 600000,
        'androidDeviceReadyTimeout': 60,
        'readyTimeout': 120000,
        'launchTimeout': 120000,
        'appPackage': 'com.bia.bridgedroid.tt',
        'appActivity': 'com.bia.tt.activities.HomeActivity',
        'noReset': true
      }

    }
  },
  waitforTimeout: 100000,
  connectionRetryTimeout: 900000,
  connectionRetryCount: 3,
  services: ['appium'],
  appium: {
    waitStartTime: 60000,
    command: appiumCmd,
    logFileName: 'appium163.log',
    args: {
      //address: '127.0.0.1',
      //port: appiumPort1,
      platformName: 'android',
      commandTimeout: '60000',
      sessionOverride: true,
      debugLogSpacing: true
    }
  },

  reporters: ['spec', 'allure', 'junit'],
  reporterOptions: {
    allure: {
      outputDir: 'allure-results'
    },
    junit: {
      outputDir: 'junit'
    }
  },


  mochaOpts: {
    ui: 'bdd',
    timeout: 9999999
  },

  onPrepare: function(config, capabilities) {
    downloadApkAM.downloadApkAM(amAppPath);
    downloadApkTT.downloadApkTT(ttAppPath);
  },

  beforeSession: function(config, capabilities, specs) {
    sleep(40);
    global.app_path = capabilities.app;
    global.expect = require('chai').expect;
    global.appPackage = capabilities.appPackage;
    global.deviceId = deviceUDID.toString();
    global.isDashboardV1Enabled = null;
    homeFeatureCommand.getDashboardFeatures().then(function(res) {
    });
    global.unUsedGiftCode = null;
    promptForTeacherAttendanceFeatureToggle.togglePromptForTeacherAttendanceForDevice(deviceId, true).then(function(res) {
      console.log(res);
    });
    toggleGiftCodeCommand.isGiftCodeFeaturesEnable().then(function(res) {
      console.log("The Global Gift Code screen value is " + isGiftCodeScreenIsEnabled);
      if (isGiftCodeScreenIsEnabled == true && testType === "functionalTest") {
        giftCode.getNewGiftCode().then(function(res) {
        });
      }
    });
    netstat({
      watch: true,
      limit: 1,
      filter: {
        protocol: 'tcp',
        local: { port: appiumPort1 },
        state: 'LISTENING'
      },

      done: function(err) {
        console.log('done');
      }
    }, function(line) {
      console.log(line);
      return false; 
    });
  },
};

我已经在功能中声明了端口号。但是唯一的一个端口正在启动。对于第二个端口,我收到错误ERROR:连接ECONNREFUSED 127.0.0.1:4727。请建议如何使用两个端口号启动两个appium服务器。

0 个答案:

没有答案