Reputation: 140
Below code is run to start the appium on mobile platform either in virtual device or real device but the code does not work throwing the error. I'm unable to figure out issue in the code.
public static String baseurl;
@Test
public void setup() throws MalformedURLException, InterruptedException
{
//File appDir = new File("src");
//File app = new File(appDir,"HomeShop18.apk" );
DesiredCapabilities cap = DesiredCapabilities.android();
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
cap.setCapability(MobileCapabilityType.BROWSER_NAME,BrowserType.CHROME);
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.VERSION, "6");
cap.setCapability("appPackage","com.android.chrome");
cap.setCapability("appActivity","com.google.android.apps.chrome.Main");
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Google Nexus 5-6.0.0" );
//cap.setCapability(MobileCapabilityType.APP,app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
WebDriver driver = new ChromeDriver();
Thread.sleep(1000);
baseurl = "https://m.homeshop18.com";
driver.get(baseurl+"/");
}
}
Here is the error in the code and I tried by giving path of the chrome but the things does not work out
[TestNG] Running:
C:\Users\Abhishek.Dalakoti\AppData\Local\Temp\testng-eclipse--57850921\testng-customsuite.xml
FAILED: 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.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'HSNMM-AbhishekD', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_73'
Driver info: driver.version: AndroidDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:180)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:158)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:109)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:39)
at AppiumLates.AppiumClass.setup(AppiumClass.java:47)
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:85)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
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:75)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:46)
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:144)
at org.openqa.selenium.remote.internal.ApacheHttpClient.execute(ApacheHttpClient.java:90)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
... 31 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)
... 44 more
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
Upvotes: 0
Views: 1429
Reputation: 238
I also faced similar issue
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 17:00:58' System info: host: 'Singh', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45' Driver info: driver.version: AndroidDriver
Appium Logs
Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 192.168.0.7 --port 4723 --app C:\selendroid-test-app-0.17.0.apk --no-reset --platform-name Android --platform-version 23 --automation-name Appium --log-no-color warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade! info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a) info: Appium REST http interface listener started on 192.168.0.7:4723
I got the solution for the above problem as:
Set the ANDROID_HOME path correctly..... path will be the Android sdk file For eg:-C:\Users\Abhishesh\AppData\Local\Android\android-sdk-windows
Solution to this problem is:- Set the system path variable correctly 1) C:\Program Files\Java\jdk1.8.0_91\bin---- set the path of jdk file 2)C:\Users\Abhishesh\AppData\Local\Android\android-sdk-windows\platform-tools---set the path of Android SDK platform tool 3)C:\Users\Abhishesh\AppData\Local\Android\android-sdk-windows\tools --- set the path of Android SDK tool 4) %SystemRoot%\system32 ---- Set the System root directory 5) C:\Program Files\nodejs\ ---- Set the nodejs file path
Once you set all the path variables Check in cmd whether it has been set properly or not Steps to check: Open CMD--> type adb You should get the response like shown below Android Debug Bridge version 1.0.36 Revision 0a04cdc4a62f-androidadb response will look somewhat like this
please check the node version (Steps to check the node version) open cmd --> type "node --version" Node version should be less than <0.12 as Appium doesnt support nodejs greater than 0.12
OR Close Appium Server and restart it.
Upvotes: 0
Reputation: 1331
this shoots up for various reasons , one will be the stale appium session which is blocking from a new session to be created,
Close appium server UI and restart it,
BTW you don't need to complicate your code. Use something like this (import and use android driver, and don't need to initialize chrome driver)
import io.appium.java_client.android.AndroidDriver;
public static String baseurl;
@Test
public void setup() throws MalformedURLException, InterruptedException
{
//File appDir = new File("src");
//File app = new File(appDir,"HomeShop18.apk" );
DesiredCapabilities cap = DesiredCapabilities.android();
cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.VERSION, "6");
cap.setCapability("appPackage","com.android.chrome");
cap.setCapability("appActivity","com.google.android.apps.chrome.Main");
cap.setCapability(MobileCapabilityType.DEVICE_NAME,"Google Nexus 5-6.0.0" );
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
Thread.sleep(1000);
baseurl = "https://m.homeshop18.com";
driver.get(baseurl+"/");
}
}
Upvotes: 1