TestKase
TestKase
|Docs
AutomateMobile

First test in JavaScript

A complete Appium test in Node.js you can copy, run, and watch on a real phone.

One file. Copy it, put your access key in, run it, and watch it happen on a real device.

What you need

Node 18 or newer, and one package:

npm install webdriverio

Nothing of ours to install. This is the ordinary Appium client.

The whole test

This drives our demo app, so there is nothing to upload — farm://app-sample is already on every device.

// first-mobile-test.js
const { remote } = require("webdriverio");
const { randomUUID } = require("crypto");

const ACCESS_KEY = "xyz_your_access_key_here";
const TEST_NAME = "sign in";

(async () => {
  const driver = await remote({
    protocol: "https",
    hostname: "hub.testkase.com",
    port: 443,
    path: "/wd/hub",
    capabilities: {
      platformName: "iOS",
      "appium:deviceName": "iPhone 16",
      "appium:automationName": "XCUITest",
      "appium:app": "farm://app-sample",
      "testkase:options": {
        accessKey: ACCESS_KEY,
        name: TEST_NAME,
        build: "first-test",
        runId: randomUUID(),
        recording: true,
      },
    },
  });

  console.log("session", driver.sessionId);

  try {
    await driver.$("~login-email").setValue("test");
    await driver.$("~login-password").setValue("test");
    await driver.$("~login-submit").click();

    // The tab bar only appears once sign-in succeeded.
    await driver.$("~tab-counter").waitForDisplayed({ timeout: 20000 });

    await driver.executeScript("testkase-status=passed", []);
    console.log("PASS ", TEST_NAME);
  } catch (err) {
    await driver.executeScript("testkase-status=failed", []);
    console.log("FAIL ", TEST_NAME, "->", err.message);
    await driver.deleteSession();
    process.exit(1);
  }

  await driver.deleteSession();
})();

Android instead? Change platformName to "Android" and appium:automationName to "UiAutomator2". The ~name selectors stay the same — our demo app uses the same accessibility ids on both platforms.

What each part does

Six things carry the whole file. Read down the middle column and you have its shape.

The partWhat it does
1https://x:[email protected]/wd/hubWhere your key goes. The same address serves desktop browsers and phones — the capabilities decide which you get.
2platformName: "iOS"Picks the platform. That is all you must send; leave the model and OS version out and you get whichever matching device is free.
3appium:appWhat to open. farm://app-sample is our demo app — nothing to upload, and it serves the right build for iOS, Android, real or virtual. Swap in your own id once you have uploaded a build.
4recording: trueSays what to keep. name is how you will recognise the session in a list; recording is the video, and you get none unless you ask. Every option.
5driver.$("~login-email")Ordinary Appium from here on. Every command behaves exactly as it does against a phone on your desk — we only carry it to the device and back.
6testkase-status=passedHow we tell a pass from a crash. Without it the session shows no result. The failed one belongs in the catch, because a test that blows up skips every line after the blow-up.

Run it

node first-mobile-test.js

The console prints a session id, then PASS. Open your dashboard while it runs and you can watch the device live; when it ends, the video is on the session.