-2

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

}
glglgl
  • 89,107
  • 13
  • 149
  • 217
Tom Cockram
  • 217
  • 2
  • 16
  • @glglgl Did you mean to say Shared? Mr comedian. – SamHoque Dec 12 '18 at 10:16
  • I know nothing of the DesiredCapabilities class but I suspect youre not supposed to try to call its constructor. There are static methods you would call https://stackoverflow.com/questions/17527951/what-is-the-use-of-desiredcapabilities-in-selenium-webdriver – JoeHz Dec 12 '18 at 10:17
  • @JoeHz According to https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/remote/DesiredCapabilities.html#DesiredCapabilities--, there is nothing wrong doing so. – glglgl Dec 12 '18 at 10:25
  • Can you post exact error message and mark the line which cause the problem? – talex Dec 12 '18 at 10:30
  • @talex the line that is causing the problem are: caps.setCapability("platformVersion", "7.1.1"); it is complaining about a 'class' or 'interface' expected – Tom Cockram Dec 12 '18 at 10:43

1 Answers1

0

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.

Nauman Malik
  • 188
  • 8