Run the sample native app JS test

Step 1: Setup environment

Requirements

  • Npm tool
  • WebdriverIO framework
  • Access key
    • You can generate an Access key using the following instruction – Access key
  • Billing unit
    • The billing unit is your team’s unique identifier, or just the word “personal” in the case of an individual account.
      More information can be found here.

Step 2: Upload and install an App

Before running tests, several preparations are required:

  • Upload the app (only once).
  • Find and take a Device
  • Install the App

All of these actions can be performed automatically via API.
For more details, please refer to the Upload and Install document.

Step 3: Prepare the test configuration

After setup up the environment, you need to prepare the test configuration

const KEY = 'mobitru_ak_...';
const BILLING_UNIT = '<TEAM_CODE>';

const credentials = `${BILLING_UNIT}:${KEY}`;
const encodedCredentials = Buffer.from(credentials).toString('base64');

exports.config = {
    runner: 'local',
    protocol: 'https',
    hostname: `@app.mobitru.com`,
    headers: {
        Authorization: `Basic ${encodedCredentials}`
    },
    path: '/wd/hub',
    logLevel: 'debug',
    port: 443,
    specs: ['./test/specs/**/native-appium-demo-android.js'], // Path to your test file.
    maxInstances: 1,
    capabilities: [{
        platformName: 'Android',
        'appium:automationName': 'UIAutomator2',
        'appium:udid': '38210DLJH0023E',
        'appium:appPackage': 'com.epam.mobitru',
        'appium:appActivity': '.MainActivity',
        'appium:noReset': true,
    }],
    bail: 0,
    waitForTimeout: 10000, // Default timeout for wait commands
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    framework: 'mocha',
    reporters: ['allure'],
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    }
};
const KEY = 'mobitru_ak....';
const BILLING_UNIT = '<TEAM_CODE>';

const credentials = `${BILLING_UNIT}:${KEY}`;
const encodedCredentials = Buffer.from(credentials).toString('base64');

exports.config = {
    runner: 'local',
    protocol: 'https',
    hostname: `@app.mobitru.com`,
    headers: {
        Authorization: `Basic ${encodedCredentials}`
    },
    path: '/wd/hub',
    logLevel: 'debug',
    port: 443,
    specs: ['./test/specs/**/native-appium-demo-ios.js'], // Path to your test file.
    maxInstances: 1,
    capabilities: [{
        platformName: 'iOS',
        'appium:automationName': 'XCUITest',
        'appium:udid': '00008101-001608482602001E',
        'appium:bundleId': 'com.epam.mobitru.demoapp'
    }],
    bail: 0,
    waitForTimeout: 10000, // Default timeout for wait commands
    connectionRetryTimeout: 120000,
    connectionRetryCount: 3,
    framework: 'mocha',
    reporters: ['allure'],
    mochaOpts: {
        ui: 'bdd',
        timeout: 60000
    }
};

Step 4: Run sample test

After setup up the environment, installing the App, and preparing the config, you can run your first test

const assert = require('assert');

describe('Appium Login Demo Test', () => {
    const USER_NAME = 'testuser@mobitru.com';
    const PASSWORD = 'password1';
    const DEFAULT_WAIT_TIMEOUT_MS = 10000;

    it('should login to the Mobitru app and verify categories are loaded', async () => {
        // Locate the email input field and enter the email
        const emailInput = await $('//*[@resource-id="com.epam.mobitru:id/login_email"]//android.widget.EditText');
        await emailInput.setValue(USER_NAME);

        // Locate the password input field and enter the password
        const passwordInput = await $('//*[@resource-id="com.epam.mobitru:id/login_password"]//android.widget.EditText');
        await passwordInput.setValue(PASSWORD);

        // Locate and click the Sign In button
        const signInButton = await $('//*[@resource-id="com.epam.mobitru:id/login_signin"]');
        await signInButton.click();

        // Wait for the resource category to appear
        const categoryElement = await $('//*[@resource-id="com.epam.mobitru:id/category"]');
        await categoryElement.waitForDisplayed({timeout: DEFAULT_WAIT_TIMEOUT_MS});
    });
});
const assert = require('assert');

describe('Appium Login Demo Test', () => {
    const USER_NAME = 'testuser@mobitru.com';
    const PASSWORD = 'password1';
    const DEFAULT_WAIT_TIMEOUT_MS = 10000;

    it('should login to the Mobitru app and verify categories are loaded', async () => {
        // Locate the email input field and enter the email
        const emailInput = await $('//XCUIElementTypeTextField[starts-with(@name,"Login")]');
        await emailInput.setValue(USER_NAME);

        // Locate the password input field and enter the password
        const passwordInput = await $('//XCUIElementTypeSecureTextField[starts-with(@name,"Password")]');
        await passwordInput.setValue(PASSWORD);

        // Locate and click the Sign In button
        const signInButton = await $('//XCUIElementTypeButton[starts-with(@name,"Sign in")]');
        await signInButton.click();

        // Wait for the resource category to appear
        const productHeader = await $('//*[starts-with(@name,"productHeaderViewLabel")]');
        await productHeader.waitForDisplayed({ timeout: DEFAULT_WAIT_TIMEOUT_MS });
    });
});

Scroll to Top