Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#147 Fix. The Appium node silent starting #240

Merged
merged 1 commit into from
Sep 11, 2015
Merged

#147 Fix. The Appium node silent starting #240

merged 1 commit into from
Sep 11, 2015

Conversation

TikhomirovSergey
Copy link
Contributor

Change list is below:

  • a new dependency was added;
        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.4.1</version>
        </dependency>
  • The package io.appium.java_client.service.local with designed classes was added;
  • The class io.appium.java_client.remote.AppiumCommandExecutor was designed;
  • AppiumDriver and subclasses were refactored. New constructors were added.
  • almost all tests were redesigned

Requirements

  • Installed Node.js 0.10 or greater.
  • At least an appium server instance installed via npm.

Warning (!!!) Node.js versions which lower than 0.12 are deprecated for Appium server >=1.4.10

Which capabilities these features provide

Proposed features provide abilities and options of the starting of a local Appium node server. End users still able to open apps as usual

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
    driver = new AndroidDriver<>(new URL("remoteOrLocalAddress"), capabilities);        

when the server has been working locally\remotely. Now they are free to launch a local Appium node server and open their app for the further testing the following way:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "");
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
    capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 120);
    driver = new AndroidDriver<>(capabilities);        

How to prepare the local service before the starting

If there is no specific parameters then

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

    AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();
    service.start();
    ...
    service.stop();

If there should be non default parameters specified then

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

    AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().withArgument(GeneralServerFlag.TEMP_DIRECTORY,
                    "C:/Windows/Temp"));

or

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

    AppiumDriverLocalService service = new AppiumServiceBuilder().withArgument(GeneralServerFlag.TEMP_DIRECTORY,
                    "C:/Windows/Temp").build();

Lists of available server side flags are here:

  • io.appium.java_client.service.local.flags.GeneralServerFlag;
  • io.appium.java_client.service.local.flags.AndroidServerFlag;
  • io.appium.java_client.service.local.flags.IOSServerFlag

Which parameters also can be defined

  • If there is need to define some specific port or any free port
  new AppiumServiceBuilder().
                    usingPort(4000);

or

  new AppiumServiceBuilder().
                    usingAnyFreePort();
  • if there is need to use another IP address
  new AppiumServiceBuilder().withIPAddress("127.0.0.1");
  • if there is need to define output log file
  import java.io.File;

  ...

  new AppiumServiceBuilder().withLogFile(logFile);
  • if there is need to define another Node.js executable file
  import java.io.File;

  ...

  new AppiumServiceBuilder().usingDriverExecutable(nodeJSExecutable);
  • if there is need to define another appium.js file
  import java.io.File;

  ...

  new AppiumServiceBuilder().withAppiumJS(appiumJS);

Some more detailes about this use case. The node server instance which has been installed via npm is supposed to be used by default. This instance can be overridden if an end user defines the "appium.node.path" system property any available way.

Externally defined file path or file path defined at system properties should contain a full path to the appium.js file (!). These server instances should have the proper structure.

How to create an AppiumDriver instance

The common constructor is still available

  public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities)

There are new constructors:

  public AppiumDriver(AppiumDriverLocalService service, Capabilities desiredCapabilities) 

  public AppiumDriver(AppiumServiceBuilder builder, Capabilities desiredCapabilities)

  public AppiumDriver(Capabilities desiredCapabilities) 

An instance of AppiumDriverLocalService which has passed through constructors will be stopped when

  driver.quit();

If there is need to keep the service alive during a long time then something like that is available

  service.start();

  ....

  new IOSDriver<MobileElement>(service.getUrl(), capabilities)

@TikhomirovSergey
Copy link
Contributor Author

@Jonahss
Will you mind if I'll myself to developer list

        <developer>
            <email>tichomirovsergey@gmail.com</email>
            <name>Sergey Tikhomirov</name>
            <url>https://github.com/TikhomirovSergey</url>
            <id>TikhomirovSergey</id>
        </developer>

? :)

@TikhomirovSergey
Copy link
Contributor Author

#147

@TikhomirovSergey
Copy link
Contributor Author

These features send server output to an IDE console also.

@Jonahss
Copy link
Member

Jonahss commented Sep 8, 2015

Oh wow this IS the bomb, way to go.

I'm liking it.
Definitely add yourself to the developer list :)

I'm glad you included good exceptions for if appium or Nodejs aren't installed.

@simonk how's it look to you?

System.setProperty(AppiumServiceBuilder.APPIUM_NODE_PROPERTY, definedNode);
AppiumDriverLocalService.buildService(new AppiumServiceBuilder().withIPAddress("127.0.0.1").
usingPort(4000).withArgument(GeneralServerFlag.TEMP_DIRECTORY,
"C:/Windows/Temp"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test going to pass on non-windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is passees on Mac OS X. But I'll remove this in order to avoid the confusion.

@bootstraponline
Copy link
Member

This PR is cool 👍 If I understand correctly, java-client is now able to programmatically start the appium node server.

}
catch (Throwable e){
destroyProcess();
throw new AppiumServerHasNotBeenStartedLocallyException("An unexpected throwable has been caught!",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd be more concise like this?

throw new ServerNotStartedException("The local appium server has not been started.");

The message An unexpected throwable has been caught! isn't very useful to an end user.

@TikhomirovSergey
Copy link
Contributor Author

Thanks @bootstraponline for remarks. I'll make improvements as sson as possible.

This PR is cool 👍 If I understand correctly, java-client is now able to programmatically start the appium node server.

Yep! You are exactly right!

@TikhomirovSergey
Copy link
Contributor Author

@bootstraponline @Jonahss Improvements were done.

I added custom_node_path.properties. Here are paths to appium.js installed with Appium desktop application. They are needed for 2-4 tests. Make sure that Appium desktop application is installed on your environment

@bootstraponline
Copy link
Member

👍

TikhomirovSergey added a commit that referenced this pull request Sep 11, 2015
#147 Fix. The Appium node silent starting
@TikhomirovSergey TikhomirovSergey merged commit 6b91363 into appium:master Sep 11, 2015
@saikrishna321
Copy link
Member

@TikhomirovSergey i tried running appium-server programmatically from java_client(3.2.0),node version(v0.12.7), i get the below error

io.appium.java_client.service.local.InvalidNodeJSInstance: Node.js is not installed
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:87)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:160)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.java:156)
at com.appium.android.test.AndroidGestureTest.beforeClass(AndroidGestureTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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.TestRunner.beforeRun(TestRunner.java:647)
at org.testng.TestRunner.run(TestRunner.java:615)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.io.IOException: Cannot run program "node": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:83)
... 27 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 31 more

@Jonahss
Copy link
Member

Jonahss commented Sep 21, 2015

@saikrishna321 Sergey is on vacation for the next week or two. You can take a look at the source and try to see whats going wrong with your setup.

@prachi02
Copy link

Hi,

I am getting the following error ,when trying to do so

module.js:340
throw err;
^
Error: Cannot find module '../../package.json'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object. (C:\Users\cwnl-psingh\AppData\Roaming\npm\node_modules\appium\lib\server\parser.js:3:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)

@muralidhar1620
Copy link

Tried with :
AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe")).withAppiumJS(new File("E:/AppiumForWindows-1.3.4.1/Appium/Appium.exe")));
Thread.sleep(60000);
service.start();

Seeing Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'SAMSUNG-PC', ip: '192.168.1.75', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_45'
Driver info: driver.version: AndroidDriver

// ########### Initialization in Script was
driver = new AndroidDriver(new URL(
"http://127.0.0.1:4723/wd/hub"), capabilities);

@prachi02
Copy link

@muralidhar1620 ...first try the default one
AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();

and see what you are getting

@prachi02
Copy link

@muralidhar1620 ...for me this piece of code is working

service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe")).withAppiumJS(new File("D:/appium/Appium/node_modules/appium/bin/appium.js")));
Thread.sleep(60000);
service.start();

@prachi02
Copy link

@muralidhar1620 ...you have to give path of appium.js not appium.exe.....and another thing in capabilities section give this:
driver = new AndroidDriver(capabilities);

Not this: this gives error what you are getting
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),
capabilities);

@muralidhar1620
Copy link

@prachi02 Tried mentioned steps and i am seeing Error

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/validator/routines/InetAddressValidator
at io.appium.java_client.service.local.AppiumServiceBuilder.createArgs(AppiumServiceBuilder.java:230)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:293)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:160)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.java:156)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:183)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:87)
at java_client.PerkTVDriverScript.main(PerkTVDriverScript.java:63)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.validator.routines.InetAddressValidator

@prachi02
Copy link

@muralidhar1620 ....paste your entire code which you are using
Are you having all dependecies...like selenium 2.47 ,common validators 1.41,java client 3.2.0?

@muralidhar1620
Copy link

Thanks @prachi02 for Reply .selenium 2.47.1 and java client 3.2.0 exists but not common validators 1.41

code
package java_client;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebElement;

public class PerkTVDriverScript {

public static Properties config;
public static AppiumDriver driver;
static int NumberofPass;
static int NumberofFail;
public static String propFileName = "C:\\Users\\SAMSUNG\\workspace\\Aug18_AndroidTV\\src\\AndroidTV\\config.properties";

public static void main(String[] args) throws Exception {
    config = new Properties();
    String propFileName = "C:\\Users\\SAMSUNG\\workspace\\Aug18_AndroidTV\\src\\AndroidTV\\config.properties";
    config.load(new FileInputStream(propFileName)); 

    // ########### Environment set up ###########
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion",
            config.getProperty("AndroidPlatformVersion"));
    capabilities.setCapability("deviceName",
            config.getProperty("DeviceName"));
    capabilities.setCapability("app", config.getProperty("APKFilePath"));
    capabilities.setCapability("app-package", config.getProperty("Bundle"));
    capabilities.setCapability("app-activity", ".MainActivity");
    capabilities.setCapability("newCommandTimeout", "0");

    //public AppiumDriver(URL remoteAddress, Capabilities desiredCapabilities)

    // ########### Initialization ###########
    driver = new AndroidDriver(capabilities);

/*driver = new AndroidDriver<WebElement>(new URL(
            "http://127.0.0.1:4723/wd/hub"), capabilities);*/
    // driver = (AppiumDriver) new RemoteWebDriver(new
    // URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(250, TimeUnit.SECONDS);

    GenericFunctions.Initiate(driver);
    GenericFunctions
            .copyFileUsingChannel(
                    "C:\\Users\\SAMSUNG\\workspace\\Aug18_AndroidTV\\src\\AndroidTV\\Results Template.html",
                    GenericFunctions.filename);
    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
    Calendar calobj = Calendar.getInstance();
    GenericFunctions.ReportEvent("<h4>" + "Execution Start Time:"
            + df.format(calobj.getTime()) + "</h4/n>");
    String intNumberofPass = null;
    String intNumberofFail = null;

    /*AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe")).withAppiumJS(new File("E:/AppiumForWindows-1.3.4.1/Appium/node_modules/appium/bin/appium.js"))); 
    Thread.sleep(60000); 
    service.start();*/

    AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();

    Log_In();

}

@muralidhar1620
Copy link

@prachi02 Also node.js is installedin windows and i am able to launch appium server from that manually.Thanks!

@prachi02
Copy link

@muralidhar1620 ...no problem....

@muralidhar1620
Copy link

@prachi02 Did you got the issue ?.Can you please paste all working code and its dependencies.Thanks!

@prachi02
Copy link

In this section of code

/AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe")).withAppiumJS(new File("E:/AppiumForWindows-1.3.4.1/Appium/node_modules/appium/bin/appium.js")));
Thread.sleep(60000);
service.start();
/

AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService();

Log_In();

Uncomment till service.start() and comment second last line like

AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe")).withAppiumJS(new File("E:/AppiumForWindows-1.3.4.1/Appium/node_modules/appium/bin/appium.js")));
Thread.sleep(60000);
service.start();

Try the above code

@muralidhar1620
Copy link

@prachi02 I tried with mentioned code before and now and i am facing with same issue

Can connect to my machine Remotely(Teamviewer) and check please

Email id : muralidhar230@gmail.com

@prachi02
Copy link

@muralidhar1620 ...are you remotely login??.....

@w2a
Copy link

w2a commented Sep 24, 2015

I just tried the new 3.2 and the appium server works absolutely fine without any issues. I have recorded a tutorial on the same if anyone needs step by step information can go through the youtube video from below link:

https://youtu.be/Y0RgcVSFfio

Thanks,
Raman
http://www.way2automation.com

@saikrishna321
Copy link
Member

@w2a i was able to start the appium by below code

appiumDriverLocalService = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/bin/appium.js"))
.withLogFile(new File("logs.txt")));
appiumDriverLocalService.start();

But i have an issue, it says adb could not be located in tools and platform-tools..

I have my ANDROID_HOME set in both .bash_profile and .zshrc profile ..

1.when i run my tests form commandline it works.
2. start appium server from terminal and then run tests it works fine, appium can locate adb

But when i start the test programmatically appium throws error. Find the below logs

2015-09-25 10:38:23:222 - info: Welcome to Appium v1.4.11 (REV 8cf8311f00e59a2b10fde1834fcf6d5ace6fbcd0)
2015-09-25 10:38:23:225 - info: Appium REST http interface listener started on 0.0.0.0:4723
2015-09-25 10:38:23:227 - info: [debug] Non-default server args: {"log":"/Users/saikrisv/git/VodQa_MobileAutomationWorkShop/VodQA_WorkShop/logs.txt"}
2015-09-25 10:38:23:228 - info: Console LogLevel: debug
2015-09-25 10:38:23:228 - info: File LogLevel: debug
2015-09-25 10:38:23:329 - info: --> GET /wd/hub/status {}
2015-09-25 10:38:23:330 - info: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.11","revision":"8cf8311f00e59a2b10fde1834fcf6d5ace6fbcd0"}}}
2015-09-25 10:38:23:335 - info: <-- GET /wd/hub/status 200 6.736 ms - 105 {"status":0,"value":{"build":{"version":"1.4.11","revision":"8cf8311f00e59a2b10fde1834fcf6d5ace6fbcd0"}}}
2015-09-25 10:38:23:664 - info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"/Users/saikrisv/git/VodQa_MobileAutomationWorkShop/VodQA_WorkShop/build/wordpress.apk","appActivity":"org.wordpress.android.ui.WPLaunchActivity","package":"org.wordpress.android","platformName":"Android","deviceName":"9111833b","platformVersion":"5.0.2"}}
2015-09-25 10:38:23:665 - info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
2015-09-25 10:38:23:666 - info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : package
2015-09-25 10:38:23:668 - info: [debug] No appPackage desired capability or server param. Parsing from apk.
2015-09-25 10:38:23:668 - info: [debug] Using local app from desired caps: /Users/saikrisv/git/VodQa_MobileAutomationWorkShop/VodQA_WorkShop/build/wordpress.apk
2015-09-25 10:38:23:669 - info: [debug] Creating new appium session 8305b31c-1497-4d2b-b642-e6485d09e38d
2015-09-25 10:38:23:670 - info: Starting android appium
2015-09-25 10:38:23:671 - info: [debug] Getting Java version
2015-09-25 10:38:23:778 - info: Java version is: 1.8.0_51
2015-09-25 10:38:23:779 - info: [debug] Checking whether adb is present
2015-09-25 10:38:23:780 - info: [debug] Cleaning up android objects
2015-09-25 10:38:23:781 - info: [debug] Cleaning up appium session
2015-09-25 10:38:23:781 - error: Failed to start an Appium session, err was: Error: Could not find adb in tools, platform-tools, or supported build-tools under "/Users/saikrisv/Library/Android/sdk/platform-tools"; do you have the Android SDK installed at this location?
2015-09-25 10:38:23:784 - info: [debug] Error: Could not find adb in tools, platform-tools, or supported build-tools under "/Users/saikrisv/Library/Android/sdk/platform-tools"; do you have the Android SDK installed at this location?
at [object Object].ADB.checkSdkBinaryPresent (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:108:10)
at [object Object].ADB.checkAdbPresent (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:134:8)
at Function.ADB.createADB (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:73:7)
at [object Object].androidCommon.initAdb (/usr/local/lib/node_modules/appium/lib/devices/android/android-common.js:1083:9)
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:607:21
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:246:17
at iterate (/usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:146:13)
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:157:25
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:248:21
at /usr/local/lib/node_modules/appium/node_modules/async/lib/async.js:612:34
at [object Object]. (/usr/local/lib/node_modules/appium/lib/devices/android/android-common.js:1077:12)
at [object Object]. (/usr/local/lib/node_modules/appium/lib/devices/android/android-common.js:1064:12)
at ChildProcess.exithandler (child_process.js:742:7)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Socket. (child_process.js:1183:11)
at Socket.emit (events.js:107:17)
at Pipe.close (net.js:485:12)
2015-09-25 10:38:23:784 - info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find adb in tools, platform-tools, or supported build-tools under "/Users/saikrisv/Library/Android/sdk/platform-tools"; do you have the Android SDK installed at this location?)","origValue":"Could not find adb in tools, platform-tools, or supported build-tools under "/Users/saikrisv/Library/Android/sdk/platform-tools"; do you have the Android SDK installed at this location?"},"sessionId":null}
2015-09-25 10:38:23:786 - info: <-- POST /wd/hub/session 500 122.221 ms - 496

@w2a
Copy link

w2a commented Sep 25, 2015

do you have the androidStudio installed at this location: /Users/saikrisv/Library/Android/sdk/platform-tools

and same you have given in the .bash_profile

The issue is related to the path variables not configure properly or have you ever installed Android SDK prior to installing the latest one that you are working on?

Thanks,
Raman
http://www.way2automation.com

@saikrishna321
Copy link
Member

@w2a

export ANDROID_HOME=/Users/saikrisv/Library/Android/sdk
export PATH=/Users/saikrisv/Library/Android/sdk/platform-tools:/Users/saikrisv/Library/Android/sdk/tools:$PATH
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home

when i do "adb devices" from terminal, i can see devices.....

@muralidhar1620
Copy link

@ALL Is it possible to run script on multipe devices with this new Java client - Grid ? cc - @w2a

@mzeljkovic
Copy link

Hi All,

Awesome work!!
Just wondering, are you planning on exposing BootstrapPort and SelendroidPort in GeneralServerFlag? If memory serves right, starting multiple appium servers without overriding those ports will cause them to step on each other.

Cheers,
M

@TikhomirovSergey
Copy link
Contributor Author

Hi guys!
@mzeljkovic @muralidhar1620 @saikrishna321 @w2a @prachi02
Let's discuss your problems and concerns here: https://github.com/appium/java-client/issues

@saikrishna321

io.appium.java_client.service.local.InvalidNodeJSInstance: Node.js is not installed
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:87)
at io.appium.java_client.service.local.AppiumServiceBuilder.findDefaultExecutable(AppiumServiceBuilder.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildService(AppiumDriverLocalService.java:160)
at io.appium.java_client.service.local.AppiumDriverLocalService.buildDefaultService(AppiumDriverLocalService.java:156)
at com.appium.android.test.AndroidGestureTest.beforeClass(AndroidGestureTest.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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.TestRunner.beforeRun(TestRunner.java:647)
at org.testng.TestRunner.run(TestRunner.java:615)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.io.IOException: Cannot run program "node": error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
at java.lang.Runtime.exec(Runtime.java:620)
at java.lang.Runtime.exec(Runtime.java:450)
at java.lang.Runtime.exec(Runtime.java:347)
at io.appium.java_client.service.local.AppiumServiceBuilder.validateNodeJSVersion(AppiumServiceBuilder.java:83)
... 27 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
... 31 more

It doesn't work because a path to node.js is not defined in your PATH environment variable. Why? I don't know. Please check it. Here is the example for Win:

path

The same works fine on MAC OS X (I've checked it)/Linux if you download and install Node.js from: https://node js.org. Also the installation process should define the path to the instance in your PATH variable if everything is going properly.

Otherwise please open a new issue here:
https://github.com/appium/java-client/issues

@TikhomirovSergey
Copy link
Contributor Author

Here are samples with usuful comments

appium-boneyard/sample-code#62

@VenkateshPS
Copy link

can some one post command to start this service on mac

Regards,
Venkatesh

@savishy
Copy link

savishy commented Nov 20, 2015

This is just fantastic!
@VenkateshPS does the same Java code not work on Mac?

@VenkateshPS
Copy link

my question was how different the arguments for the code will be on mac? as i have installed and using Appium.app 1.4.13

@saikrishna321
Copy link
Member

@VenkateshPS There would b not different in code for mac.. All you need is appium installed from node.

@shivakrishnach31
Copy link

HI @saikrishna321 and @w2a ,

Below is my code:

package abc;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

public class NewTest {
private static AppiumDriverLocalService service;
@BeforeSuite
public void beforeSuite() throws InterruptedException{

service = AppiumDriverLocalService
            .buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("/Applications/Appium.app/Contents/Resources/node/bin/node"))
            .withAppiumJS(new File("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js"))
            .withLogFile(new File("logs.txt")));
            service.start();    
}
public AppiumDriver<MobileElement> driver;
@Test
public void findings() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("browserName", "");
    capabilities.setCapability("deviceName", "");
    capabilities.setCapability("platformName", "iOS");
    capabilities.setCapability("app", "*******.ipa");
    capabilities.setCapability("udid", "*******");
    try {
        driver =  new IOSDriver<MobileElement>(new URL("http://127.0.0.1/wd/hub"),capabilities);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

I got the below error when I run the above code. Could you please help me to get rid of this.

[TestNG] Running:
/private/var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/testng-eclipse-303574033/testng-customsuite.xml

�[36minfo�[39m: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
�[36minfo�[39m: Appium REST http interface listener started on 0.0.0.0:4723
�[36minfo�[39m: [debug] Non-default server args: {"log":"/Users/mahesh/Documents/automation/VideoRecording/logs.txt"}
�[36minfo�[39m: Console LogLevel: debug
�[36minfo�[39m: File LogLevel: debug
�[36minfo�[39m: �[37m-->�[39m �[37mGET�[39m �[37m/wd/hub/status�[39m �[90m{}�[39m
�[36minfo�[39m: [debug] Responding to client with success: {"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"}}}
�[36minfo�[39m: �[37m<-- GET /wd/hub/status �[39m�[32m200�[39m�[90m 11.740 ms - 105�[39m �[90m{"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"}}}�[39m
FAILED: findings
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'pcnicmcdev01', ip: '172.25.11.82', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_45'
Driver info: driver.version: IOSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
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.ios.IOSDriver.execute(IOSDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:247)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:37)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:160)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:168)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:56)
at video.NewTest.findings(NewTest.java:47)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
at org.testng.TestRunner.privateRun(TestRunner.java:773)
at org.testng.TestRunner.run(TestRunner.java:623)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
at org.testng.SuiteRunner.run(SuiteRunner.java:259)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
at org.testng.TestNG.run(TestNG.java:1018)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:80 [/127.0.0.1] failed: Connection refused
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'pcnicmcdev01', ip: '172.25.11.82', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_45'
Driver info: driver.version: IOSDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:64)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
... 35 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:80 [/127.0.0.1] failed: Connection refused
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:151)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:143)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:89)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:52)
... 36 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
... 49 more

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

Default suite

Total tests run: 1, Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@c46bcd4: 37 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@fad74ee: 6 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 6 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@52feb982: 20 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@7a187f14: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3043fe0e: 36 ms

@saikrishna321
Copy link
Member

@shivakrishnach31 look at the code below

AppiumServiceBuilder builder = new AppiumServiceBuilder().withAppiumJS(new File("/usr/local/lib/node_modules/appium/bin/appium.js"))
                 .withArgument(GeneralServerFlag.APP,
                                System.getProperty("user.dir") + "/build/wordpress.apk")
                               .withArgument(GeneralServerFlag.LOG_LEVEL, "info").usingAnyFreePort(); /*and so on*/;
                         appiumDriverLocalService = builder.build();
                         appiumDriverLocalService.start();
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("deviceName", "Android");
        caps.setCapability("platformVersion", "5.0.2");
        caps.setCapability("package", "org.wordpress.android");
        caps.setCapability("appActivity", "org.wordpress.android.ui.WPLaunchActivity");
        driver = new AndroidDriver<MobileElement>(appiumDriverLocalService.getUrl(), caps);

@TikhomirovSergey
Copy link
Contributor Author

Guys
Please report issues here
https://github.com/appium/java-client/issues

@daniellozynski
Copy link

Hi,

one of the server arguments is .withIPAdress() - what would be a scenario where I would change the IP address of the Appium server ? Not sure if I got this right...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.