0

I am using the APK info app to know what activities' name are:

  package name.v2.acyivities.SplashActivity

  package name.v2.acyivities.OnBoardingChooseRegion

(...)

And then I create the DesiredCapabilities:

public AndroidDriver remoteRunningDevice() throws  Exception {

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability("platformName", MobileConfig.platformName);

    cap.setCapability("deviceName", MobileConfig.emulatorDeviceName);

    cap.setCapability("platformVersion", MobileConfig.emulatorPlatformVersion);

    cap.setCapability("app-package", MobileConfig.appPackage);
    cap.setCapability("appActivity","MobileConfig.appPackage" +".v2.acyivities.OnBoardingChooseRegion");
    cap.setCapability("noSign", true);

    driver = new AndroidDriver(new URL(MobileConfig.url), cap);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    return driver;
}

But it can't be run and result is:

java.lang.NullPointerException

How do I solve this?

6
  • Do you also have the stacktrace? On what line does the NullPointerException occur? Commented Nov 10, 2015 at 11:42
  • i tested on an already installed Android application and remeber application status by running cmd: Commented Nov 13, 2015 at 4:07
  • "C:/Program Files (x86)/Appium/node.exe" "C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js" --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone --log G:/log_appium.txt Commented Nov 13, 2015 at 4:07
  • But i can't run this command bu using java Runtime rt = Runtime.getRuntime(); final Process pr = rt.exec(APPIUMSERVERSTARTCMD); Commented Nov 13, 2015 at 4:08
  • Someone said add "cmd /c " before that command but it do not work Commented Nov 13, 2015 at 4:11

2 Answers 2

0
public AndroidDriver driver;

DesiredCapabilities capabilities = DesiredCapabilities.android();
capabilities.setCapability("deviceName", deviceName);
capabilities.setCapability("platformName", "android");
capabilities.setCapability(CapabilityType.VERSION, osVersion);
capabilities.setCapability("appPackage", "YOUR PACKAGE NAME");
capabilities.setCapability("appActivity", "MainActivity");
capabilities.setCapability("app", appPath);     

driver = new AndroidDriver(new URL("http://127.0.0.1:"+port2+"/wd/hub"),capabilities);

you can use UIAutomator to find your package name. Device name and OS version can be found using 'adb devices'

4
  • i tested on an already installed Android application and remeber application status by running cmd: "C:/Program Files (x86)/Appium/node.exe" "C:/Program Files (x86)/Appium/node_modules/appium/bin/Appium.js" --address 127.0.0.1 --chromedriver-port 9516 --bootstrap-port 4725 --selendroid-port 8082 --no-reset --local-timezone --log G:/log_appium.txt Commented Nov 13, 2015 at 4:09
  • But i can't run this command bu using java Runtime rt = Runtime.getRuntime(); final Process pr = rt.exec(APPIUMSERVERSTARTCMD) . Someone said add "cmd /c " before but it not work Commented Nov 13, 2015 at 4:11
  • Process p = Runtime.getRuntime().exec(command);
    – Suman
    Commented Nov 13, 2015 at 14:38
  • public String getPort() { ServerSocket socket = new ServerSocket(0); socket.setReuseAddress(true); String port = Integer.toString(socket.getLocalPort()); socket.close(); return port; } public void runCommand(){ String port = ap.getPort(); String chromePort = ap.getPort(); String bootstrapPort = ap.getPort(); String command = "appium --session-override -p "+port+" --chromedriver-port "+chromePort+" -bp "+bootstrapPort; Process p = Runtime.getRuntime().exec(command); }
    – Suman
    Commented Nov 13, 2015 at 15:52
0

in your code:

    cap.setCapability("app-package", MobileConfig.appPackage);
    cap.setCapability("appActivity","MobileConfig.appPackage" +".v2.acyivities.OnBoardingChooseRegion");

You are using MobileConfig.appPackage to get the package name, for example if the package name stored on MobileConfig.appPackage is 'com.example', the desired capability is somethings like app-package=com.example

What I am pointing here is the second line, when setting capabilities for appActivity which is you are using: "MobileConfig.appPackage" +".v2.acyivities.OnBoardingChooseRegion". The "MobileConfig.appPackage" will be considered as String, so the capability will become like:

appActivity=MobileConfig.appPackage.v2.acyivities.OnBoardingChooseRegion

This will lead to app Activity not found, since the package name is different (may causing the Null pointer, but I am not sure). I assume that you want to make the capability is more like:

appActivity=com.example.v2.acyivities.OnBoardingChooseRegion

the capability should be like this one:

    cap.setCapability("appActivity", MobileConfig.appPackage + ".v2.acyivities.OnBoardingChooseRegion");

Write the MobileConfig.appPackage without quotes. Hope this will help to find the clue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.