Search code examples
javaandroidselenium-webdriverautomationappium-android

Appium script throws "Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type" for android application


Please find my code below and help me to get out of the exception

I am using Appium version 1.17.1,cglib3.3.0 jar,java-client-7.3.0 jar,Selenium-java-3.141.59 with project as java project

Please find the below code

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

}

HomePage.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;

}

Result: Application gets opened but not performing any actions and throws the below Exception

Getting the following Exception

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

Please help me to get out of the above exception.

Thanks in Advance


Solution

  • This might be due to unavailability of asm jar. It can be downloaded from the below link,

    http://download.forge.ow2.org/asm/