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
答案 0 :(得分:1)
由于各种原因而出现这种情况,其中一个是过时的appium会话,它阻止了新会话的创建,
关闭appium服务器UI并重新启动它,
顺便说一下,您不需要使代码复杂化。使用类似这样的东西(导入并使用android驱动程序,不需要初始化chrome驱动程序)
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+"/");
}
}
答案 1 :(得分:0)
我也面临类似的问题
org.openqa.selenium.remote.UnreachableBrowserException:无法启动新会话。可能的原因是远程服务器的无效地址或浏览器启动失败。 构建信息:版本:&#39; 2.53.0&#39;,修订版:&#39; 35ae25b&#39;,时间:&#39; 2016-03-15 17:00:58&#39; 系统信息:主持人:&#39; Singh&#39;,ip:&#39; 192.168.56.1&#39;,os.name:&#39; Windows 8.1&#39;,os.arch:&#39 ; amd64&#39;,os.version:&#39; 6.3&#39;,java.version:&#39; 1.8.0_45&#39; 驱动程序信息:driver.version:AndroidDriver
Appium Logs
使用以下命令启动Appium服务器: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 警告:Appium对节点版本的支持&lt; 0.12已被弃用,将来的版本将被删除。请升级! 信息:欢迎来到Appium v1.4.13(REV c75d8adcb66a75818a542fe1891a34260c21f76a) info:Appium REST http接口监听器在192.168.0.7:4723
上启动
我得到了上述问题的解决方案:
正确设置ANDROID_HOME路径.....路径将是Android sdk文件 例如:-C:\ Users \ Abhishesh \ AppData \ Local \ Android \ android-sdk-windows
解决这个问题的方法是: - 正确设置系统路径变量 1)C:\ Program Files \ Java \ jdk1.8.0_91 \ bin ----设置jdk文件的路径 2)C:\ Users \ Abhishesh \ AppData \ Local \ Android \ android-sdk-windows \ platform-tools ---设置Android SDK平台工具的路径 3)C:\ Users \ Abhishesh \ AppData \ Local \ Android \ android-sdk-windows \ tools ---设置Android SDK工具的路径 4)%SystemRoot%\ system32 ----设置系统根目录 5)C:\ Program Files \ nodejs \ ----设置nodejs文件路径
设置所有路径变量后 检查cmd是否已正确设置 检查步骤: 打开CMD - &gt;输入adb 您应该得到如下所示的响应 Android Debug Bridge版本1.0.36 修订版0a04cdc4a62f-android adb response will look somewhat like this
请检查节点版本(检查节点版本的步骤) open cmd - &gt; type&#34; node --version&#34; 节点版本应小于<0.12 因为Appium不支持大于0.12的nodejs
OR 关闭Appium Server并重新启动它。