请找到我下面的代码,帮我摆脱异常。
我使用Appium 1.17.1版本,cglib3.3.0 jar,java-client-7.3.0 jar,Selenium-java-3.141.59,项目为java项目。
请找到以下代码
HybridBase.java
public class HybridBase {
public static AndroidDriver<AndroidElement> capabilities(String device) throws MalformedURLException
{
AndroidDriver<AndroidElement> driver;
File f = new File("src");
File fs = new File(f,"ApiDemos-debug.apk");
DesiredCapabilities cap=new DesiredCapabilities();
if(device.equals("real")){
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
}
else if(device.equals("emulator")){
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
}
cap.setCapability(MobileCapabilityType.UDID, "3200f0fdb4e8753b");
// cap.setCapability(MobileCapabilityType.UDID, "3200f0fdb4e8753b");
cap.setCapability(MobileCapabilityType.FULL_RESET, false);
cap.setCapability(MobileCapabilityType.NO_RESET, true);
cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
driver=new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
return driver;
}
}
Basic.java
public class Basic extends HybridBase {
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
AndroidDriver<AndroidElement> driver = capabilities("real");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
HomePage h = new HomePage(driver);
// driver.findElementByXPath("//android.widget.TextView[@content-desc='Preference']").click();
//driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();
h.preferences.click();
Preferences p =new Preferences(driver);
//driver.findElementByXPath("//android.widget.TextView[@text='3. Preference dependencies']").click();
p.dependencies.click();
driver.findElementById("android:id/checkbox").click();
driver.findElementByXPath("(//android.widget.RelativeLayout)[2]").click();
driver.findElementByClassName("android.widget.EditText").sendKeys("Karthi");
driver.findElementsByClassName("android.widget.Button").get(1).click();
}
}
首页.java
public class HomePage {
public HomePage(AppiumDriver driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
// PageFactory.initElements(driver, this);
}
@AndroidFindBy(xpath = "//android.widget.TextView[@text='Preference']")
public WebElement preferences;
}
Preferences.java
public class Preferences {
public Preferences(AppiumDriver driver) {
PageFactory.initElements(new AppiumFieldDecorator(driver), this);
// PageFactory.initElements(driver, this);
}
@AndroidFindBy(xpath = "//android.widget.TextView[@text='3. Preference dependencies']")
public WebElement dependencies;
}
结果:应用程序被打开但没有执行任何操作,并抛出以下异常。应用程序被打开,但没有执行任何操作,并抛出以下异常。
得到以下异常
Jun 12, 2020 8:35:55 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type
at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:184)
at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:72)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:72)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:222)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:220)
at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:105)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:160)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at pageobjects.HomePage.<init>(HomePage.java:15)
at Basic.main(Basic.java:19)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 14 more
请帮我摆脱上述异常情况。
先谢谢你
这可能是由于无法使用 罐子. 它可以从以下链接下载。
我通过添加asm-6.1 jar和添加cglib-3.2.6 jar而不是cglib-3.3.0 jar得到了上述问题的解决方法
cglib jar的链接 - https:/github.comcglibcglibreleases。asm-6.1 jar的链接--。http:/download.forge.ow2.orgasm。
如果有任何需要澄清的地方,请随时联系......。
This issue occurs due to the incompatible jar. try to use the latest jar from the below link,
https://github.com/cglib/cglib/releases
http://download.forge.ow2.org/asm/
http://download.forge.ow2.org/
References
https://github.com/appium/appium/issues/9699