0

The problem encountered was on ubuntu 20.04.

Followed the instruction from https://github.com/testdotai/appium-classifier-plugin

I did install the test-ai-classifier under the appium path and as well globally using npm install -g test-ai-classifier

I made sure that appium-doctor did not give me any error by running from the command line appium-doctor. I went to the appium path and did the following from command line:

  1. node
  2. require('test-ai-classifier');

Always got the same error:

Thrown:
Error: Cannot find module 'test-ai-classifier'
Require stack:

at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18) { code: 'MODULE_NOT_FOUND', requireStack: [ '' ]

Has anyone of you encountered this issue? If yes, how did you solve it? Which environment did you use? Did you install test-ai-classifier globally or within the appium's path?

2 Answers2

0

Environment:

Windows 10
Tensorflow=1.1.0
python=2.7
global modules path = C:\Users\natha\AppData\Roaming\npm
appium = 1.19.1
node = 14.15.0
npm=6.14.9
test-ai-classifies=2.1.1

Pre-requisites; Install Android SDK and configure ANDROID_HOME Install Java SDK and configure JAVA_HOME

Appium installation steps:

npm install -g appium --drivers=xuitest,uiautomator2
npm install -g wd
appium -a 127.0.0.1 -p 4723
npm install -g appium-doctor
appium-doctor
(appium 1.19.1 is installed)

test-ai-classifier installation - globally:

npm install -g node-pre-gyp@0.11.0
npm install --unsafe-perm --verbose -g node-sass
npm install -g node-gyp --unsafe-perm=true
//NODE_GYP_FORCE_PYTHON=python
//NODE_GYP_FORCE_PYTHON=python2
npm install -g test-ai-classifier@2.1.1 --unsafe-perm=true --build-from-source --python=python2.7

test-ai-classifier installation - in appium path:

where appium
C:\Users\natha\AppData\Roaming\npm\appium
cd C:\Users\natha\AppData\Roaming\npm\node_modules\appium\
npm install node-pre-gyp@0.11.0
npm install --unsafe-perm --verbose node-sass
npm install node-gyp --unsafe-perm=true
npm install @tensorflow/tfjs-node@1.2.3
npm install test-ai-classifier@2.1.1

Global node modules configuration: Where does npm install packages? If you want to change the global modules path, use npm config edit and put prefix = /my/npm/global/modules/prefix in the file

change from
; prefix=C:\Program Files\nodejs
to
; prefix=C:\Users\natha\AppData\Roaming\npm

How to validate test-ai-classifier installation?

[https://github.com/cloudgrey-io/appiumpro/issues/9][2]

If you go into the place where appium is installed, and run node, you'll get an interactive node.js prompt. From there, run require("test-ai-classifier");
If you get an error, it means the classifier module is not correctly installed and accessible to appium.
If not, it means everything is good, just make sure you restarted the appium server after installing it.

Create a java class in InteeliJ and add the following code:

package com.example.appium;

import io.appium.java_client.MobileBy;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;


import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

public class TestAppiumAI {


    private static AndroidDriver driver;

    @Test
    public void installTest() throws MalformedURLException, InterruptedException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "MotoG");
        capabilities.setCapability("platformVersion", "7.1.1");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("udid", "ZH33L2Z6KL");
        capabilities.setCapability("automationName", "UiAutomator2");
        capabilities.setCapability("skipServerInstallation", "true");
        capabilities.setCapability("autoGrantPermissions", "true");
        capabilities.setCapability("noReset", "false");


        capabilities.setCapability("appPackage", "com.android.settings");
        capabilities.setCapability("appActivity","com.android.settings.Settings");

        HashMap<String, String> customFindModules = new HashMap<String, String>();
        customFindModules.put("ai", "test-ai-classifier");

        capabilities.setCapability("customFindModules", customFindModules);
        capabilities.setCapability("shouldUseCompactResponses", false);


        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

        //driver.findElement(MobileBy.custom("ai:search")).click();
        driver.findElement(MobileBy.custom("ai:bluetooth")).click();
        driver.quit();

    }
}

Create TestNG.xml as given below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Regression" thread-count="2" parallel="tests" preserve-order="true" verbose="2">

    <test name="Real Device1">
        <classes>
            <class name="com.example.appium.TestAppiumAI"/>
        </classes>
    </test>
</suite>

Start Appium server from command line:

appium -a 127.0.0.1 -p 4723

Right click TestNG.xml, and execute. Observe Bluetooth under Settings app is getting selected. Please feel free to take the source code/project from

[https://github.com/anbunathan/appium-examples/blob/master/Template1/src/test/java/com/example/appium/TestAppiumAI.java][2]

Also, I have added a video: https://youtu.be/CFDSejLJEQY

Anbunathan
  • 77
  • 6
0

In my case I used python and work on Ubuntu 20.04. There is also an answer from Anbunathan for those who use or love java and work on Windows

Pre-requisites:

Install Android SDK and configure ANDROID_HOME
Install Java SDK and configure JAVA_HOME

Environment:

Ubuntu 20.04,
Tensorflow=2.3.1,
Tensorflow-estimator=2.3.0,
Tensorflow-gpu=2.2.0,
python=2.7.18,
appium = 1.19.1,
node = 12.14.0,
npm=6.13.4,
test-ai-classifier=1.0.0

Put the following at the end of your bashrc
#Nodejs
VERSION=v12.14.0
DISTRO=linux-x64
export PATH=/usr/local/lib/node-$VERSION-$DISTRO/bin:$PATH

Appium installation steps(I did not install appium globally):

On the command line, in your home directory, create a directory for global installations: mkdir ~/.npm-global

Configure npm to use the new directory path: npm config set prefix '~/.npm-global'

In your prefer text editor, open or create a /.profile file and add this line to it: export PATH=/.npm-globa/bin:$PATH

On the command line, update your system variables: source ~/.profile

To test your new configuration, install a package globally without using sudo: npm install -g jshint

Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile): NPM_CONFIG_PREFIX=/home/user/.npm-global

npm install appium
npm install wd --> in the command line start appium
npm install appium-doctor --> in the command line start appium-doctor

Do not forget to set the path of appium in your bashrc (export NODE_PATH=~/.npm-global/lib/node_modules/appium:$PATH)

If you want to do it globally just do the following:

npm install -g appium --drivers=xuitest,uiautomator2
npm install -g wd --> in the command line start appium
npm install -g appium-doctor --> in the command line start appium-doctor

test-ai-classifier installation - in appium path:

go to cd ~/.npm-global/lib/node_modules/appium
npm install test-ai-classifier@1.0.0

You might want to install this if you ever face some problems:
npm install node-pre-gyp@0.11.0
npm install --unsafe-perm --verbose node-sass
npm install node-gyp --unsafe-perm=true
npm install @tensorflow/tfjs-node@1.2.3

In order to make sure that test-ai-classifier is installed do the following:

Go to your command line
cd ~/.npm-global/lib/node_modules/appium
Enter node
Enter require('test-ai-classifier');

If you get an error, it means the classifier module is not correctly installed and accessible to appium.

If not, it means everything is good, just make sure you restarted the appium server after installing it.
Create your python class using your favorite IDE (Android Studio in my case).
Go to your command line and start appium(appium -a 127.0.0.1 -p 4723).
Check as well if appium-doctor does not show any error. Start it from where you installed it.
Connect your device or start your simulator from your IDE.
Go to command line and start your python script. In my case I used python3 for the shebang but working with python 2.7.

Please feel free to take a look at the source code project located here:

https://github.com/ericnana/appium_classifier_ai_python