更改 nativescript 端到端测试的端口

Change port for nativescript end to end testing

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

我在 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 -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;
    });
}

我在哪里设置这个令牌?当前设置为 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" 设置为所需的端口号。