paul
paul

Reputation: 4487

Appium: A new session could not be created

Before posting this question I went to these questions on Stackoverflow and other forums:

  1. A new session could not be created. (Original error: Instruments crashed on startup)
  2. Appium Error : A new session could not be created. (Original error: Did not get session redirect from Chromedriver)
  3. https://github.com/appium/appium/issues/2981
    and did few changes in my code below:

    Code:

    package test.appium;
    
    import io.appium.java_client.AppiumDriver;
    
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.remote.CapabilityType;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.testng.annotations.Test;
    
    public class WordPad {
    WebDriver dr;
    
    @Test
    public void testApp() throws MalformedURLException, InterruptedException {
        String apkpath = "D:\\apkdump\\blackcarbon.wordpad.apk";
        File app = new File (apkpath);
        DesiredCapabilities capabilities= new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
        capabilities.setCapability("deviceName","TestOneAdb1");
        capabilities.setCapability("appium-version", "1.2.4.1");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("app",app.getAbsolutePath());
        capabilities.setCapability("appPackage", "com.wordpad");
        capabilities.setCapability("appActivity", "com.wordpad.Main");
        dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);                    
        dr.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
        dr.quit();      
    }   
    }
    

    but I am still getting the error:

    info: [debug] UiAutomator shut down normally

    error: Failed to start an Appium session, err was: Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity

    info: [debug] Cleaning up android objects

    info: [debug] Cleaning up appium session

    info: [debug] Error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity

    at null.<anonymous> (D:\MobileTesting\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:1143:21)
    
    at null.<anonymous> (D:\MobileTesting\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:172:9)
    
    at ChildProcess.exithandler (child_process.js:635:7)
    
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    
    at maybeClose (child_process.js:743:16)
    
    at Process.ChildProcess._handle.onexit (child_process.js:810:5)
    

    info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)","origValue":"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity"},"sessionId":null}

    info: [37m<-- POST /wd/hub/session [39m[31m500[39m[90m 51290.254 ms - 346[39m [90m[39m What I tried:

    1. Install app manually on emulator and check if its working: It was working
    2. Once the app is installed via code: I can play with manually on emulator, it works perfectly fine.
    3. Downgrade Appium version from latest 1.1.0 tried but same error
    4. Specify Appiumversion capabilities in code, tried but still same error.

Let me know what I am missing, how can I launch app after installation?

Upvotes: 1

Views: 13806

Answers (3)

user6136
user6136

Reputation: 1

I had the same error, and it turned out to be because I'd changed my project's directory name, so the path to the apk was wrong. A silly mistake for sure, but probably worth checking just in case.

Upvotes: 0

kiedysktos
kiedysktos

Reputation: 4100

I had similar problem. My error message was also

"Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity".

In my case I had different main activity set in two places.

First one - Appium GUI:

Appium --> Android Settings --> Main Activity, Package and App Path

Second one - in the code:

capabilities.setCapability("appPackage", "com.company.AppName");
capabilities.setCapability("appActivity", "com.company.AppName.AppMainActivity");

Those two above have to be consistent - the same package and activity.

Upvotes: 0

Abhishek Swain
Abhishek Swain

Reputation: 1054

Possible Causes:

1. It seems the issue is with one more missing capability or improper android version:

capabilities.setCapability("platformVersion", "4.4");

As you are not using 'Selendroid' as automation mode, so the emulator or device you are using for testing should be of Android 4.2+ .

Please make this sure and mention the above desired capability in the list.

2. Instead of using

capabilities.setCapability("appActivity", "com.wordpad.Main");

try with

capabilities.setCapability("appActivity", ".Main");

Upvotes: 0

Related Questions