Search code examples
androidnode.jstestingappiumnative

I want to tap on android keyboard search button with using Appium and node JS


I use Appium, NodeJS

I want to tap the search button on the mobile keyboard after entering the text in the input. But none of the following codes are executed. Could it have something to do with dependencies? Like drivers? Or the library used (webdriverio)?

Does anyone have a complete guide to offer?

Complete code:

const { remote } = require("webdriverio");

const capabilities = {
  "appium:platform": "Android",
  "appium:platformVersion": "11",
  "appium:automationName": "UiAutomator2",
  "appium:appPackage": "com.android.settings",
  "appium:appActivity": ".Settings",
  platformName: "Android",
  "appium:app":
    "/Users/ASUS/Downloads/MEmu Download/Showcaller-Caller-ID-Block-1.9.1(www.Farsroid.com).apk",
  "appium:deviceName": "Pixel 2 API 30",
  "appium:adv": "Pixel_2_API_30",
  "appium:autoGeneratePermissions": true,
  "appium:settings[ignoreUnimportantViews]": true,
};

const wdOpts = {
  hostname: process.env.APPIUM_HOST || "localhost",
  port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
  logLevel: "info",
  capabilities,
};

async function runTest() {
  const driver = await remote(wdOpts);
  try {
    await driver.touchPerform([{ action: "tap", options: { x: 50, y: 50 } }]);

    await driver.touchAction({
        action: "tap",
        x: 50,
        y: 50,
      });
  } finally {
    await driver.pause(1000);
    await driver.deleteSession();
  }
}

runTest().catch(console.log);

emulator: emulator

appium inspector: appium inspector


Solution

  • I found the answer to this problem. It hits the search button directly from the keyboard 😊😊😊

    await driver.execute("mobile: performEditorAction", { action: "Search" });