gpt4 book ai didi

android - 更改本地脚本端到端测试的端口

转载 作者:行者123 更新时间:2023-12-02 13:37:43 26 4
gpt4 key购买 nike

我将 NativeScript 6.1.2 与 Appium 结合使用,通过 Android 模拟器运行端到端测试。我需要在与默认端口(5546)不同的端口上运行 appium 测试,因为它与同一台计算机上尝试进行相同测试的另一个用户发生冲突。

我已在 appium.capability.json 文件中设置了具有以下功能的 Android 虚拟设备;

"samsung": {
"platformName": "Android",
"platformVersion": "7.0",
"deviceName": "samsung_galaxy_s8",
"avd": "samsung_galaxy_s8",
"lt": 60000,
"newCommandTimeout": 720,
"noReset": false,
"fullReset": false,
"app": ""
}

当我开始测试时;

npm run e2e -- --runType samsung

我得到以下信息;

Executing "/bin/ps aux | grep -ie 'sdk/emulator/qemu' | grep -ie 'samsung_galaxy_s8' | grep -v grep  | xargs kill -9"
No matching processes to kill!
Starting emulator with options: -avd samsung_galaxy_s8 -port 5546 ["-no-audio","-no-boot-anim","-wipe-data","-no-snapshot-load","-no-snapshot-save"]
Booting emulator ...
Check if "emulator-5546" is running.
Check has "passed".
Check if emulator is responding
Emulator is booted!
Started device: {"name":"samsung_galaxy_s8","apiLevel":"24","releaseVersion":"7.0","platform":"android","type":"emulator","status":"booted","token":"5546","pid":26944,"startedAt":1572236203683,"config":{"density":1.6,"offsetPixels":25}}

注意:“-avd samsung_galaxy_s8 -port 5546”行是我想要更改的内容。

更新

我发现 appium 启动进程的位置以及端口是通过使用模拟器对象上的属性“token”来设置的。

它位于/node_modules/mobile-devices-controller/lib/android-controller.js 文件中;

static startEmulatorProcess(emulator, logPath, options) {
return __awaiter(this, void 0, void 0, function* () {
options = options || ["-no-audio", "-no-snapshot-save", "-no-boot-anim"];
if (logPath) {
options.push(` > ${logPath} 2 >& 1`);
}
utils_1.logInfo(`Starting emulator with options: -avd ${emulator.name} -port ${emulator.token}`, options);
const process = child_process_1.spawn(AndroidController.EMULATOR, [" -avd ", emulator.name, " -port ", emulator.token, ...options], {
shell: true,
detached: false,
});
process.stdout.on("data", (data) => {
console.log(data.toString());
});
process.stdout.on("error", (data) => {
console.log(data.toString());
});
emulator.pid = process.pid;
emulator.process = process;
return emulator;
});
}

我在哪里设置这个 token ?当前设置为 5546。

更新:我根据 WiRa 的答案使用的完整命令

启动模拟器

${ANDROID_HOME}emulator/emulator -avd samsung_galaxy_s8 -gpu guest -no-audio -verbose -port 3500

开始端到端测试

DEVICE_TOKEN=3500 npm run e2e -- --runType device.samsung

注意:由于模拟器经常崩溃,我还使用了循环

while true; do pkill -f android; sleep 2; tnsa &; em &> ~/emulator.log; done

最佳答案

您可以将环境变量“DEVICE_TOKEN”设置为所需的端口号。

关于android - 更改本地脚本端到端测试的端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58585745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com