开发爱好者

还未发布过话题
  • @limit 问题处理好了不? 帮看看是什么问题, 谢谢。

    开发环境:
    windows10 + appium-desktop1.5.0 + 小米 5plus(android7.0) + chromedriver=2.26

    源码:

    public static void main(String[] args) throws InterruptedException, MalformedURLException {
    // TODO Auto-generated method stub

    AndroidDriver driver = null;

    //设置 apk 的路径
    File clasPathRoot = new File(System.getProperty("user.dir"));
    File appDir = new File(clasPathRoot, "apps");
    File app = new File(appDir, "weixin_1300.apk");// app 安装包

    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("platformVersion", "7.0");
    capabilities.setCapability("deviceName", "3bf6f87e");//真机
    capabilities.setCapability("platformName", "Android");

    capabilities.setCapability("appPackage", "com.tencent.mm");
    capabilities.setCapability("appActivity", "com.tencent.mm.ui.LauncherUI");

    capabilities.setCapability("noReset", true);// 不重装 app
    capabilities.setCapability("noSign", true);// 不进行重签名

    capabilities.setCapability("sessionOverride", true);
    // 权限
    capabilities.setCapability("autoGrantPermissions", true);

    // 设置 apk 路径
    capabilities.setCapability("app", app.getAbsolutePath());

    //加入微信 webwiew 调试能力. ===== 加下面这几句就出错了。
    ChromeOptions options2 = new ChromeOptions();
    options2.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    capabilities.setCapability(ChromeOptions.CAPABILITY, options2);

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    }

    报错如下:

    Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. (Original error: unknown error: Failed to clear data for com.android.chrome on device 3bf6f87e: Error: java.lang.SecurityException: PID 19864 does not have permission android.permission.CLEAR_APP_USER_DATA to clear data of package com.android.chrome

    (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.15063 x86_64)) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 47.67 seconds
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
    System info: host: 'JIANGNENGTING', ip: '192.168.18.254', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
    Driver info: driver.version: AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:132)
    at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:79)
    at com.jnt.csair.weixin.H5Weixin.main(H5Weixin.java:59)

  • 原码如下: 有知道的兄弟们不.

    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    import org.apache.log4j.Logger;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.DesiredCapabilities;

    import io.appium.java_client.android.AndroidDriver;

    public class H5Weixin {

    private static Logger logger = Logger.getLogger(H5Weixin.class);

    public static void main(String[] args) throws InterruptedException, MalformedURLException {
    // TODO Auto-generated method stub
    AndroidDriver driver = null;
    DesiredCapabilities capability = null;

    capability = new DesiredCapabilities();
    capability.setCapability("app", "");
    capability.setCapability("appPackage", "com.tencent.mm");
    capability.setCapability("appActivity", ".ui.LauncherUI");
    capability.setCapability("deviceName", "3bf6f87e");
    capability.setCapability("fastReset", "false");
    capability.setCapability("fullReset", "false");
    capability.setCapability("noReset", "true");
    // capability.setCapability("unicodeKeyboard", "True");
    // capability.setCapability("resetKeyboard", "True");

    // 关键是加上这段
    ChromeOptions options2 = new ChromeOptions();
    options2.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
    capability.setCapability(ChromeOptions.CAPABILITY, options2);

    // 启动微信浏览器
    logger.info("启动微信浏览器");

    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capability);

    // driver.manage().timeouts().implicitlyWait(500, TimeUnit.MILLISECONDS);
    // Thread.sleep(5000);
    //
    // logger.info("点击微信搜索菜单");
    // WebElement webElement = driver.findElement(By.xpath("//[@content-desc='搜索']"));
    // webElement.click();
    // logger.info("输入文件字符串");
    // webElement = driver.findElement(By.xpath("//
    [@text='搜索']"));
    // webElement.click();
    // webElement.clear();
    // webElement.sendKeys("文件");
    // Thread.sleep(5000);
    // logger.info("点击文件传输助手");
    // webElement = driver.findElement(By.xpath("//*[@text='文件传输助手']"));
    // webElement.click();
    // Thread.sleep(5000);
    // logger.info("发送跳转网站的网页 URL");

    // webElement = driver.findElement(By.xpath("//[@resource-id='com.tencent.mm:id/z4']"));// 不同微信版本,定位不一样
    // webElement.sendKeys("http://192.168.1.103:8080/openurl/open.html");
    // logger.info("点击发送按钮");
    // webElement = driver.findElement(By.xpath("//
    [@text='发送']"));
    // webElement.click();
    // Thread.sleep(5000);
    // logger.info("点击网址");
    // webElement = driver.findElement(By.xpath("//*[@text='" + "http://192.168.1.103:8080/openurl/open.html" + "']"));
    // webElement.click();
    // Thread.sleep(5000);
    // logger.info("切换到微信 webView");

    // Webdriver 转 AndroidDriver
    AndroidDriver androidDriver = (AndroidDriver) driver;
    androidDriver.context("WEBVIEW_com.tencent.mm:tools");
    driver = androidDriver;

    }

    }

  • 楼主我用你微信那块代码运行报如下错,不知道什么原因。chromedriver 版本换了 chromedriver=2.26, chromedriver=2.33,chromedriver=2.38 都不行

    [INFO ] 2018-04-19 11:48:52,751 method:com.jnt.csair.weixin.H5Weixin.main(H5Weixin.java:41)
    启动微信浏览器
    Exception in thread "main" org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: An unknown server-side error occurred while processing the command. (Original error: unknown error: known package com.android.chrome does not accept activity/process
    (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.15063 x86_64)) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 23.01 seconds
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:15.31Z'
    System info: host: 'JIANGNENGTING', ip: '192.168.18.254', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_131'
    Driver info: driver.version: AndroidDriver
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
    at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
    at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
    at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
    at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
    at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
    at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
    at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:73)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:209)
    at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:132)
    at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94)
    at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:79)
    at com.jnt.csair.weixin.H5Weixin.main(H5Weixin.java:42)

开发爱好者