Error: Could not start a new session , possible causes are invalid address of server

Platform:Mac Ios
I launch the appium server ,click on inspector and then run the below java code
package demo;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.ios.IOSDriver;

import java.io.File;

public class FirstClass {
public WebDriver driver;

@BeforeClass
public void setUp() throws MalformedURLException{

DesiredCapabilities capabilities = new DesiredCapabilities();
File appDir=new File (“Users/Vikas/Downloads/Quotiful.app”) ;
capabilities.setCapability(“platformName”, “iOS”);
capabilities.setCapability(“platformVersion”, “9.0”);
capabilities.setCapability(“deviceName”,“Iphone_6s”);
capabilities.setCapability(“UDID”, “9af627ef929c13e048d80bea3d6e1ac4de44816f”);
capabilities.setCapability(“app”, appDir.getAbsolutePath());
@Test
public void testCal() throws Exception {
// //locate the Text on the calculator by using By.name()
driver.findElement(By.name(“OK”)).click();
driver.findElement(By.name(“Log in”)).click();

@AfterClass
public void teardown(){
//close the app

driver.quit();
System.out.println(“exection completed”);
}
}


Eclipse Error

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.0’, revision: ‘35ae25b’, time: ‘2016-03-15 16:57:40’
System info: host: ‘Gaurav-MacBook.local’, ip: ‘172.16.1.172’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.2’, java.version: ‘1.7.0_17’
Driver info: driver.version: IOSDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:43)
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:39)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:69)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:78)
at io.appium.java_client.ios.IOSDriver.(IOSDriver.java:55)
at demo.FirstClass.setUp(FirstClass.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
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.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:170)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:104)
at org.testng.TestRunner.privateRun(TestRunner.java:774)
at org.testng.TestRunner.run(TestRunner.java:624)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
at org.testng.SuiteRunner.run(SuiteRunner.java:261)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
at org.testng.TestNG.run(TestNG.java:1048)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:137)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:58)
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
Build info: version: ‘2.53.0’, revision: ‘35ae25b’, time: ‘2016-03-15 16:57:40’
System info: host: ‘Gaurav-MacBook.local’, ip: ‘172.16.1.172’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.2’, java.version: ‘1.7.0_17’
Driver info: driver.version: IOSDriver
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:76)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
… 35 more
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/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: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:64)
… 36 more
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 49 more

I guess, below row
driver = new IOSDriver(new URL(“http://127.0.0.1:4327/wd/hub”), capabilities);
is missing in @BeforeClass

tried with this…still no improvments .Pls help

@neha can you provide your whole @beforeClass method?

Hi @sam_viz
package demo;

import java.net.MalformedURLException;import java.net.URL;

import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.testng.annotations.AfterClass;import org.testng.annotations.BeforeClass;import org.testng.annotations.Test;

import io.appium.java_client.ios.IOSDriver;

import java.io.File;

public class FirstClass {public WebDriver driver;

@BeforeClasspublic void setUp() throws MalformedURLException{

DesiredCapabilities capabilities = new DesiredCapabilities();File appDir=new File (“Users/Vikas/Downloads/Quotiful.app”) ;capabilities.setCapability(“platformName”, “iOS”);capabilities.setCapability(“platformVersion”, “9.0”);capabilities.setCapability(“deviceName”,“Iphone_6s”);capabilities.setCapability(“UDID”, “9af627ef929c13e048d80bea3d6e1ac4de44816f”);capabilities.setCapability(“app”, appDir.getAbsolutePath());driver = new IOSDriver(new URL(“http://127.0.0.1:4327/wd/hub”), capabilities);
@Test public void testCal() throws Exception { driver.findElement(By.name(“OK”)).click(); driver.findElement(By.name(“Log in”)).click();

@AfterClass public void teardown(){ //close the app

driver.quit(); System.out.println(“exection completed”); } }

I launch the appium server ,click on inspector and then run the below java code

Can you just start the appium server and run the java code (without launching the inspector) ?

P.S: It’s not related to your problem (for now), but it seems to me that the path you specified in your appDir variable is missing a “/” in first ( “/Users/Vikas/Downloads/Quotiful.app”)

P.S 2: why do you have your @AfterClass method inside the @BeforeClass one?

i have literally tried everything… my automation was running seamlessly before and literally it stopped working suddenly…

on my IDE … it shows…
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.

below are the appium logs…

[debug] [Instruments] Attempting to run app on real device with UDID ‘baf9f892931888b3a66e70511bc4d2d213afce46’
[debug] [Instruments] Found Insruments-Without-Delay: /Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-instruments/thirdparty/iwd7
[debug] [Instruments] Spawning instruments with command: ‘/Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate -D /var/folders/ws/w0skf0_j6jvcj3_vn0j_lmdh0000gn/T/appium-instruments/instrumentscli0.trace -w baf9f892931888b3a66e70511bc4d2d213afce46 com.examsoft.SofTestMV12 -e UIASCRIPT “/Users/examsofttest/Library/Application Support/appium/bootstrap/bootstrap-af584f5b6c6e42b3.js” -e UIARESULTSPATH /var/folders/ws/w0skf0_j6jvcj3_vn0j_lmdh0000gn/T/appium-instruments’
[debug] [Instruments] And launch timeouts (in ms): {“global”:90000}

[iOSLog] [IOS_SYSLOG_ROW] Sep 22 13:43:10 iPad-configured-6 com.apple.xpc.launchd[1] : assertion failed: 13G34: launchd + 116796 [9F6284CF-8A17-36CC-9DB5-85D510A21F14]: 0x3

[debug] [Instruments] [INST STDERR] 2016-09-22 13:43:11.073 instruments[987:30837] WebKit Threading Violation - initial use of WebKit from a secondary thread.

[debug] [Instruments] [INST STDERR] Instruments Usage Error: Specified target process is invalid: com.XXXX.XXXXX
instruments, version 7.3 (60133)
usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument …]]]

[debug] [Instruments] Instruments exited with code 255

[Instruments] Error launching instruments: Instruments crashed on startup

i am not able to debug

Here is the command that is failing:

What happens if you run that (without quotes) from the terminal? Also, is ‘com.examsoft.SofTestMV12’ the correct bundle id? Instruments doesn’t seem to like it.

Yes i tried… that did not work , and the Bundle id is correct !!
in the end i set up my machine again …

Sometimes that’s the best way. Glad it’s working for you.