'Appium Test Connection Refused

I'm trying to run this simple test on Appium on an android phone that's supposed to open a calculator application but I keep getting errors.

This is the code I've written :

package appiumTests;

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;

public class CalculatorTest {

static AppiumDriver<MobileElement> driver;

public static void main(String args[]) {

    try {
        openCalculator();
    } catch (Exception e) {

        System.out.println(e.getCause());
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

}

public static void openCalculator() throws Exception {

    DesiredCapabilities cap = new DesiredCapabilities();

    cap.setCapability("devicename", "Galaxy A51");
    cap.setCapability("udid", "R58N4211WGA");
    cap.setCapability("platformName", "Android");
    cap.setCapability("platformVersion", "10");
    cap.setCapability("appPackage", "com.google.android.calculator");
    cap.setCapability("appActivities", "com.android.calculator2.Calculator");

    URL url = new URL("http://127.0.0.1:4723/wd/hub");
    driver = new AppiumDriver<MobileElement>(url, cap);
    
    
    System.out.println("APPLICATION STARTED...");
    
}

}

And these are the errors I'm getting:



Solution 1:[1]

  1. Make sure your appium server is started with default port (4723)
  2. udid/deviceName use either of them , preferably not both
  3. Capability is written wrongb replace with correct one already mentioned one

appActivities

appActivity

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Roberto Caboni