Search code examples
javascriptmocha.jsappiumwebdriver-io

Webdriverio and Appium, can't attach inspector and troubles with sessions


I'm new with Appium and WebdriverIO, I have an app created (a .zip file) and I want to test it with those 2 frameworks.

TL:DR - just go to the fourth code block.

I followed some tutorials and created a project containing

  • config files
  • test files

and of course a package.json.

First things first, my package.json:

{
  "name": "my-test",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "wdio": "wdio run ./config/wdio.conf.js",
    "ios.app": "./node_modules/.bin/wdio ./config/wdio.ios.app.conf.js"
  },
  "devDependencies": {
    "@wdio/appium-service": "^7.16.16",
    "@wdio/cli": "^7.16.16",
    "@wdio/devtools-service": "^7.16.16",
    "@wdio/local-runner": "^7.16.16",
    "@wdio/mocha-framework": "^7.16.15",
    "@wdio/spec-reporter": "^7.16.14",
    "chai": "^4.3.6",
    "chromedriver": "^99.0.0",
    "wdio-chromedriver-service": "^7.2.8",
    "webdriverio": "^7.16.16"
  }
}

Then, my config files, divided in shared and ios :

shared.conf.js

exports.config = {
  // ====================
  // Runner and framework
  // Configuration
  // ====================
  runner: "local",
  framework: "mocha",
  mochaOpts: {
    timeout: 30000,
  },
  sync: true,
  logLevel: "info",
  deprecationWarnings: true,
  bail: 0,
  baseUrl: "localhost",
  // path for appium sessions
  path: "/wd/hub",
  waitforTimeout: 15000,
  connectionRetryTimeout: 90000,
  connectionRetryCount: 3,
  reporters: ["spec"],
  autoGrantPermissions: true,
  autoAcceptAlerts: true,
  nativeWebTap: true,

  // ====================
  // Appium Configuration
  // ====================
  services: [
    [
      "appium",
      {
        // For options see
        // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
        args: {
          // Auto download ChromeDriver
          relaxedSecurity: true,
          // chromedriverAutodownload: true,
          // For more arguments see
          // https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
        },
        command: "appium",
      },
    ],
  ],
  port: 4723,
};

wdio.ios.app.conf.js

const { join } = require("path");
const { config } = require("./shared.conf");

// ============
// Specs
// ============
config.specs = ["./tests/specs/**/*.spec.js"];

// ============
// Capabilities
// ============
// For all capabilities please check
// http://appium.io/docs/en/writing-running-appium/caps/#general-capabilities
config.capabilities = [
  {
    // The defaults you need to have in your config
    platformName: "iOS",
    maxInstances: 1,
    // For W3C the appium capabilities need to have an extension prefix
    // This is `appium:` for all Appium Capabilities which can be found here
    // http://appium.io/docs/en/writing-running-appium/caps/
    "appium:deviceName": "iPhone 7",
    "appium:platformVersion": "15.2",
    "appium:orientation": "PORTRAIT",
    // `automationName` will be mandatory, see
    // https://github.com/appium/appium/releases/tag/v1.13.0
    "appium:automationName": "XCUITest",
    // The path to the app
    "appium:app": join(process.cwd(), "../../../my-test.zip"),
    // Read the reset strategies very well, they differ per platform, see
    // http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
    "appium:noReset": true,
    // How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
    // default: 240
    "appium:newCommandTimeout": 240,
  },
];

exports.config = config;

So I created a very simple test file: there's a login screen, it finds the login textarea, writes the login, same for password, and push the button "signin":

describe("a test group", function () {
  it("a test", async function () {
    console.log("*******start*******");
    // commands here
    const selectUsername = 'type == "XCUIElementTypeTextField"';
    const selectPassword = 'type == "XCUIElementTypeSecureTextField"';
    const username = await $(`-ios predicate string:${selectUsername}`);
    const password = await $(`-ios predicate string:${selectPassword}`);
    const btnText = 'label == "SIGNIN"';
    const loginBtn = await $(`-ios predicate string:${btnText}`);
    await username.click();
    await username.addValue("[email protected]");
    await password.click();
    await password.addValue("mypassword");
    await loginBtn.click();
  });
});

My issue here is that when the test is running a) if I open the appium inspector, I can't find any running session, even if it has to exist somewhere:

enter image description here

plus (minor) I think the session never stops. If I re-run the test, the app running in the simulator shows the page of already logged-in, failing the test (because does not find the login/password fields).

Where are the sessions? and what I'm doing wrong?


Solution

  • Solved.

    I was not able to edit the path in config file, but if I change the remote path in appium inspector to / , it finds the current session.