如何正确安装测试ai分类器插件使用appium为用户界面选择器?

cyvaqqii  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(268)

遇到的问题是在ubuntu20.04上。
遵照https://github.com/testdotai/appium-classifier-plugin
我确实在appium路径下安装了test-ai分类器,并使用npm install-g test-ai分类器进行了全局安装
通过从命令行appium doctor运行,我确保appium doctor没有给我任何错误。我转到appium路径并从命令行执行以下操作:
节点
require('test-ai-classifier');
总是出现同样的错误:

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: [ '' ]

你们中有人遇到过这个问题吗?如果是,你是怎么解决的?你使用了哪种环境?你是在全局还是在appium的路径中安装了测试ai分类器?

gcmastyq

gcmastyq1#

环境:

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

先决条件;安装android sdk并配置android\u home安装java sdk并配置java\u home
appium安装步骤:

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)

测试ai分类器安装-全局:

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

测试ai分类器安装-应用程序路径:

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

全局节点模块配置:npm在哪里安装包?如果要更改全局模块路径,请使用npm config edit并将prefix=/my/npm/global/modules/prefix放在文件中

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

如何验证测试ai分类器安装?

[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.

在inteelij中创建java类并添加以下代码:

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();

    }
}

创建testng.xml,如下所示:

<?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>

从命令行启动appium服务器:

appium -a 127.0.0.1 -p 4723

右键单击testng.xml,然后执行。在“设置”下观察蓝牙应用程序正在被选中。请随时采取源代码/项目从

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

此外,我还添加了一个视频:https://youtu.be/cfdsejljeqy

vulvrdjw

vulvrdjw2#

在我的例子中,我使用python并在ubuntu20.04上工作。anbunathan也为那些使用或热爱java并在windows上工作的人提供了答案
先决条件:

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

环境:

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-classifies=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安装步骤(我没有全局安装appium):

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

测试ai分类器安装-应用程序路径:

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

为了确保安装了测试ai分类器,请执行以下操作:

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.

请随意查看位于此处的源代码项目:

https://github.com/ericnana/appium_classifier_ai_python

相关问题