我正在使用Protractor进行并行测试。问题是我有3个用户,我希望Protractor为每个实例自动选择一个免费用户。
let usersInActions = {};
const users = [
{ username: 'aaa', password: 'aaa'},
{ username: 'bbb', password: 'bbb'},
{ username: 'ccc', password: 'ccc'}
];
let config = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ['incognito', 'disable-extensions']
},
maxInstances: 3,
shardTestFiles: true
},
beforeLaunch: async () => {
const capabilities = await browser.getCapabilities();
const sesssionId = capabilities.get('webdriver.remote.sessionid');
if (!browser.params.usersInActions) {
browser.params.usersInActions = {};
}
const freeUser = users.find(u => {
return !browser.params.usersInActions[sesssionId];
});
usersInActions[sesssionId] = freeUser;
browser.params.user = freeUser;
},
afterLaunch: async () => {
const capabilities = await browser.getCapabilities();
const sesssionId = capabilities.get('webdriver.remote.sessionid');
browser.params.usersInActions[sesssionId] = null;
}
};