org.openqa.selenium.WebDriverException:


#1

below is the my code when i execute this code system shows me exception like that

org.openqa.selenium.WebDriverException: Connection refused: connect
Build info: version: ‘3.8.1’, revision: ‘6e95a6684b’, time: ‘2017-12-01T19:05:14.666Z’
System info: host: ‘MACPK-WKS-0066’, ip: ‘192.168.8.27’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_161’
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumCommandExecutor.lambda$2(AppiumCommandExecutor.java:141)
at java.util.Optional.orElseGet(Unknown Source)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:140)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
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.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:219)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:142)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:77)
at com.macrosoft.CherryPick.selendroidTest.test1(selendroidTest.java:61)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
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:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.openqa.selenium.remote.internal.ApacheHttpClient.fallBackExecute(ApacheHttpClient.java:138)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:86)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:101)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
… 34 more

------My Code is here -------
package com.macrosoft.CherryPick;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class selendroidTest {
private static AndroidDriver driver;
@Test
public void test1() throws MalformedURLException, InterruptedException{
// Create object of DesiredCapabilities class and specify android platform
// Create object of DesiredCapabilities class

	DesiredCapabilities capabilities = new DesiredCapabilities();
	 
	 
	 
	// Optional
	 
	capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
	 
	 
	// Specify the device name (any name)
	 
	capabilities.setCapability("deviceName", "My New Phone");
	 
	 
	// Platform version
	 
	capabilities.setCapability("platformVersion", "4.4.2");
	 
	 
	// platform name
	 
	capabilities.setCapability("platformName", "Android");
	 
	 
	// specify the application package that we copied from appium                
	 
	capabilities.setCapability("appPackage", "io.selendroid.testapp");
	 
	 
	// specify the application activity that we copied from appium                   
	 
	capabilities.setCapability("appActivity", ".HomeScreenActivity");
	 
	 
	// Start android driver I used 4727 port by default it will be 4723
	 
	driver = new AndroidDriver(new URL("http://127.0.0.1:4727/wd/hub"), capabilities);
	 
	 
	 
	// Specify the implicit wait of 5 second
	 
	driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	 
	 
	 
	// Enter the text in textbox
	 
	driver.findElement(By.xpath("//android.widget.EditText[@content-desc='my_text_fieldCD']")).sendKeys("Mukesh Selenium Appium");
	 
	 
	// click on registration button  
	                                   
	driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();
	 
	 
	 
	// Wait for 10 second
	 
	Thread.sleep(10000);
	 
	 
	 
	// close the application
	 driver.quit();

}

}


#2

Make sure you have launched the emulator.
if you want to launch avd via code use this -> http://aksahu.blogspot.in/2016/01/start-or-launch-android-emulator.html


#3

@Jeeva thanks for your dedication but i am using real device [galaxy s4] for testing


#4

Envirnment

  1. Appium
  2. senium
  3. Gson
  4. JDk
  5. Window 7
  6. Real testing device [galaxy s4]

Even device is connected with my laptop when I go to command prompt even it shows me my device


#5

Device udid is missing in desired capabilities. Please add it. and make sure you have enabled the USB debugging enabled in developer options.


#6

my device is matched all capabilites , now i am facing of this kind of issue
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: C:\Windows\system32\cmd.exe /s /c “java -jar “C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\sign.jar” C:\Software\selendroid-test-app-0.17.0.apk --override”
java.util.zip.ZipException: zip file is empty


#7

when i wants to connect with real device then appium shows me error


#8

I too faced this exception. Please find the logs below:

log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
driver launched
Changing to Stage environment
Jun 19, 2018 11:10:53 AM org.openqa.selenium.support.ui.ExpectedConditions findElements
WARNING: WebDriverException thrown by findElements(By.xpath: /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v4.widget.DrawerLayout/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView/android.support.v7.widget.LinearLayoutCompat[12])
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 170 milliseconds
Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’
System info: host: ‘m-c02pk1tsg3qc’, ip: ‘fe80:0:0:0:1861:ceae:b8cb:1b35%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.13.4’, java.version: ‘1.8.0_144’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.walmart.android, deviceScreenSize=1440x2560, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, unlockKey=123654789, deviceName=ce11160bd19c2d0205, platform=LINUX, deviceUDID=ce11160bd19c2d0205, appActivity=com.walmart.android.app.main.MainActivity, desired={appPackage=com.walmart.android, appActivity=com.walmart.android.app.main.MainActivity, platformVersion=7.0, unlockType=pattern, platformName=Android, unlockKey=123654789, deviceName=ce11160bd19c2d0205}, platformVersion=7.0, webStorageEnabled=false, locationContextEnabled=false, unlockType=pattern, takesScreenshot=true, javascriptEnabled=true, deviceModel=SM-G930F, platformName=Android, deviceManufacturer=samsung}]
Session ID: fb577a38-6626-4620-9070-a33a75a6f91a
*** Element info: {Using=xpath, value=/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.support.v4.widget.DrawerLayout/android.widget.FrameLayout[1]/android.support.v7.widget.RecyclerView/android.support.v7.widget.LinearLayoutCompat[12]}
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:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:671)
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.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:437)
at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:54)
at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.findElementsByXPath(RemoteWebDriver.java:513)
at io.appium.java_client.DefaultGenericMobileDriver.findElementsByXPath(DefaultGenericMobileDriver.java:144)
at io.appium.java_client.AppiumDriver.findElementsByXPath(AppiumDriver.java:200)
at org.openqa.selenium.By$ByXPath.findElements(By.java:356)
at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:398)
at io.appium.java_client.DefaultGenericMobileDriver.findElements(DefaultGenericMobileDriver.java:50)
at io.appium.java_client.AppiumDriver.findElements(AppiumDriver.java:164)
at org.openqa.selenium.support.ui.ExpectedConditions.findElements(ExpectedConditions.java:901)
at org.openqa.selenium.support.ui.ExpectedConditions.access$200(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$8.apply(ExpectedConditions.java:232)
at org.openqa.selenium.support.ui.ExpectedConditions$8.apply(ExpectedConditions.java:229)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:209)
at com.test.moneyservices.utilities.AppiumHelpers.waitForElementAndTap(AppiumHelpers.java:164)
at methodrepository.Flows.navigateToDebugOption(Flows.java:359)
at methodrepository.SetEnvironMentToStage.setEnvironment(SetEnvironMentToStage.java:63)
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:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
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:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
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)

Please help me resolve this.