Appium Server not connected through Java Client Program

I am recently started Mobile Devices Automation on Appium With Java as language.

I am trying to run the initial setup code through program it is giving the below message. Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:4723 [/127.0.0.1] failed: Connection refused: connect

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.
System info: os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: '1.7.0_71’

When Manual run Appium server it doesn’t have any errors and server started , android apk file is installed.

Below is my code ,Eclipse doesn’t show any errors. I use Android Emulator for this Initial test. Appium and Java Project code in same host machine.

public void setup() throws MalformedURLException {
WebDriver AppWebDriver = null;
AppiumDriver ApUMDriver = null;
AndroidDriver AppiumURLDriver;

URL Serverurl;

// TODO Auto-generated method stub
DesiredCapabilities Appiumcapabiliy = new DesiredCapabilities();

 File appDir = new File("c:\ApkbuildsDir");
 File app = new File(appDir, "xxx.apk");

 Appiumcapabiliy.setCapability("devicename","Device11");
 Appiumcapabiliy.setCapability("platformname","Android");
 Appiumcapabiliy.setCapability("platformVersion","4.2.2");

 Appiumcapabiliy.setCapability("app-package","packagename");
 Appiumcapabiliy.setCapability("app-activity","activityscreen");
 Appiumcapabiliy.setCapability("app", app.getAbsolutePath());

 Serverurl = new URL("http://127.0.0.1:4723/wd/hub");
 AppWebDriver = new AndroidDriver(Serverurl,Appiumcapabiliy);

 AppWebDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS); 
 ApUMDriver.findElement(By.name("My Card"));

}
Could you please guide me how to eliminate this server connect error through program.

Regards, Kiran

Try with different port number greater than 4000

Hi ,
I tired as per your suggestion but no improvement. I modified the code as below but no improvement. see below code , instead of 127 default ip address I have provided host ip address and changed the port , same was mentioned in the Appium also. below code and error.

public class Sample {

//public static AndroidDriver driver;
public static AppiumDriver ApUMDriver;
public static DesiredCapabilities Appiumcapabiliy;
//public WebDriver AppWebDriver;

public static void main(String[] args) throws Exception {
	
	Appiumcapabiliy = new DesiredCapabilities();
	Appiumcapabiliy.setCapability("newCommandTimeout",300);
	
	 File appDir = new File("D://APPIUMWORK//android-sdk_r24.0.1-windows//android-sdk-windows//build-tools");
	 File app = new File(appDir, "Vons_4.2.0.3_09Oct14.apk");
	 
	 Appiumcapabiliy.setCapability("devicename","Device11");
	 Appiumcapabiliy.setCapability("platformname","Android");
	 Appiumcapabiliy.setCapability("platformVersion","4.2.2");
	 Appiumcapabiliy.setCapability(CapabilityType.BROWSER_NAME,"");	  
	 Appiumcapabiliy.setCapability("app-package","com.Safeway.client.android.vons");
	 Appiumcapabiliy.setCapability("app-activity","com.Safeway.client.android.ui.SplashScreen");
	 Appiumcapabiliy.setCapability("app", app.getAbsolutePath());
	 
	 ApUMDriver = new AndroidDriver (new URL("http://10.31.24.67:4725/wd/hub"),Appiumcapabiliy);
	 					 
	 ApUMDriver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
	
	
	//WebElement element = ApUMDriver.findElementByName("Weekly Ad");
	//element.click();
	
	
	
}

Error is pointing to this line - ApUMDriver = new AndroidDriver (new URL(“http://10.31.24.67:4725/wd/hub”),Appiumcapabiliy);

Eclipse Console text -
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.
System info: os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_71’
Driver info: driver.version: remote
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:593)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:39)
at com.Sample.Java.Sample.main(Sample.java:52)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 10.31.24.67:4725 [/10.31.24.67] failed: Connection refused: connect
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:140)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at org.openqa.selenium.remote.HttpCommandExecutor.fallBackExecute(HttpCommandExecutor.java:215)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)
… 7 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:72)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123)
… 19 more

Could you please help me in this regard , I really struck up at initial stage.

Regards,
Kiran

From the error it seems that there is a problem with IP address or port number.
Have you tried with 127.0.0.1:4000?

Hi ,

Yes , I have tried as per your suggestion but no improvement.

here is statement:
public static AppiumDriver ApUMDriver;
ApUMDriver = new AndroidDriver (new URL(“http://127.0.0.1:4725/wd/hub”),Appiumcapabiliy);

tried with different port no also like 4890 , no positive result.

Regards,
Kiran

Sorry, you can solve it by trial and error method please try again with
0.0.0.0:4000

Hi,

Here I tried temporarily , manually started Appium server as 127.0.0.1 and 4890
executed below code and it passed the url initiation code but Android Driver code is not working can you guide me.

executed below statement without any issues after manually starting the Appium server

ApUMDriver = new AndroidDriver (new URL(“http://127.0.0.1:4890/wd/hub”),Appiumcapabiliy);

now to test further steps , I have mentioned below

if (Anddriver.isLocked()){
System.out.println(“device is locked”);
} else{
System.out.println(“device is not locked”);
}

I am getting below error in the console.

Exception in thread “main” java.lang.NullPointerException
at com.Sample.Java.Sample.main(Sample.java:71)

when I clicked on “Sample.Java” link it is pointing to above code in the java file.

Can you guide me in this?

Also I am working on “Native App” automation? can reference links of AndroidDriver in Appium (I am using all latest files)

Regards,
Kiran

Hi Kiran,

The error, i reckon , is too obvious. Anyways Just curious, the driver variable (ApUMDriver) referenced to AndroidDriver and the one used (Anddriver) in the error-ed code are not the same. Can you check whether the code compiled without any errors?

If yes, check whether Anddriver is instantiated properly and is pointing to the AppiumServer to the correct URL.

Regards
Praveen MS

1 Like

Hi Praveen,

Thanks for response , after vacation back to work. Please ignore my previous code.

Below is working partially.
a) Able to kick start Appium server through code without any issues and it was perfectly running at 4788 port
Appiumcapabiliy.setCapability(“newCommandTimeout”,300);
CommandLine command = new CommandLine(“cmd”);
command.addArgument("/c");
command.addArgument(“C:\Program Files\nodejs\node.exe”);
command.addArgument(“D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\bin\appium.js”);
command.addArgument("–address");
command.addArgument(“127.0.0.1”);
command.addArgument("–port");
command.addArgument(“4788”);
command.addArgument("–no-reset");
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
DefaultExecutor executor = new DefaultExecutor();
executor.setExitValue(1);
executor.execute(command, resultHandler);
After above statements I have placed below code to install App on the Emulator which was configured and detected fully.

File appDir = new File(“D://APPIUMWORK//android-sdk_r24.0.1-windows//android-sdk-windows//build-tools”);
File app = new File(appDir, “Vons_4.2.0.3_09Oct14.apk”);

	 Appiumcapabiliy.setCapability("automationname", "appium");
	 Appiumcapabiliy.setCapability("platformname","Android");

Appiumcapabiliy.setCapability(“platformVersion”,“4.2.2”);
Appiumcapabiliy.setCapability(“devicename”,“Nexus 7”);
Appiumcapabiliy.setCapability(CapabilityType.BROWSER_NAME,"");
Appiumcapabiliy.setCapability(“app-package”,“com.Safeway.client.android.vons”);
Appiumcapabiliy.setCapability(“app-activity”,“com.Safeway.client.android.ui.SplashScreen”);
Appiumcapabiliy.setCapability(“app”, app.getAbsolutePath());

	 ApUMDriver = new AndroidDriver (new URL("http://127.0.0.1:4788/wd/hub"),Appiumcapabiliy);

I am getting the message , device name is not provided.
Please see error description as mentioned below.

e[36minfoe[39m: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
e[36minfoe[39m: Appium REST http interface listener started on 127.0.0.1:4788
e[36minfoe[39m: [debug] Non-default server args: {“address”:“127.0.0.1”,“port”:4788,“noReset”:true}
e[36minfoe[39m: Console LogLevel: debug
e[36minfoe[39m: e[37m–>e[39m e[37mPOSTe[39m e[37m/wd/hub/sessione[39m e[90m{“desiredCapabilities”:{“newCommandTimeout”:300,“automationname”:“appium”,“platformVersion”:“4.2.2”,“app”:“D:\APPIUMWORK\android-sdk_r24.0.1-windows\android-sdk-windows\build-tools\Vons_4.2.0.3_09Oct14.apk”,“platformName”:“Android”,“browserName”:"",“app-package”:“com.Safeway.client.android.vons”,“devicename”:“Nexus 7”,“platformname”:“Android”,“app-activity”:“com.Safeway.client.android.ui.SplashScreen”}}e[39m
e[31merrore[39m: The following desired capabilities are required, but were not provided: deviceName
e[31merrore[39m: Failed to start an Appium session, err was: Error: The following desired capabilities are required, but were not provided: deviceName
e[36minfoe[39m: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
e[36minfoe[39m: [debug] Got configuration error, not starting session
e[36minfoe[39m: [debug] Cleaning up appium session
e[36minfoe[39m: [debug] Error: The following desired capabilities are required, but were not provided: deviceName
at Capabilities.checkValidity (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\server\capabilities.js:139:13)
at Appium.configure (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\appium.js:226:35)
at null. (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\appium.js:106:10)
at Appium.start (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\appium.js:117:5)
at Object.exports.createSession [as handle] (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\lib\server\controller.js:182:16)
at next_layer (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\express\lib\router\route.js:113:13)
at Route.dispatch (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\express\lib\router\route.js:117:5)
at D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\express\lib\router\index.js:222:24
at Function.proto.process_params (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\express\lib\router\index.js:288:12)
at next (D:\APPIUMWORK\APPIUMFORWIN\AppiumForWindows-1.3.4.1\Appium\node_modules\appium\node_modules\express\lib\router\index.js:216:19)
e[36minfoe[39m: [debug] Responding to client with error: {“status”:33,“value”:{“message”:“A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName)”,“origValue”:“The following desired capabilities are required, but were not provided: deviceName”},“sessionId”:null}
e[36minfoe[39m: e[37m<-- POST /wd/hub/session e[39me[31m500e[39me[90m 6.888 ms - 286e[39m e[90me[39m
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.18 seconds
Build info: version: ‘2.44.0’, revision: ‘76d78cf’, time: ‘2014-10-23 20:03:00’
System info: host: ‘CSCINDAE751814’, ip: ‘10.31.24.67’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.7.0_71’
Driver info: io.appium.java_client.android.AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:240)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:126)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:153)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:109)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:39)
at com.Sample.Java.Sample.main(Sample.java:86)

Could you please guide me to resolve this issue?

Regards,
Kiran

Hi Kiran,

i too have gotten this error when i setup the appium server.

As documented in the URL http://appium.io/slate/en/v1.0.0/?ruby#appium-server-capabilities, can you update the capability as deviceName instead of devicename. Also, can you ensure that the device name Nexus 7 is listed when the command adb devices is run in the command line.

Hope this helps.

Note: adb devices will output the result as

List of devices attached
{device-id} {deviceName}

Regards
Praveen MS

on adv devices the name may not appear, but it is not important. You can set it:

deviceName = "Android"

or whatever. Your error, as praveenmukilan said is having devicename instead of deviceName

Hi Praveen & Telmo_Cardoso,

Provided solution “deviceName” have worked , now I am able to start the server and initiate / install app through code.

I have initiated emulator , applied command adb devices ,result is as follows.
List of devices attached
emulator-5554 device <In this case can I consider “device” is name of the emulator, I have doubt of device name>

In the code , I have kept the deviceName “Nexus 7” , I think device name is not important.

Thanks for your support !!! , going ahead now on Appium.

Praveen / Telmo_Cardoso, I have raised one more request , could you please respond to that if you have any info. Subject is as follows

Request Examples for AppiumDriver Locator Strategies

Regards,
Kiran

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

Hi i am facing same issue can you hemp me out?