FAILED CONFIGURATION: @BeforeClass setUp 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

Hi,
I am new to Appium and am trying to configure Appium for the first time.
I had done the initial configuration but i am still unable to run the code. I had already been to all same queries posted on this forum but still unable to tackle the issue. Below are my code, Error message and Appium logs. Please help !!!

CODE:

package amazon;

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

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

public class appium {

WebDriver driver;

@BeforeClass
public void setUp() throws Exception {

//location of the app
File app = new File("D:\\Selenium\\workspaces\\AppiumTestProject\\src\\Apps\\Amazon", "ContactManager.apk");
//To create an object of Desired Capabilities
DesiredCapabilities capability = new DesiredCapabilities();
//OS Name
capability.setCapability("device","Android");
capability.setCapability(CapabilityType.BROWSER_NAME, "");
//Mobile OS version. In My case its running on Android 5.1.1
capability.setCapability(CapabilityType.VERSION, "5.1.1");
capability.setCapability("app", app.getAbsolutePath());
//To Setup the device name
capability.setCapability("deviceName","668dc236");
capability.setCapability("platformName","Android");
//set the package name of the app
capability.setCapability("app-package", "com.example.android.contactmanager-1");
//set the Launcher activity name of the app
capability.setCapability("app-activity", ".ContactManager");
//driver object with new Url and Capabilities
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capability);
System.out.println("App launched");
}


@Test
public void testApp() throws MalformedURLException{

	System.out.println("App launched");
	// locate Add Contact button and click it
	WebElement WebElementaddContactButton = driver.findElement(By.name("Add Contact"));
	//addContactButton.click();
	WebElementaddContactButton.click();
	//locate input fields and type name and email for a new contact and save it
	List<WebElement>textFields = driver.findElements(By.className("android.widget.EditText"));
	textFields.get(0).sendKeys("Neeraj Test");
	textFields.get(1).sendKeys("9999999999");
	textFields.get(2).sendKeys("[email protected]");
	driver.findElement(By.name("Save")).click();
	//insert assertions here
	}

}

ERROR LOG:

[TestNG] Running:
C:\Users\J\AppData\Local\Temp\testng-eclipse–1021935099\testng-customsuite.xml

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
FAILED CONFIGURATION: @BeforeClass setUp
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.46.0’, revision: ‘87c69e2’, time: ‘2015-06-04 16:16:56’
System info: host: ‘Jubin’, ip: ‘192.168.43.238’, os.name: ‘Windows 8’, os.arch: ‘amd64’, os.version: ‘6.2’, java.version: ‘1.7.0_13’
Driver info: driver.version: RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:242)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:128)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:155)
at amazon.appium.setUp(appium.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:175)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:107)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect
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:134)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:578)
… 28 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket(PlainConnectionSocketFactory.java:74)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
… 41 more

SKIPPED: testApp

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

===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 0

[TestNG] Time taken by org.testng.reporters.XMLReporter@3e0a1e1f: 32 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@6b2f5733: 38 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 8 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@584ffe5e: 81 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@191ad846: 50 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@2810ba97: 22 ms

APPIUM LOG

Starting Node Server

warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
info: [debug] Starting Appium in pre-launch mode
info: Pre-launching app
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] No appPackage desired capability or server param. Parsing from apk.
info: [debug] Using local app from command line: D:\Selenium\workspaces\AppiumTestProject\src\Apps\Amazon\ContactManager.apk
info: [debug] Creating new appium session 94946a2b-443d-40ef-85e2-b419baee9710
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_131
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe
info: [debug] Parsing package and activity from app manifest
info: [debug] Checking whether aapt is present
info: [debug] Using aapt from C:\Users\J\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe
info: [debug] Extracting package and launch activity from manifest.
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe dump badging D:\Selenium\workspaces\AppiumTestProject\src\Apps\Amazon\ContactManager.apk
info: [debug] badging package: com.example.android.contactmanager
info: [debug] badging act: com.example.android.contactmanager.ContactManager
info: [debug] Parsed package and activity are: com.example.android.contactmanager/com.example.android.contactmanager.ContactManager
info: [debug] Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
info: [debug] Using fast reset? false
info: [debug] Preparing device for session
info: [debug] Checking whether app is actually present
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Launching Emulator with AVD **************************************************************************, launchTimeout 120000ms and readyTimeout 120000ms
info: [debug] Checking whether emulator is present
info: [debug] Using emulator from C:\Users\J\AppData\Local\Android\sdk\tools\emulator.exe
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file C:\Users\J.android\avd**************************************************************************.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file (null)\config.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file C:\Users\J.android\avd**************************************************************************.ini for reading.
[6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file (null)\config.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file (null)\config.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file C:\Users\J.android\avd**************************************************************************.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file (null)\config.ini for reading.

error: Unable to start Emulator: [6408]:warning:./android/base/files/IniFile.cpp:158:Failed to process .ini file (null)\config.ini for reading.
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
info: [debug] Trying to find ************************************************************************** emulator
info: [debug] Getting connected emulators
info: [debug] Getting connected devices…
info: [debug] executing cmd: C:\Users\J\AppData\Local\Android\sdk\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: [debug] 0 emulator(s) connected
Killed Node Server.
Node Server Process Ended

problem with you emulator. Its not getting started. Can you first check your emulator has started before starting the tests.

Hi Team,

Thanks for the reply. I am not working with emulators. I am trying to debug on my Mobile Phone. The issue is however resolved now.

Solution:
In Appium Android setting i had previously checked the option to Launch AVD and as i had not configured AVD, so it was unable to start the session on AVD.

I just unchecked Launch AVD option and passed on my mobile ADB device id taken from cmd (adb devices) and everything is running smoothly.

Thanks again:grinning: