英文:
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 "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" error message.
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();
}
}
> Exception in thread "main"
> org.openqa.selenium.SessionNotCreatedException: Unable to create a new
> remote session. Please check the server log for more details. Original
> error: An unknown server-side error occurred while processing the
> command. Original error: A new session could not be created. Details:
> session not created: This version of ChromeDriver only supports Chrome
> version 83
> Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
> System info: host: '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 info: driver.version: AndroidDriver
> remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: A new session
> could not be created. Details: session not created: This version of
> ChromeDriver only supports Chrome version 83
> 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)
> 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)
> at process._tickCallback (internal/process/next_tick.js:68:7)
> Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
> System info: host: '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>
# 答案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, "com.android.chrome");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.google.android.apps.chrome.Main");
Following import:
import io.appium.java_client.remote.AndroidMobileCapabilityType;
Remove this line from your code:
cap.setCapability("chromedriverExecutable", "D:\\chromedriver\\chromedriver\\chromedriver.exe");
Note: Make sure the chrome browser is installed on the device.
Reference : How to find appPackage and appActivity name of your App
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论