更改本机端对端测试的端口

问题描述 投票:0回答:1

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

我在appium.capabilities.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-端口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;
    });
}

我在哪里设置此令牌?当前设置为5546。

更新:我按照WiRa的答案使用的完整命令

启动模拟器

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

开始e2e测试

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

注意:由于模拟器不断崩溃,我也使用了循环

while true; do pkill -f android; sleep 2; tnsa &; em &> ~/emulator.log; done
android appium nativescript emulation e2e-testing
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.