繁体   English   中英

使用 Android 模拟器从 eclipse 执行简单的 Appium 脚本时遇到问题,请帮我确定问题

[英]Getting issue while Executing simple Appium Script from eclipse using Android Emulator , Please help me identify the issue

Having 2 files and added jar files is added as Snapshot, my appium server is running fine showing me 200 response and on android emulator app is opening but not able to click any thing Java Build path and appium server logs as snapshot Appium Server Logs , node版本:v14.16.1,npm 版本:6.14.12,jave 版本:jdk-16_windows-x64_bin,Android studio 3.4.2 &Appium server:1.21.0 "ApiDemos-debug"
//基础文件1内容:

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Base {

    public static AndroidDriver<AndroidElement> Capabilities() throws MalformedURLException {
        // TODO Auto-generated method stub
    File f= new File("src");
    File fs= new File(f,"ApiDemos-debug.apk");  
DesiredCapabilities cap= new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "appium");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
AndroidDriver<AndroidElement> driver= new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
return driver ;
    }

}

//基础文件2内容:

导入 java.net.MalformedURLException; 导入 java.util.concurrent.TimeUnit;

导入 io.appium.java_client.android.AndroidDriver; 导入 io.appium.java_client.android.AndroidElement;

公共 class 基础扩展基础{

public static void main(String[] args) throws MalformedURLException, InterruptedException {
    // TODO Auto-generated method stub
    
    AndroidDriver<AndroidElement> driver = Capabilities();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //driver.findElementByXPath("(//android.widget.TextView)[8]").click();
    //driver.wait(2000);
    //driver.findElementsByClassName("//android.widget.TextView").get(8).click();
    driver.findElementByAndroidUIAutomator("text(\"Preference\")").click();
    
}

}

现在从 eclipse 运行时,基本文件 2 出现以下问题,即使在带有注释行的基本文件中也得到类似的失败响应:

May 09, 2021 11:00:15 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0 INFO: Detected dialect: W3C Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringUtils at io.appium.java_client.internal.ElementMap.getElementClass(ElementMap.java:77) at io.appium.java_client.internal.JsonToMobileElementConverter.newRemoteWebElement(JsonToMobileElementConverter.java:69) at org.openqa.selenium.remote.internal.JsonToWebElementConverter. apply(JsonToWebElementConverter.java:55) at io.appium.java_client.internal.JsonToMobileElementConverter.apply(JsonToMobileElementConverter.java:63) at org.openqa.selenium.remote.RemoteWebDrive r.execute(RemoteWebDriver.java:561) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client .android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323) at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61) at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1) 在 io.appium。 ava_client.android.AndroidDriver.findElement(AndroidDriver.java:1) at io.appium.java_client.FindsByAndroidUIAutomator.findElementByAndroidUIAutomator(FindsByAndroidUIAutomator.java:38) at Basics.main(Basics.java:18) Caused by: java.lang.ClassNotFoundException : org.apache.commons.lang3.StringUtils at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders. java:182) 在 java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)

错误消息如下:

引起: java.lang.ClassNotFoundExceptionorg.apache.commons.lang3.StringUtil

因此,您可能希望将Apache Commons Lang 3.x添加到调试版本:

debugImplementation "org.apache.commons:commons-lang3:3.12.0"

对于遇到同样问题的其他人,让我解释一下步骤:

  1. 打开“ Apache网站下载commons-lang3 ”>下载:commons-lang3-3.12.0-bin.zip下Apache Commons-lang3-3.12.0-bin.zip。
  2. 解压缩文件夹并仅复制“commons-lang3-3.12.0.jar”文件,不需要其他 jar 文件。 导航到系统中的类似路径:“C:\Program Files\Java\jdk1.8.0_181\jre\lib\ext”并粘贴上面的 jar
  3. 打开eclipse>右键单击项目>属性> java构建路径>库>添加外部jars ...> select并关闭“commons-lang3-31”文件夹。
  4. 添加“导入 org.apache.commons.*;” 在.java文件的顶部并保存>运行
  5. 现在运行您的项目,希望问题得到解决,如果没有,请告诉我。 此外,如果您对上述问题有其他解决方案,请随时更新评论。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM