appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.22k stars 758 forks source link

Unable to run appium server script programmatically Err:Cannot instantiate class #1274

Closed mounikaakuthota12 closed 4 years ago

mounikaakuthota12 commented 4 years ago

Trying to run the appium server launch through code (java) but facing an issue below are the logs.....It's running fine if start appium either from terminal or Desktop appium..

########### . appium version : v1.15.1 . ###############

[RemoteTestNG] detected TestNG version 7.0.0 log4j:WARN No appenders could be found for logger (AppiumServer). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. [Appium] Welcome to Appium v1.15.1 [Appium] Appium REST http interface listener started on 0.0.0.0:4723 [HTTP] --> GET /wd/hub/status [HTTP] {} [debug] [GENERIC] Calling AppiumDriver.getStatus() with args: [] [debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.15.1"}} [HTTP] <-- GET /wd/hub/status 200 5 ms - 68 [HTTP]  [HTTP] --> GET /wd/hub/status [HTTP] {} [debug] [GENERIC] Calling AppiumDriver.getStatus() with args: [] [debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.15.1"}} [HTTP] <-- GET /wd/hub/status 200 2 ms - 68 [HTTP]  [HTTP] --> POST /wd/hub/session [HTTP] {"desiredCapabilities":{"app":"/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk","appActivity":"com.cbs.app.screens.startup.SplashActivity","appPackage":"com.cbs.app","newCommandTimeout":15000,"automationName":"Appium","platformName":"Android","deviceName":"520056e44e84150d"},"capabilities":{"firstMatch":[{"appium:app":"/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk","appium:appActivity":"com.cbs.app.screens.startup.SplashActivity","appium:appPackage":"com.cbs.app","appium:automationName":"Appium","appium:deviceName":"520056e44e84150d","appium:newCommandTimeout":15000,"platformName":"android"}]}} [debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk","appActivity":"com.cbs.app.screens.startup.SplashActivity","appPackage":"com.cbs.app","newCommandTimeout":15000,"automationName":"Appium","platformName":"Android","deviceName":"520056e44e84150d"},null,{"firstMatch":[{"appium:app":"/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk","appium:appActivity":"com.cbs.app.screens.startup.SplashActivity","appium:appPackage":"com.cbs.app","appium:automationName":"Appium","appium:deviceName":"520056e44e84150d","appium:newCommandTimeout":15000,"platformName":"android"}]}] [debug] [BaseDriver] Event 'newSessionRequested' logged at 1574881448933 (11:04:08 GMT-0800 (Pacific Standard Time)) [Appium] [Appium] ====================================================================== [Appium] DEPRECATION WARNING: [Appium] [Appium] The 'automationName' capability was not provided in the desired [Appium] capabilities for this Android session [Appium] [Appium] Setting 'automationName=UiAutomator2' by default and using the [Appium] UiAutomator2 Driver [Appium] [Appium] The next major version of Appium (2.x) will require the [Appium] 'automationName' capability to be set for all sessions on all [Appium] platforms [Appium] [Appium] In previous versions (Appium <= 1.13.x), the default was [Appium] 'automationName=UiAutomator1' [Appium] [Appium] If you wish to use that automation instead of UiAutomator2, please [Appium] add 'automationName=UiAutomator1' to your desired capabilities [Appium] [Appium] For more information about drivers, please visit [Appium] http://appium.io/docs/en/about-appium/intro/ and explore the [Appium] 'Drivers' menu [Appium] [Appium] ====================================================================== [Appium] [Appium] Appium v1.15.1 creating new AndroidUiautomator2Driver (v1.37.2) session [debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided [debug] [BaseDriver] Creating session with W3C capabilities: { [debug] [BaseDriver] "alwaysMatch": { [debug] [BaseDriver] "platformName": "android", [debug] [BaseDriver] "appium:app": "/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk", [debug] [BaseDriver] "appium:appActivity": "com.cbs.app.screens.startup.SplashActivity", [debug] [BaseDriver] "appium:appPackage": "com.cbs.app", [debug] [BaseDriver] "appium:automationName": "Appium", [debug] [BaseDriver] "appium:deviceName": "520056e44e84150d", [debug] [BaseDriver] "appium:newCommandTimeout": 15000 [debug] [BaseDriver] }, [debug] [BaseDriver] "firstMatch": [ [debug] [BaseDriver] {} [debug] [BaseDriver] ] [debug] [BaseDriver] } [BaseDriver] Session created with session id: 0fd31f41-88d1-4434-a2fd-c3bda62eabf6 [BaseDriver] Using local app '/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk' [debug] [UiAutomator2] Checking whether app is actually present [ADB] The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb. [debug] [UiAutomator2] Deleting UiAutomator2 session [debug] [BaseDriver] Event 'newSessionStarted' logged at 1574881449057 (11:04:09 GMT-0800 (Pacific Standard Time)) [debug] [W3C] Encountered internal error running command: Error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path. [debug] [W3C] at ADB.getBinaryFromPath (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:135:11) [HTTP] <-- POST /wd/hub/session 500 158 ms - 789 [HTTP]  org.testng.TestNGException: Cannot instantiate class com.cbs.test.RunAndroidAppSuite at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:30) at org.testng.internal.InstanceCreator.instantiateUsingDefaultConstructor(InstanceCreator.java:193) at org.testng.internal.InstanceCreator.createInstanceUsingObjectFactory(InstanceCreator.java:113) at org.testng.internal.InstanceCreator.createInstance(InstanceCreator.java:79) at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:114) at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:172) at org.testng.TestClass.getInstances(TestClass.java:102) at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:82) at org.testng.TestClass.init(TestClass.java:74) at org.testng.TestClass.(TestClass.java:39) at org.testng.TestRunner.initMethods(TestRunner.java:463) at org.testng.TestRunner.init(TestRunner.java:342) at org.testng.TestRunner.init(TestRunner.java:295) at org.testng.TestRunner.(TestRunner.java:226) at org.testng.remote.support.RemoteTestNG6_12$1.newTestRunner(RemoteTestNG6_12.java:33) at org.testng.remote.support.RemoteTestNG6_12$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG6_12.java:66) at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:679) at org.testng.SuiteRunner.init(SuiteRunner.java:196) at org.testng.SuiteRunner.(SuiteRunner.java:127) at org.testng.TestNG.createSuiteRunner(TestNG.java:1265) at org.testng.TestNG.createSuiteRunners(TestNG.java:1244) at org.testng.TestNG.runSuitesLocally(TestNG.java:1093) at org.testng.TestNG.runSuites(TestNG.java:1032) at org.testng.TestNG.run(TestNG.java:1000) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:23) ... 26 more Caused by: java.lang.ExceptionInInitializerError at com.cbs.test.framework.AndroidObject.(AndroidObject.java:28) at com.cbs.test.DriverObject.android(DriverObject.java:23) at com.cbs.test.RunAndroidAppSuite.(RunAndroidAppSuite.java:14) ... 32 more Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path. Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'C02XQ8SRJG5JMBP', ip: '10.119.135.102', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path. at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9) at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:388:37) Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'C02XQ8SRJG5JMBP', ip: '10.119.135.102', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2' Driver info: driver.version: AndroidDriver at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208) at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:95) at com.cbs.test.framework.helpers.AndroidHelper.startAppiumDriver(AndroidHelper.java:52) at com.cbs.test.framework.helpers.AndroidHelper.(AndroidHelper.java:38) ... 35 more Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186) ... 49 more Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path. Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03' System info: host: 'C02XQ8SRJG5JMBP', ip: '10.119.135.102', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '12.0.2' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find 'adb' in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path. at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:804:9) at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:388:37) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62) at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128) ... 54 more

CODE SNIPPET:

static {
    AppiumServer.launchAppiumServer("4723");
    Props.loadRunConfigProps(RUN_CONFIG_PROPERTIES);
    ANDROID_DRIVER = startAppiumDriver();
    Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
}

private AndroidHelper() {
    super(ANDROID_DRIVER);
}

private static AndroidDriver<MobileElement> startAppiumDriver() {
    DesiredCapabilities capabilities = getAppiumDesiredCapabilities();

// int port = 4723; // if(!AppiumServer.checkIfServerIsRunnning(port)) { try { ANDROID_DRIVER = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } return ANDROID_DRIVER; }

######### And the Appiumserver class which appium provided . ############### /// AppiumServer.java . /////

package com.cbs.test.framework.helpers;

import java.io.IOException; import java.net.ServerSocket; import java.net.URL;

import org.apache.log4j.Logger;

import io.appium.java_client.service.local.AppiumDriverLocalService; import io.appium.java_client.service.local.AppiumServiceBuilder;

/**

mykola-mokhnach commented 4 years ago

Duplicate of https://github.com/appium/appium/issues?q=is%3Aissue+%22ANDROID_HOME+or+ANDROID_SDK_ROOT+%22+is%3Aclosed

Please make sure the environment is properly configured for the process.

mounikaakuthota12 commented 4 years ago

@mykola-mokhnach Thank you.