Thanks @wreed, i am trying to reference below issue to start appium by programmatically and set AppiumDriverLocalService.
The thread you are following is JAVA programming way to start appium server. It is bit complex and more prone to errors ...
But AppiumDriverLocalService is a new feature implemented by appium guys in java client 3.2 to start appium server using appium library itself instead of using JAVA.
so wreed is basically saying when you use this new feature it is must to have node.js to be installed on u r system.
same error you are getting.
So first install node.js on your system then you can try with below code. It works fine on android for me.
In this way appium library just wants to know where is node.exe in u r system and where is appium.js file in ur system. appium.js file will be inside the appium server you downloaded and node.exe will be in programfiles like other installed programs.
AppiumDriverLocalService service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe"))
.withAppiumJS(new File("C:/Users/Desktop/android/AppiumForWindows-1.3.4.1/Appium/node_modules/appium/bin/appium.js"))
.withLogFile(new File("C:/Users/amit.ja/AppiumServerLogs.txt"))
.withIPAddress("127.0.0.1")
.usingPort(4725));
service.start();
Hope this Helps !!!!
Thanks @amitjaincoer191. i have successful to start the Appium service by AppiumDriverLocalService on MAC. The code lists as below:
public class StartAppium {
private IOSDriver<MobileElement> iosDriver;
private AppiumDriverLocalService service;
@BeforeClass
public void setUp() throws Exception {
service = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(
new File(
"/usr/local/lib/node_modules/appium/bin/appium.js"))
.withIPAddress("127.0.0.1").usingPort(4723));
service.start();
DesiredCapabilities capabilities = DesiredCapabilities.iphone();
capabilities.setCapability("platformName", "IOS");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("platformVersion", "9.0");
capabilities.setCapability("browserName", "Safari");
iosDriver = new IOSDriver<MobileElement>(service.getUrl(), capabilities);
iosDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
@Test
public void getAppiumStatus() {
iosDriver.navigate().to("http://www.baidu.com");
iosDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
iosDriver.findElementByName("wd").sendKeys("appium desired capability");
iosDriver.findElement(By.name("wd")).clear();
}
@AfterClass
public void tearDown() {
iosDriver.quit();
service.stop();
}
}
Hi guys,
Do you have any idea on how to assign nodeconfig file to appium by AppiumDriverLocalService ?
Thanks
Are u using grid nodeconfig.json file using this option ?
If yes Can u tell me one more thing ...
So for grid you used this code multiple times to register a node to a running grid HUB ???
Hi @amitjaincoer191,
Yes, i register appium as a node to Selenium Grid. The grid is the HUB.
But i don't try it multiple times.
Is there anything wrong on this ?
@suroit and @amitjaincoer191,
I got below error when I try with the @suroit code. As per the console error, it is saying ideviceinstaller is not installed on mac. But I have installed and it is alreary exist in my mac. Could u please help me to get rid of this errors.
[TestNG] Running:
/private/var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/testng-eclipse--385757555/testng-customsuite.xml
[36minfo[39m: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
[36minfo[39m: Appium REST http interface listener started on 127.0.0.1:4723
[36minfo[39m: [debug] Non-default server args: {"address":"127.0.0.1","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 8.936 ms - 105[39m [90m{"status":0,"value":{"build":{"version":"1.4.13","revision":"c75d8adcb66a75818a542fe1891a34260c21f76a"}}}[39m
[36minfo[39m: [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [90m{"desiredCapabilities":{"app":"/Users/mahesh/Downloads/ShureMotivPreview-3.ipa","browserName":"","platformName":"iOS","udid":"39e1f150b412544633088c913f117be93a846b67","deviceName":""}}[39m
[36minfo[39m: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_45)
[36minfo[39m: [debug] Using local .ipa from desired caps: /Users/mahesh/Downloads/ShureMotivPreview-3.ipa
[36minfo[39m: [debug] Copying local zip to tmp dir
[36minfo[39m: [debug] /Users/mahesh/Downloads/ShureMotivPreview-3.ipa copied to /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/appium-app.zip
[36minfo[39m: [debug] Unzipping /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/appium-app.zip
[36minfo[39m: [debug] Testing zip archive: /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/appium-app.zip
[36minfo[39m: [debug] Zip archive tested clean
[36minfo[39m: [debug] Unzip successful
[36minfo[39m: [debug] Using locally extracted app: /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/Payload/ShureMotiv.app
[36minfo[39m: [debug] Creating new appium session 155dcc2e-24f4-4b26-b037-1cb4a83e4554
[36minfo[39m: [debug] Removing any remaining instruments sockets
[36minfo[39m: [debug] Cleaned up instruments socket /tmp/instruments_sock
[36minfo[39m: [debug] Auto-detecting iOS udid...
[36minfo[39m: [debug] Not auto-detecting udid, running on sim
[36minfo[39m: [debug] Could not parse plist file (as binary) at /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/Payload/ShureMotiv.app/en.lproj/Localizable.strings
[36minfo[39m: Will try to parse the plist file as XML
[36minfo[39m: [debug] Could not parse plist file (as XML) at /var/folders/jx/ffh_slbj46l55xd0wqb7j7sc0000gp/T/115113-8681-1te72y6/Payload/ShureMotiv.app/en.lproj/Localizable.strings
[33mwarn[39m: Could not parse app Localizable.strings assuming it doesn't exist
[36minfo[39m: [debug] Getting bundle ID from app
[36minfo[39m: [debug] Parsed app Info.plist (as binary)
[36minfo[39m: [debug] Creating instruments
[36minfo[39m: [debug] Preparing uiauto bootstrap
[36minfo[39m: [debug] Dynamic bootstrap dir: /Users/mahesh/Library/Application Support/appium/bootstrap
[36minfo[39m: [debug] Dynamic env: {"nodePath":"/Applications/Appium.app/Contents/Resources/node/bin/node","commandProxyClientPath":"/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js","instrumentsSock":"/tmp/instruments_sock","interKeyDelay":null,"justLoopInfinitely":false,"autoAcceptAlerts":false,"autoDismissAlerts":false,"sendKeyStrategy":"grouped"}
...6minfo[39m: [debug] Dynamic bootstrap code: // This file is automatically generated. Do not manually modify!
[36minfo[39m: [debug] Dynamic bootstrap path: /Users/mahesh/Library/Application Support/appium/bootstrap/bootstrap-5b08b331b944fae5.js
[36minfo[39m: [debug] Reusing dynamic bootstrap: /Users/mahesh/Library/Application Support/appium/bootstrap/bootstrap-5b08b331b944fae5.js
[36minfo[39m: [debug] Attempting iOS device log capture via libimobiledevice idevicesyslog
[33mwarn[39m: Could not capture device log using libimobiledevice idevicesyslog. Libimobiledevice probably isn't installed
[36minfo[39m: [debug] Attempting iOS device log capture via deviceconsole
[36minfo[39m: [debug] Creating iDevice object with udid 39e1f150b412544633088c913f117be93a846b67
[36minfo[39m: [debug] Couldn't find ideviceinstaller, trying built-in at /Applications/Appium.app/Contents/Resources/node_modules/appium/build/libimobiledevice-macosx/ideviceinstaller
[31merror[39m: Could not initialize ideviceinstaller; make sure it is installed and works on your system
[36minfo[39m: [debug] Cleaning up appium session
[31merror[39m: Failed to start an Appium session, err was: Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
[36minfo[39m: [debug] Error: Could not initialize ideviceinstaller; make sure it is installed and works on your system
at [object Object].IOS.getIDeviceObj (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js:909:13)
at [object Object].IOS.installToRealDevice (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios.js:856:32)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:607:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:246:17
at iterate (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:146:13)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:157:25
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:248:21
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/async/lib/async.js:612:34
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:52:5)
at [object Object]. (/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios/ios-crash-log.js:27:5)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob. (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:131:7)
at Glob.emit (events.js:107:17)
at Glob.finish (/Applications/Appium.app/Contents/Resources/nodemodules/appium/node_modules/glob/glob.js:168:8)
at done (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:157:12)
at Glob.processReaddir2 (/Applications/Appium.app/Contents/Resources/nodemodules/appium/node_modules/glob/glob.js:351:12)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:288:17
at RES (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/inflight/inflight.js:23:14)
at f (/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/node_modules/once/once.js:17:25)
at Glob.readdirEntries (/Applications/Appium.app/Contents/Resources/nodemodules/appium/node_modules/glob/glob.js:480:10)
at /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/glob/glob.js:457:12
at FSReqWrap.oncomplete (fs.js:95:15)
[36minfo[39m: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system)","origValue":"Could not initialize ideviceinstaller; make sure it is installed and works on your system"},"sessionId":null}
[36minfo[39m: [37m<-- POST /wd/hub/session [39m[31m500[39m[90m 2030.939 ms - 300[39m [90m[39m
FAILED: findings
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2.23 seconds
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'pcnicmcdev01', ip: '172.25.11.76', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11', java.version: '1.8.0_45'
Driver info: io.appium.java_client.ios.IOSDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
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:647)
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:48)
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)
===============================================
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.JUnitReportReporter@39ed3c8d: 29 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 7 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@762efe5d: 13 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@75a1cd57: 26 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@6504e3b2: 44 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@182decdb: 26 ms
Just having ideviceinstaller on the Mac doesn't mean it shows on your $PATH. Try this command:which ideviceinstaller
That will tell you if it's on your $PATH. If it's not, here is a tutorial on adding to the $PATH on OS X:
http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/46
There are many more like it a mere google search away.
Hello friend,
Please use the way I explained in method-1 in my post, it will help you.
http://aksahu.blogspot.in/2015/10/start-and-stop-appium-server.html191
Thanks,
Aswini Kumar
http://in.linkedin.com/in/aksahu17
Hi
I am getting below error while starting appium server using above method.
It would be great, if you can help to solve this issue.
I am using 1.4.16 appium version on Mac
io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException: The local appium server has not been started. The given Node.js executable: /usr/local/bin/node Arguments: [/usr/local/lib/node_modules/appium/bin/appium.js, --port, 32394, --address, 127.0.0.1, --udid, 192.168.59.101:5555, --log-level, warn:error:info, --chromedriver-port, 59215, --bootstrap-port, 59214, --no-reset, --nodeconfig, /Users/mayur_d/Test_Branch_3.12/target/test-classes/GridConfig.json, --session-override]
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:140)
at com.test.gridsetup.GridConfig$1.run(GridConfig.java:202)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/exec/DaemonExecutor
at org.openqa.selenium.os.UnixProcess.(UnixProcess.java:52)
at org.openqa.selenium.os.CommandLine.(CommandLine.java:38)
at io.appium.java_client.service.local.AppiumDriverLocalService.start(AppiumDriverLocalService.java:125)
... 4 more
Caused by: java.lang.ClassNotFoundException: org.apache.commons.exec.DaemonExecutor
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Code i have written is
private void startAppiumServer(final Client client, final String nodeConfigFilePath) throws InterruptedException {
Logger.info("Starting appium server");
executorService = Executors.newSingleThreadExecutor();
executorService.execute(new Runnable() {
public void run() {
try {
AppiumDriverLocalService driverLocalService = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/bin/appium.js"))
.usingDriverExecutable(new File("/usr/local/bin/node")).withIPAddress("127.0.0.1")
.usingAnyFreePort().withArgument(GeneralServerFlag.UIID, client.getSerialNo())
.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,
"" + client.getBootstrapPort())
.withArgument(GeneralServerFlag.CHROME_DRIVER_PORT,
"" + client.getChromeDriverport())
.withArgument(GeneralServerFlag.NO_RESET)
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(GeneralServerFlag.LOG_LEVEL, "warn:error:info")
.withArgument(GeneralServerFlag.CONFIGURATION_FILE, nodeConfigFilePath));
Logger.info("Server url: " + driverLocalService.getUrl());
driverLocalService.start();
} catch (Exception e) {
Logger.error("Failed to start appium server. ");
e.printStackTrace();
}
}
});
}
Hey. I got below error while following the above step:
/usr/local/lib/node_modules/appium/bin/appium.js:1
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash’;
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:449:3
Hi, I got the error while following the same approach.
/usr/local/lib/node_modules/appium/bin/appium.js:1
(function (exports, require, module, __filename, __dirname) { import _ from 'lodash’;
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:449:3
Just to update on this thread for benefit of others, with below code I could get appiun node registered with Selenium HUB
String nodeConfigFilePath = "/Users/Mobile-Automation/Android-Automation/serenityAppiumFlipkart/EMULATOR_Nexus_4_1.json";
AppiumDriverLocalService driverLocalService = AppiumDriverLocalService
.buildService(new AppiumServiceBuilder()
.withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js"))
.usingDriverExecutable(new File("/usr/local/bin/node"))
//.withIPAddress("127.0.0.1")
.usingPort(4445)
//.withArgument(GeneralServerFlag.UIID, "123456")
//.withArgument(AndroidServerFlag.BOOTSTRAP_PORT_NUMBER,
// "" + 2252)
//.withArgument(GeneralServerFlag.CHROME_DRIVER_PORT,
// "" + client.getChromeDriverport())
//.withArgument(GeneralServerFlag.NO_RESET)
.withArgument(GeneralServerFlag.SESSION_OVERRIDE)
.withArgument(GeneralServerFlag.LOG_LEVEL, "debug")
.withArgument(GeneralServerFlag.CONFIGURATION_FILE, nodeConfigFilePath));
//Logger.info("Server url: " + driverLocalService.getUrl());
driverLocalService.start();
Before you run this program, make sure to try it out from command line with below command
appium --nodeconfig EMULATOR_Nexus_4_1.json --port 4445
In case you do something wrong as appium --nodeconfig EMULATOR_Nexus_4_1.json --bp 2252, you will get nice output about flags usage
Couple of open queries still as below
it didn't work with usingAnyFreePort(), I had to explicitly mention port number.
I could register android emulator node, even when it was not in open state, not sure if this is valid ?
Regards,
Vikram