尝试使用appium
打开Android浏览器。我正在使用genymotion
用于Android设备模拟器并编写以下代码..
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName","Android Emulator");
capabilities.setCapability("browserName", "Browser");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("Android", true);
Driver_ST = new RemoteWebDriver(new URL("http://URL:4723/wd/hub"), capabilities);
代码执行后如果我看到appium
出现以下错误:
>info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"\/data","status":0}
> info: [debug] dataDir set to: /data
> info: [debug] Creating Chrome session
> info: [debug] Set chromedriver binary as: D:\android\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> info: [debug] Ensuring Chromedriver exists
> info: [debug] Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %b))
> info: [debug] No old chromedrivers seemed to exist
> info: [debug] Spawning chromedriver with: D:\android\Appium\node_modules\appium\build\chromedriver\windows\chromedriver.exe
> info: [debug] [CHROMEDRIVER] Starting ChromeDriver (v2.10.267521) on port 9515
> Only local connections are allowed.
> info: [debug] Making http request with opts:
{"sessionId":null,"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.browser","androidActivity":"com.android.browser.BrowserActivity","androidDeviceSerial"}}}}
> error: Chromedriver create session did not work. Status was 200 and body was {"sessionId":"b6aa64e8f25541d3513243792337a1e7","status":13,"value":{"message":"unknown error: Chrome version must be >= 33.0.1750.0\n (Driver info: chromedriver=2.10.267521,platform=Windows NT 6.3 x86_64)"}}
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: Did not get session redirect from Chromedriver
> info: [debug] Error: Did not get session redirect from Chromedriver
> at null.<anonymous> (D:\android\Appium\node_modules\appium\lib\devices\android\chromedriver.js:222:12)
> at Request._callback (D:\android\Appium\node_modules\appium\lib\devices\common.js:121:5)
> at Request.self.callback (D:\android\Appium\node_modules\appium\node_modules\request\request.js:121:22)
> at Request.EventEmitter.emit (events.js:98:17)
> at Request.<anonymous> (D:\android\Appium\node_modules\appium\node_modules\request\request.js:985:14)
> at Request.EventEmitter.emit (events.js:117:20)
> at IncomingMessage.<anonymous> (D:\android\Appium\node_modules\appium\node_modules\request\request.js:936:12)
> at IncomingMessage.EventEmitter.emit (events.js:117:20)
> at _stream_readable.js:920:16
> at process._tickDomainCallback (node.js:459:13)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Did not get session redirect from Chromedriver)","origValue":"Did not get session redirect from Chromedriver"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 28735.979 ms - 214
那么为什么它会给我一个错误,即虽然我正在尝试打开Android浏览器,但chromedriver
的会话无法创建。
请帮忙。我缺少任何能力或任何需要安装的驱动程序。
答案 0 :(得分:1)
我正在使用此代码示例。该工作正常。请尝试打开(自动化名称:Selendroid)
@Before
public void setUp() throws Exception {
PropertyConfigurator.configure("log4j.properties");
// set up appium
File app = new File(SignUpElement.apkFilePath);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(GeneralElement.device, GeneralElement.deviceType);
capabilities.setCapability(GeneralElement.emulator, GeneralElement.emulatorType);
capabilities.setCapability(GeneralElement.platformVer, GeneralElement.platformVerType);
capabilities.setCapability(GeneralElement.platformName, GeneralElement.platformNameType);
capabilities.setCapability("appPackage", "");
capabilities.setCapability("appActivity", "");
capabilities.setCapability("app", app.getAbsolutePath());
try {
WebElementFactory.driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
答案 1 :(得分:0)
使用捆绑的Chromedriver服务器作为代理实现自动化。使用4.2和4.3时,自动化仅适用于官方Chrome浏览器或Chromium。 4.4+以上的自动化也适用于内置的“浏览器”应用程序。 Chrome / Chromium /浏览器必须已安装在被测设备上。
答案 2 :(得分:0)
Stock Browser is not working
你应该等到它被修复。
但是,在模拟器上启动它应该没有问题。 你能试试吗?
Chrome适用于真实设备。
It's not possible暂时将其安装在Android模拟器上。
有一个关于Android模拟器的警告。在 目前,无法在Android模拟器上安装Chrome
答案 3 :(得分:0)
我将功能app
设置为Browser
,它对我有用 -
capabilities.setCapability("app", "Browser");
即使我提供了错误的设备名称或版本,appium仍会发现附加的模拟器并在其上启动浏览器。我的整套功能看起来都是 -
capabilities.setCapability("BROWSER_NAME", "Android");
capabilities.setCapability("app", "Browser");
capabilities.setCapability("VERSION", "XXX");
capabilities.setCapability("deviceName", "XXX");
capabilities.setCapability("platformName", "Android");
driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.get("http://www.google.com/");