The problem
I’m trying to invoke Appium server programatically. I’m blocked by error telling "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.
".
Here is my sample code.
@Test
public void startWebkitProxy(){
//Commmand provided in terminal to start webkit debug
//“ios_webkit_debug_proxy -c 29808cb769651582f444f6d95a2ece576beb2591:27753 -d”
CommandLine iOSWebkitDebugProxyCommand = new CommandLine(“starting ios_webkit_debug_proxy”);
iOSWebkitDebugProxyCommand.addArgument("-c");
iOSWebkitDebugProxyCommand.addArgument(udidOfDevice+":27753"); //input
iOSWebkitDebugProxyCommand.addArgument("-d");
DefaultExecuteResultHandler iOSWebkitResultHandler = new DefaultExecuteResultHandler();
DefaultExecutor iOSProxyexecutor = new DefaultExecutor();
iOSProxyexecutor.setExitValue(1);
try {
iOSProxyexecutor.execute(iOSWebkitDebugProxyCommand, iOSWebkitResultHandler);
iOSWebkitResultHandler.toString();
Thread.sleep(5000);
System.out.println("iOS Webkit debug proxy : Started");
} catch (IOException e) {
System.out.println("Failed to start iOS Webkit debug Proxy" + e);
e.printStackTrace();//paste the complete trace.
} catch (InterruptedException e) {
System.out.println("Failed to start iOS Webkit debug Proxy" + e);
e.printStackTrace();//paste the complete trace.
}
}
@Test
public void startAppiumServer(){
//Appium Server Arguements.
CommandLine commandAppiumServer = new CommandLine("/Applications/Appium.app/Contents/Resources/node/bin/node");
commandAppiumServer.addArgument("/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/appium.js", false);
commandAppiumServer.addArgument("--address", false);
commandAppiumServer.addArgument("127.0.0.1");
commandAppiumServer.addArgument("--port", false);
commandAppiumServer.addArgument("4723");
commandAppiumServer.addArgument("--no-reset", false);//Avoid resetting the app betweeen sessions
// commandAppiumServer.addArgument("–full-reset", false);
// commandAppiumServer.addArgument("–log-level", false);// Will block the console logs in eclipse
commandAppiumServer.addArgument("–log", false);
commandAppiumServer.addArgument("–session-override", true);
commandAppiumServer.addArgument("–pre-launch", true);
commandAppiumServer.addArgument(“safari”, true);
// commandAppiumServer.addArgument("–webkit-debug-proxy-port");port is 27753
System.out.println(“Server Flags : Completed.”);
//Customizing logs with time stamp information.
// Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime());
// command.addArgument("/Users/sethupandi/appium"+currentTimestamp+".log");
DefaultExecuteResultHandler serverResultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
System.out.println("Default Executor : executed commands.");
try {
executor.execute(commandAppiumServer, serverResultHandler);
System.out.println("Appium Server Started");
} catch (ExecuteException e) {
System.out.println("Failed to start Appium server" + e);
e.printStackTrace();
} catch (IOException e) {
System.out.println("Failed to start Appium server" + e);
e.printStackTrace();
}
// appiumService = AppiumDriverLocalService.buildDefaultService();
// appiumServerURL= appiumService.getUrl().toString();
// System.out.println("Appium service URL " + appiumServerURL);
}
@Test(dependsOnMethods={“startAppiumServer”})
public void killExistingSessions() {
System.out.println("killing the existing sessions");
CommandLine command = new CommandLine("cmd");
command.addArgument("/c");
command.addArgument("killall");
command.addArgument("node");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
try {
executor.execute(command, resultHandler);
System.out.println("Sessions cleared");
} catch (IOException e) {
System.out.println("Failed to pre kill the appium session" + e);
e.printStackTrace();//paste the complete trace.
}
}
@Test(dependsOnMethods={“killExistingSessions”})
public void addCapabilities() {
System.out.println("Declaring capabilities");
iosCapabilities= new DesiredCapabilities();
iosCapabilities.setCapability("CapabilityType.Browser_Name","Safari");
iosCapabilities.setCapability("browserName", "");//Safari if we invoke browser for automation. Else an empty string.
iosCapabilities.setCapability("autoWebview", true); // to retain the webview of app corresponding to session.
iosCapabilities.setCapability("sendKeyStrategy", "grouped");
iosCapabilities.setCapability("platformName", "iOS");
iosCapabilities.setCapability("appium-version", "1.4.13");
iosCapabilities.setCapability("platformVersion", "9.3.4");
iosCapabilities.setCapability("deviceName", "XXXX Ipad");
iosCapabilities.setCapability("device", "iPad Air 2");
iosCapabilities.setCapability("appName", "XXXXX");
iosCapabilities.setCapability("Udid", "29808cb769651XXXXXXf6d95a2ece576beb2591");
iosCapabilities.setCapability("bundleId", "com.XX.XXXX.mobile");
// iosCapabilities.setCapability(“FullReset”, true);
iosCapabilities.setCapability(“NoReset”, false);
iosCapabilities.setCapability(“nativeInstrumentsLib”, true); //Instructing to use Native instruments lib
iosCapabilities.setCapability(“app”, “/Users/XX/Documents/XXXX.ipa”); //<Mention the path , when app needs to be installed>
iosCapabilities.setCapability(“orientation”, “PORTRAIT”);//setting up orientation due to open bugs in interacting with UI elements in Landscape mode.
}
@Test(dependsOnMethods={“addCapabilities”})
public void appiumDriverInitialization() throws MalformedURLException, InterruptedException{
ios_driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"),iosCapabilities);
// ios_driver = new IOSDriver(new URL(appiumServerURL),cap);
System.out.println("Driver initialized");
}
Environment
- Appium version: 1.4.13
- Desktop OS/version used to run Appium:10.11.13
- Node.js version (unless using Appium.app|exe):
- Mobile platform/version under test: iOS 9.3.4
- Real device or emulator/simulator: Real Device.
- Appium CLI or Appium.app|exe: Xcode 7.3.1
Details
Link to Appium logs
[TestNG] Running:
/private/var/folders/gx/mhyf28l12s15xb_z08t3k4_80000gn/T/testng-eclipse–475563406/testng-customsuite.xml
Test : Trail
Server Flags : Completed.
Default Executor : executed commands.
Appium Server Started
usage: appium.js [-h] [-v] [–shell]
[–localizable-strings-dir LOCALIZABLESTRINGSDIR] [–app APP]
[–ipa IPA] [-U UDID] [-a ADDRESS] [-p PORT]
[-ca CALLBACKADDRESS] [-cp CALLBACKPORT] [-bp BOOTSTRAPPORT]
[-k] [-r BACKENDRETRIES] [–session-override] [–full-reset]
[–no-reset] [-l] [-lt LAUNCHTIMEOUT] [-g LOG]
[–log-level {info,info:debug,info:info,info:warn,info:error,warn,warn:debug,warn:info,warn:warn,warn:error,error,error:debug,error:info,error:warn,error:error,debug,debug:debug,debug:info,debug:warn,debug:error}]
[–log-timestamp] [–local-timezone] [–log-no-colors]
[-G WEBHOOK] [–native-instruments-lib]
[–app-pkg ANDROIDPACKAGE] [–app-activity ANDROIDACTIVITY]
[–app-wait-package ANDROIDWAITPACKAGE]
[–app-wait-activity ANDROIDWAITACTIVITY]
[–android-coverage ANDROIDCOVERAGE] [–avd AVD]
[–avd-args AVDARGS]
[–device-ready-timeout ANDROIDDEVICEREADYTIMEOUT] [–safari]
[–device-name DEVICENAME] [–platform-name PLATFORMNAME]
[–platform-version PLATFORMVERSION]
[–automation-name AUTOMATIONNAME]
[–browser-name BROWSERNAME] [–default-device]
[–force-iphone] [–force-ipad] [–language LANGUAGE]
[–locale LOCALE] [–calendar-format CALENDARFORMAT]
[–orientation ORIENTATION]
[–tracetemplate AUTOMATIONTRACETEMPLATEPATH]
[–instruments INSTRUMENTSPATH] [–show-sim-log]
[–show-ios-log] [–nodeconfig NODECONFIG] [-ra ROBOTADDRESS]
[-rp ROBOTPORT] [–selendroid-port SELENDROIDPORT]
[–chromedriver-port CHROMEDRIVERPORT]
[–chromedriver-executable CHROMEDRIVEREXECUTABLE]
[–use-keystore] [–keystore-path KEYSTOREPATH]
[–keystore-password KEYSTOREPASSWORD] [–key-alias KEYALIAS]
[–key-password KEYPASSWORD] [–show-config]
[–no-perms-check] [–command-timeout DEFAULTCOMMANDTIMEOUT]
[–keep-keychains] [–strict-caps] [–isolate-sim-device]
[–tmp TMPDIR] [–trace-dir TRACEDIR]
[–intent-action INTENTACTION]
[–intent-category INTENTCATEGORY]
[–intent-flags INTENTFLAGS]
[–intent-args OPTIONALINTENTARGUMENTS]
[–dont-stop-app-on-reset] [–debug-log-spacing]
[–suppress-adb-kill-server] [–async-trace]
appium.js: error: argument “-g/–log”: Expected one argument. null
iOS Webkit debug proxy : Started
killing the existing sessions
Sessions cleared
Declaring capabilities
PASSED: startAppiumServer
PASSED: startWebkitProxy
PASSED: killExistingSessions
PASSED: addCapabilities
FAILED: appiumDriverInitialization
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.53.1’, revision: ‘a36b8b1’, time: ‘2016-06-30 17:37:03’
System info: host: ‘V4s-MBP-2’, ip: ‘192.168.0.150’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.3’, java.version: ‘1.8.0_121’
Driver info: driver.version: IOSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
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:249)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:83)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:93)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:75)
at com.sg.s2bng.driversetup.driversetup.appiumDriverInitialization(driversetup.java:190)
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:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
Caused by: org.openqa.selenium.WebDriverException: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused (Connection refused)
Build info: version: ‘2.53.1’, revision: ‘a36b8b1’, time: ‘2016-06-30 17:37:03’
System info: host: ‘V4s-MBP-2’, ip: ‘192.168.0.150’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.3’, java.version: ‘1.8.0_121’
Driver info: driver.version: IOSDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:84)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
… 36 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused (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:144)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:69)
… 37 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
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)
… 50 more
SKIPPED: setNativeAppView
java.lang.Throwable: Method driversetup.setNativeAppView()[pri:0, instance:com.sg.s2bng.driversetup.driversetup@735b5592] depends on not successfully finished methods
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1068)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
SKIPPED: setWebView
java.lang.Throwable: Method driversetup.setWebView()[pri:0, instance:com.sg.s2bng.driversetup.driversetup@735b5592] depends on not successfully finished methods
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1068)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
SKIPPED: loginPage
java.lang.Throwable: Method driversetup.loginPage()[pri:0, instance:com.sg.s2bng.driversetup.driversetup@735b5592] depends on not successfully finished methods
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1068)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)
===============================================
Default test
Tests run: 8, Failures: 1, Skips: 3
===============================================
Default suite
Total tests run: 8, Failures: 1, Skips: 3
Configuration Failures: 1, Skips: 0
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@34f7cfd9: 6 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@3d1cfad4: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@932bc4a: 21 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@69997e9d: 7 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@37654521: 9 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 5 ms