Closed mounikaakuthota12 closed 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.
@mykola-mokhnach Thank you.
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. [35m[Appium][39m Welcome to Appium v1.15.1 [35m[Appium][39m Appium REST http interface listener started on 0.0.0.0:4723 [35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/status[39m [35m[HTTP][39m [90m{}[39m [debug] [35m[GENERIC][39m Calling AppiumDriver.getStatus() with args: [] [debug] [35m[GENERIC][39m Responding to client with driver.getStatus() result: {"build":{"version":"1.15.1"}} [35m[HTTP][39m [37m<-- GET /wd/hub/status [39m[32m200[39m [90m5 ms - 68[39m [35m[HTTP][39m [90m[39m [35m[HTTP][39m [37m-->[39m [37mGET[39m [37m/wd/hub/status[39m [35m[HTTP][39m [90m{}[39m [debug] [35m[GENERIC][39m Calling AppiumDriver.getStatus() with args: [] [debug] [35m[GENERIC][39m Responding to client with driver.getStatus() result: {"build":{"version":"1.15.1"}} [35m[HTTP][39m [37m<-- GET /wd/hub/status [39m[32m200[39m [90m2 ms - 68[39m [35m[HTTP][39m [90m[39m [35m[HTTP][39m [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [35m[HTTP][39m [90m{"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"}]}}[39m [debug] [35m[W3C][39m 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] [35m[BaseDriver][39m Event 'newSessionRequested' logged at 1574881448933 (11:04:08 GMT-0800 (Pacific Standard Time)) [35m[Appium][39m [35m[Appium][39m ====================================================================== [35m[Appium][39m DEPRECATION WARNING: [35m[Appium][39m [35m[Appium][39m The 'automationName' capability was not provided in the desired [35m[Appium][39m capabilities for this Android session [35m[Appium][39m [35m[Appium][39m Setting 'automationName=UiAutomator2' by default and using the [35m[Appium][39m UiAutomator2 Driver [35m[Appium][39m [35m[Appium][39m The next major version of Appium (2.x) will require the [35m[Appium][39m 'automationName' capability to be set for all sessions on all [35m[Appium][39m platforms [35m[Appium][39m [35m[Appium][39m In previous versions (Appium <= 1.13.x), the default was [35m[Appium][39m 'automationName=UiAutomator1' [35m[Appium][39m [35m[Appium][39m If you wish to use that automation instead of UiAutomator2, please [35m[Appium][39m add 'automationName=UiAutomator1' to your desired capabilities [35m[Appium][39m [35m[Appium][39m For more information about drivers, please visit [35m[Appium][39m http://appium.io/docs/en/about-appium/intro/ and explore the [35m[Appium][39m 'Drivers' menu [35m[Appium][39m [35m[Appium][39m ====================================================================== [35m[Appium][39m [35m[Appium][39m Appium v1.15.1 creating new AndroidUiautomator2Driver (v1.37.2) session [debug] [35m[BaseDriver][39m W3C capabilities and MJSONWP desired capabilities were provided [debug] [35m[BaseDriver][39m Creating session with W3C capabilities: { [debug] [35m[BaseDriver][39m "alwaysMatch": { [debug] [35m[BaseDriver][39m "platformName": "android", [debug] [35m[BaseDriver][39m "appium:app": "/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk", [debug] [35m[BaseDriver][39m "appium:appActivity": "com.cbs.app.screens.startup.SplashActivity", [debug] [35m[BaseDriver][39m "appium:appPackage": "com.cbs.app", [debug] [35m[BaseDriver][39m "appium:automationName": "Appium", [debug] [35m[BaseDriver][39m "appium:deviceName": "520056e44e84150d", [debug] [35m[BaseDriver][39m "appium:newCommandTimeout": 15000 [debug] [35m[BaseDriver][39m }, [debug] [35m[BaseDriver][39m "firstMatch": [ [debug] [35m[BaseDriver][39m {} [debug] [35m[BaseDriver][39m ] [debug] [35m[BaseDriver][39m } [35m[BaseDriver][39m Session created with session id: 0fd31f41-88d1-4434-a2fd-c3bda62eabf6 [35m[BaseDriver][39m Using local app '/Users/makut0812/Documents/workspace/cbscom-qa-automation/cbsmobile/Resources/CBS-7.2.2-2172213-3.2.67-playStore-release.apk' [debug] [35m[UiAutomator2][39m Checking whether app is actually present [35m[ADB][39m 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] [35m[UiAutomator2][39m Deleting UiAutomator2 session [debug] [35m[BaseDriver][39m Event 'newSessionStarted' logged at 1574881449057 (11:04:09 GMT-0800 (Pacific Standard Time)) [debug] [35m[W3C][39m 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] [35m[W3C][39m at ADB.getBinaryFromPath (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:135:11) [35m[HTTP][39m [37m<-- POST /wd/hub/session [39m[31m500[39m [90m158 ms - 789[39m [35m[HTTP][39m [90m[39m 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:
// 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;
/**
*/ public class AppiumServer {
private static AppiumDriverLocalService service; public static AppiumServiceBuilder builder= new AppiumServiceBuilder(); static Logger log = Logger.getLogger("AppiumServer");
/**
catch(Exception e) { log.error(" Could not able to start appium server "); } return service.getUrl();
}
/**
This method is to stop Appium Server if still existing. */ public static void stopAppiumServer() { try{ if (service != null) service.stop(); log.info("Appium Server has been stopped."); } catch(Exception e){ log.error("Unable to stop Appium server."); } } public static boolean checkIfServerIsRunnning(int port) {
boolean isServerRunning = false; ServerSocket serverSocket; try { serverSocket = new ServerSocket(port); serverSocket.close(); } catch (IOException e) { //If control comes here, then it means that the port is in use isServerRunning = true; } finally { serverSocket = null; } return isServerRunning; }
// private AppiumDriverLocalService service; // private AppiumServiceBuilder builder; // private DesiredCapabilities cap; //
// public void startServer() { // //Set Capabilities // cap = new DesiredCapabilities(); // cap.setCapability("noReset", "false"); //
// //Build the Appium service // builder = new AppiumServiceBuilder(); // builder.withIPAddress("127.0.0.1"); // builder.usingPort(4723); // builder.withCapabilities(cap); // builder.withArgument(GeneralServerFlag.SESSION_OVERRIDE); // builder.withArgument(GeneralServerFlag.LOG_LEVEL,"error"); //
// //Start the server with the builder // service = AppiumDriverLocalService.buildService(builder); // service.start(); // } //
//
// // // // public static void main(String[] args) { // AppiumServerJava appiumServer = new AppiumServerJava(); //
// int port = 4723; // if(!appiumServer.checkIfServerIsRunnning(port)) { // appiumServer.startServer(); // appiumServer.stopServer(); // } else { // System.out.println("Appium Server already running on Port - " + port); // } // } //} }