Chrome浏览器在使用Java的Appium中无法启动。

huangapple go评论85阅读模式
英文:

Chrome browser fails to launch in Appium using Java

问题

请有人帮助我解决这个问题。提前谢谢。
在运行打开模拟器中的 Chrome 浏览器的 Java 代码时,我收到了以下错误消息:"无法启动 Chromedriver 会话:无法创建新会话。详细信息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 83"。

public class ChromeBrowserLaunch {
    AppiumDriver driver;
    public static void main(String[] args) throws MalformedURLException {	
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel");
        cap.setCapability(MobileCapabilityType.VERSION, "8.0");
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
        cap.setCapability("chromedriverExecutable", "D:\\chromedriver\\chromedriver\\chromedriver.exe");
        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);	
        driver.get("http://facebook.com");
        driver.findElementByXPath("//*[@id=\"m_login_email\"]").sendKeys("geeta");
        driver.findElementByXPath("//*[@id=\"m_login_password\"]").sendKeys("geeta");
        driver.hideKeyboard();
        driver.findElement(By.id("signup-button")).click();
    }
}

异常线程 "main"
org.openqa.selenium.SessionNotCreatedException: 无法创建新的远程会话。请检查服务器日志以获取更多详细信息。原始错误:处理该命令时发生未知的服务器端错误。原始错误:无法创建新会话。详细信息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 83
构建信息:版本:'3.141.59',修订版:'e82be7d358',时间:'2018-11-14T08:17:03'
系统信息:主机:'DESKTOP-R5U0RRK',IP:'192.168.0.106',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',
java.version:'1.8.0_231'
驱动程序信息:driver.version:AndroidDriver
远程堆栈跟踪:UnknownError:处理该命令时发生未知的服务器端错误。原始错误:无法创建新会话。详细信息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 83
在 getResponseForW3CError (C:\Users\admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
在 asyncHandler (C:\Users\admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37)
在 process._tickCallback (internal/process/next_tick.js:68:7)
构建信息:版本:'3.141.59',修订版:'e82be7d358',时间:'2018-11-14T08:17:03'
系统信息:主机:'DESKTOP-R5U0RRK',IP:'192.168.0.106',os.name:'Windows 10',os.arch:'amd64',os.version:'10.0',
java.version:'1.8.0_231'


<details>
<summary>英文:</summary>

someone please help me to resolve this issue. Thanks in advance.
While running java code to open chrome browser in Emulator, I am getting &quot;Failed to start Chromedriver session: A new session could not be created. Details: session not created: This version of ChromeDriver only supports Chrome version 83&quot; error message.
    
    public class ChromeBrowserLaunch {
    	AppiumDriver driver;
    	public static void main(String[] args) throws MalformedURLException {	
    		DesiredCapabilities cap = new DesiredCapabilities();
    		cap.setCapability(MobileCapabilityType.DEVICE_NAME, &quot;Pixel&quot;);
    		cap.setCapability(MobileCapabilityType.VERSION, &quot;8.0&quot;);
    		cap.setCapability(MobileCapabilityType.PLATFORM_NAME, &quot;Android&quot;);
    		cap.setCapability(MobileCapabilityType.BROWSER_NAME, &quot;Chrome&quot;);
    		cap.setCapability(&quot;chromedriverExecutable&quot;, &quot;D:\\chromedriver\\chromedriver\\chromedriver.exe&quot;);
    		driver = new AndroidDriver&lt;MobileElement&gt;(new URL(&quot;http://127.0.0.1:4723/wd/hub&quot;), cap);
    		driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);	
    		driver.get(&quot;http://facebook.com&quot;);
    		driver.findElementByXPath(&quot;//*[@id=\&quot;m_login_email\&quot;]&quot;).sendKeys(&quot;geeta&quot;);
    		driver.findElementByXPath(&quot;//*[@id=&#39;m_login_password&#39;]&quot;).sendKeys(&quot;geeta&quot;);
    		driver.hideKeyboard();
    		driver.findElement(By.id(&quot;signup-button&quot;)).click();
    	}
    }
    

&gt; Exception in thread &quot;main&quot;
&gt; org.openqa.selenium.SessionNotCreatedException: Unable to create a new
&gt; remote session. Please check the server log for more details. Original
&gt; error: An unknown server-side error occurred while processing the
&gt; command. Original error: A new session could not be created. Details:
&gt; session not created: This version of ChromeDriver only supports Chrome
&gt; version 83
&gt;     Build info: version: &#39;3.141.59&#39;, revision: &#39;e82be7d358&#39;, time: &#39;2018-11-14T08:17:03&#39;
&gt;     System info: host: &#39;DESKTOP-R5U0RRK&#39;, ip: &#39;192.168.0.106&#39;, os.name: &#39;Windows 10&#39;, os.arch: &#39;amd64&#39;, os.version: &#39;10.0&#39;,
&gt; java.version: &#39;1.8.0_231&#39;
&gt;     Driver info: driver.version: AndroidDriver
&gt;     remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: A new session
&gt; could not be created. Details: session not created: This version of
&gt; ChromeDriver only supports Chrome version 83
&gt;         at getResponseForW3CError (C:\Users\admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
&gt;         at asyncHandler (C:\Users\admin\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:388:37)
&gt;         at process._tickCallback (internal/process/next_tick.js:68:7)
&gt;     Build info: version: &#39;3.141.59&#39;, revision: &#39;e82be7d358&#39;, time: &#39;2018-11-14T08:17:03&#39;
&gt;     System info: host: &#39;DESKTOP-R5U0RRK&#39;, ip: &#39;192.168.0.106&#39;, os.name: &#39;Windows 10&#39;, os.arch: &#39;amd64&#39;, os.version: &#39;10.0&#39;,
&gt; java.version: &#39;1.8.0_231&#39;



</details>


# 答案1
**得分**: 1

Chrome浏览器在Android上的包名称为`com.android.chrome`,活动名称为`com.google.android.apps.chrome.Main`。

在Appium中,您无需像Selenium那样需要浏览器可执行文件来打开浏览器,只需在您的能力中添加**`.APP_PACKAGE`**和**`.APP_ACTIVITY`**,就像这样:
```java
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.chrome");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.google.android.apps.chrome.Main");

以下是导入部分:

import io.appium.java_client.remote.AndroidMobileCapabilityType;

从您的代码中删除这行:

cap.setCapability("chromedriverExecutable", "D:\\chromedriver\\chromedriver\\chromedriver.exe");

注意:确保设备上已安装Chrome浏览器。

参考:如何找到您的应用程序的appPackage和appActivity名称

英文:

Chrome browser on Android has the package name com.android.chrome and the name of the activity com.google.android.apps.chrome.Main

In Appium you don't need a browser executable to open a browser like Selenium, so just add .APP_PACKAGE and .APP_ACTIVITY in your capability, like this:

cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, &quot;com.android.chrome&quot;);
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, &quot;com.google.android.apps.chrome.Main&quot;);

Following import:

import io.appium.java_client.remote.AndroidMobileCapabilityType;

Remove this line from your code:

cap.setCapability(&quot;chromedriverExecutable&quot;, &quot;D:\\chromedriver\\chromedriver\\chromedriver.exe&quot;);

Note: Make sure the chrome browser is installed on the device.

Reference : How to find appPackage and appActivity name of your App

huangapple
  • 本文由 发表于 2020年5月29日 11:47:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/62078372.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定