Search code examples
javaappium

'class' or 'interface' expected


I am trying to start automating testing using Appium. I'm getting 'class' or 'interface' expected on my desired capabilities.

The code I'm using is below:

package tests;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;

public class AppiumTest {

    public static void main(String[] args) {

        //Set the Desired Capabilities
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "My Phone");
        caps.setCapability("udid", "ZY224Gs7NG"); //Give Device ID of your mobile phone
        caps.setCapability("platformName", "Android");
        caps.setCapability("platformVersion", "7.1.1");
        caps.setCapability("appPackage", "com.android.vending");
        caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
        caps.setCapability("noReset", "true");

        //Instantiate Appium Driver
        try {
            AppiumDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);

        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }
    }

}

Solution

  • Instead of the above code in AppiumTest class use the code

    cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID); cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android device");

    Always use device name as "Android device" and you don't need PlatformVersion line in your code and no need to give device id as well so also remove this line "caps.setCapability("udid", "ZY224Gs7NG");"

    The other code looks great it should work with these changes.