FAILED CONFIGURATION: @BeforeClass launch org.openqa.selenium.SessionNotCreatedException: 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

FAILED CONFIGURATION: @BeforeClass launch
org.openqa.selenium.SessionNotCreatedException: 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) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 51.03 seconds
Build info: version: ‘2.52.0’, revision: ‘4c2593c’, time: ‘2016-02-11 19:03:33’
System info: host: ‘PBLAP253’, ip: ‘172.31.98.222’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_45’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:158)
at policybazaar.Health.launch(Health.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:510)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:211)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)

SKIPPED: mod1

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@506e6d5e: 92 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@4411d970: 93 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@79b4d0f: 14 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@6aaa5eb0: 14 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 14 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@668bc3d5: 12 ms

  1. Make sure app is installed before running script or provide apk path in “app” capability
  2. Check if you have provided the launch activity correctly for “appActivity” capability

running adb shell dumpsys window windows | Findstr “mCurrentFocus” immediately after launching app on test device may help you to get the activity name correctly

add driver start code - what activity you are adding to wait or ?

Main activitiy to launch app

@Anshita_Sen sometimes before Main activity starting other activities starting. To forget about activity staff:

capabilities.setCapability(MobileCapabilityType.APP, appDir.getAbsolutePath());
capabilities.setCapability("appWaitActivity", "xx.xxxx.*");

where “xx.xxxx” initial activity names of your app. e.g. with default Message app on phone we have:

"com.google.android.apps.messaging.ui.ConversationListActivity" -> "com.google.android.apps.messaging.*"