我正在尝试在Android设备上自动化Android Chrome浏览器(不只是webview或其他浏览器,而是Chrome浏览器)。我认为这可以通过以下链接https://sites.google.com/a/chromium.org/chromedriver/getting-started/getting-started---android实现,但它会自动化我的PC浏览器浏览器。
我也尝试过Appium,但日志后没有任何反应:
debug: executing: adb install C:\Users\hidden\Downloads\AppiumForWindows-0.14.2\
Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk
当我尝试从浏览器访问信息时,我明白了:
info: Responding to client with error: {"status":13,"value":{"message":"An unkno
wn server-side error occurred while processing the command.","origValue":"Did no
t successfully proxy server command"},"sessionId":"666c9e4f-7653-487a-b299-959d4
000ca79"}
我的环境变量PATH中有chromedriver.exe,整个日志如下所示:
info: Welcome to Appium v0.14.2
info: Appium REST http interface listener started on 127.0.0.1:5555
info - socket.io started
debug: Appium request initiated at /wd/hub/session
debug: Request received with params: {"desiredCapabilities":{"platform":"ANDROID
","app":"chrome","browserName":"android","browserConnectionEnabled":true,"app-pa
ckage":"com.android.chrome","device":"android","rotatable":true,"app-activity":"
com.google.android.apps.chrome.Main","takesScreenshot":true,"version":""}}
info: Looks like we want chrome on android
info: Creating new appium session 666c9e4f-7653-487a-b299-959d4000ca79
info: Ensuring Chromedriver exists
debug: Pushing unlock helper app to device...
debug: executing: adb install C:\Users\hidden\Downloads\AppiumForWindows-0.14.2\
Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk
warn: killed=false, code=1, signal=null
debug: Appium request initiated at /wd/hub/status
debug: Request received with params: {}
debug: Proxying command to 127.0.0.1:9515
info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/status
","method":"GET"}
info: Responding to client with error: {"status":13,"value":{"message":"An unkno
wn server-side error occurred while processing the command.","origValue":"Did no
t successfully proxy server command"},"sessionId":"666c9e4f-7653-487a-b299-959d4
000ca79"}
GET /wd/hub/status 500 1014ms - 238b
POST /wd/hub/session 200 31311ms
谢谢。
答案 0 :(得分:9)
debug:执行:adb install C:\ Users \ hidden \ Downloads \ AppiumForWindows-0.14.2 \ Appium \ node_modules \ appium \建立\ unlock_apk \ unlock_apk-debug.apk
如果此处没有发生任何事情,那么您必须重新启动ARM仿真器和appium服务器/ chromedriver。我多次遇到这种情况,并注意到很多次adb关闭并失去连接。如果我重新启动abd,一切都会开始工作。这只是一个安装apk的adb命令,它应该花费时间取决于apk的大小但不多。
public static void main(String[] args) throws MalformedURLException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device","Android");
capabilities.setCapability("app", "Chrome");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability(CapabilityType.VERSION, "4.3");
capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.get("http://www.yahoo.com");
}
我有这段代码在appium自动化android chrome浏览器上运行良好。在上面的日志中,您的chromedriver未成功启动,因此浏览器未自动化。我有appium日志,它自动化Chrome浏览器: 此外,ChromeDriver和Chrome APK的每个组合都无效。自从几天以来我一直在努力奋斗,并发现: Chrome驱动程序2.3和Chrome APK 29.xxx兼容。 Chrome驱动程序2.9 / 2.8和Chrome APK 30.xx或31.xx无效。
关于Just ChromeDriver: 如果您没有设置功能,您提到的铬链接将自动化PC浏览器。像这样:
DesiredCapabilities capabilities=new DesiredCapabilities();//DesiredCapabilities.chrome();
ChromeOptions options=new ChromeOptions();
options.setExperimentalOptions("androidPackage", "com.android.chrome");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
你必须设置这个功能,因为你只是使用chromedriver(而不是appium)。 我正在研究这个但是找不到这个能力。 此外,你必须自己在命令promt上启动ChromDriver,它将在9515端口监听任何自动化。
答案 1 :(得分:1)
1)阅读appium日志,看看它引用的是哪个版本的chrome驱动程序。 2)在线查看最新的chromedriver版本。 截至今日最新版本为2.23。下载这个为WindowsAnd提取它 http://chromedriver.storage.googleapis.com/index.html?path=2.23/ 3)升级Appium(今日最新 - 1.4.16.1) 现在转到这个位置, C:\ Program Files(x86)\ Appium \ node_modules \ appium \ node_modules \ appium-chromedriver \ chromedriver \ win
将chromedriver.exe粘贴到此处(替换旧版本)
4)
public AndroidDriver<AndroidElement> startChrome() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "AndroidDevice");
capabilities.setCapability("newCommandTimeout", 180);
capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");
try {
driver = new AndroidDriver<>(new URL(appiumURL), capabilities);
driver.get("google.com")
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} return driver;
}
5)如果这不起作用,请确保签入appium日志,如果它指向更新的chrome版本
答案 2 :(得分:0)
首先检查您的移动设备是否已连接Chrome浏览器。 在Web浏览器URL上键入以下命令
chrome://inspect/devices#devices
这将显示已连接的设备列表。
然后设置所需的功能。
下面是为我工作的代码:
public void setUp() {
File app = new File("./TestingAPK/app-release-v3.1.0-c20170201.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capabilities.setCapability("deviceName", "emulator-5554");
capabilities.setCapability("unicodekeyboard", true);
capabilities.setCapability("resetkeyboard", true);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "21");
capabilities.setCapability("appPackage", "app.mangalam.billboy");
capabilities.setCapability("appActivity", "app.mangalam.billboy.main.SplashActivity");
capabilities.setCapability("app", app.getAbsolutePath());
try {
driver = new AndroidDriver < > (new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
}
答案 3 :(得分:0)
我以这种方式进行设置,并且运行良好。
String appium_node = ("http://0.0.0.0:4723/wd/hub");
//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Mi Android Phone");
caps.setCapability("udid", "ba689af30404"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "8.1.0");
caps.setCapability("browserName", "Chrome");
caps.setCapability("noReset", true);
caps.setCapability("unicodekeyboard", true);
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
try {
driver = new AndroidDriver < > (new URL(appium_node), caps);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
}
答案 4 :(得分:0)
这使我在最新的Appium 1.10中启动了chrome浏览器
package com.prac.com;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.android.AndroidDriver;
public class Demo1LaunchChrome {
private static AndroidDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException{
// TODO Auto-generated method stub
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability("deviceName", "emulator demo1");
cap.setCapability("platformVersion", "8.0.0");
cap.setCapability("platformName", "Android");
System.setProperty("webdriver.chrome.driver", "C:\\Appium Jars\\chromedriver_win32\\chromedriver");
Thread.sleep(10000);
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);
Thread.sleep(10000);
driver.get("https://hobbyclues.in");
Thread.sleep(10000);
System.out.println("Done!");
driver.quit();
}
}
答案 5 :(得分:-1)
以下几点需要添加:-
1)添加chromedriverExecutable功能,并提供chromeDriver.exe的路径
2)编写代码以将Native_App切换到WEBVIEW。
public static void applaunch() throws MalformedURLException, InterruptedException
{
DesiredCapabilities capabilites = new DesiredCapabilities();
capabilites.setCapability(MobileCapabilityType.DEVICE_NAME, "MyDevice");
capabilites.setCapability(MobileCapabilityType.UDID, "112udid12");
capabilites.setCapability(MobileCapabilityType.PLATFORM_NAME, "android");
capabilites.setCapability(MobileCapabilityType.PLATFORM_VERSION, "9");
capabilites.setCapability("chromedriverExecutable", "C:/path/Of/chromedriver.exe");
capabilites.setCapability(AndroidMobileCapabilityType.APP_PACKAGE ,"com.android.chrome");
capabilites.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY ,"com.google.android.apps.chrome.Main");
capabilites.setCapability("noReset", true);
AppiumDriver<MobileElement> driver= new AppiumDriver<MobileElement>(new URL("http://127.0.0.1:4725/wd/hub") ,capabilites);
driver.get("https://www.facebook.com/");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Thread.sleep(5000);
//We use Set<String> views to get all context values.
//And then navigate Native_APP to WEBVIEW_chrome.
Set<String> views = driver.getContextHandles();
for (String view :views)
{
System.out.println("View is :- "+view);
if(view.contains("WEBVIEW_chrome"))
{
driver.context(view);
break;
}
}
driver.findElement(By.xpath("userID")).sendKeys("UserOne@gmail.com");
driver.findElement(By.xpath("Password")).sendKeys("MyPassword");
driver.findElement(By.xpath("LoginBtn")).click();