我有一个本地移动设备实验室(就像Sauce一样)。我使用他们的客户端保留设备,并希望在该实验室中创建的Appium网址上运行代码
我厌倦了使用onPrepare函数进行保留并创建新功能,并将该功能传递给功能对象到WDIO conf文件。当我运行npm脚本时,它仅运行onPrepare函数,但不会创建t Appium est会话(尽管当我在本地托管Appium时,它可以很好地工作)
/**
* WebdriverIO config file to run tests on native mobile apps.
* Config file helps us configure all the settings and setup environments
* to run our tests.
*/
var deviceConf = require('./configRegistry').device;
var BASE_URL = 'HOST URL';
var ReservationCapabilities = require('**/lib/reservation_capabilities').ReservationCapabilities;
var PlexusCredentials = require('**/lib/plexus_credentials').PlexusCredentials;
var PlexusClient = require('**/plexus_client').PlexusClient;
var Reservation = require('**/lib/reservation').Reservation;
var login = require('../../resources/login_credentials');
var reservation, combinedCaps,deviceId;
var webdriverio = require('webdriverio');
const host = '127.0.0.1'; // default appium host
const port = 8080; // default appium port
const waitforTimeout = 60000;
const commandTimeout = 60000;
exports.config = {
debug: false,
specs: [
'resources/features/*.feature'
],
host: BASE_URL,
port: port,
path: '/wd/hub',
maxInstances: 1,
/**
* test configurations
*/
logLevel: 'silent',
coloredLogs: true,
framework: 'cucumber', // cucumber framework specified
cucumberOpts: {
compiler: [],
backtrace: true,
failFast: false,
timeout: 5 * 60 * 60000,
require: ['test/resources/features/*.feature'] // importing/requiring step definition files
},
/**
* hooks help us execute the repeatitive and common utilities
* of the project.
*/
onPrepare: async function () {
console.log('<<< Setting up code for Appium test >>>');
console.log('Trying to make session - - ' + login.userName);
reservation = new Reservation();
var credentials = new PlexusCredentials(login.userName, login.labKey);
var plexusClient = new PlexusClient(credentials);
var reservationCapabilities = new ReservationCapabilities(login.userName + ' reserved device using WDIO', 10);
reservationCapabilities.plexusDeviceType = login.deviceType;
reservation = await plexusClient.reserveDevice(reservationCapabilities);
deviceId = reservation.device.udid.id;
capabilities = [{
'app': deviceConf[0].appPackage,
'appPackage': deviceConf[0].appPackage,
'noReset': true,
'deviceId': deviceId,
'deviceName': deviceId,
'platform': reservation.device.udid.os,
'appActivity': deviceConf[0].appActivity,
'deviceLabAuth': login.userName + ':' + login.labKey + ':' + reservation.device.reservationId,
'newCommandTimeout': deviceConf[0].newCommandTimeout,
'androidPackage': deviceConf[0].appPackage,
'unicodeKeyboard': true,
'udid': deviceId,
'resetKeyboard': false
}];
},
capabilities: combinedCaps,
beforeSession : function(capabilities){
console.log(capabilities +"Before function");
},
afterScenario: function (scenario) {
console.log("afterScenario");
// browser.screenshot();
},
onComplete: async function () {
console.log('<<< TESTING FINISHED >>>');
await reservation.cancel();
}
};
Console log:
<<< NATIVE APP TESTS STARTED >>>
Trying to make session - - receivingtest
reservation created
<<< TESTING FINISHED >>>
我想向WDIO驱动程序发送具有所需功能的正确URL /端口/路径