线下班第二期_appium on iOS_20180310

webview

adb shell pm list packages |grep webview
adb shell dumpsys package com.android.webview

adb shell cat /proc/net/unix | grep --text  _devtools_remote
adb forward tcp:12184 localabstract:webview_devtools_remote_4366

versionName=58.0.3029.125
https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md

    @Test
    public void testWebView2() throws InterruptedException, MalformedURLException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("deviceName", "demo");
        capabilities.setCapability("appPackage", "io.appium.android.apis");
        capabilities.setCapability("appActivity", ".ApiDemos");
        //capabilities.setCapability("automationName", "uiautomator2");
        capabilities.setCapability("showChromedriverLog", true);
        //capabilities.setCapability("dontStopAppOnReset", true);


        AndroidDriver<AndroidElement> driver=new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.findElementByAccessibilityId("Views").click();
        MobileElement webview = driver.findElement(By.id("android:id/list"))
                .findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
                        + "new UiSelector().text(\\"WebView\\"));"));
        webview.click();
        System.out.println(driver.getContextHandles());

        for(AndroidElement e : driver.findElementsByXPath("//*")){
            System.out.println(e.getTagName());
            System.out.println(e.getText());
        }

        driver.context(driver.getContextHandles().toArray()[1].toString());


        for(AndroidElement e : driver.findElementsByXPath("//*")){
            System.out.println(e.getTagName());
            System.out.println(e.getText());
        }

        Thread.sleep(10000);




    }

iOS

演练app: https://github.com/appium/ios-uicatalog

依赖工具包安装:
brew install ideviceinstaller
brew install libimobiledevice
查看模拟器列表:instruments -s devices
查看真机列表:idevice_id -l
安装app: ideviceinstaller -i demo.app
命令行编译:
xcodebuild -scheme UICatalog -target iOS clean build
xcodebuild -scheme UICatalog -target iOS archive


WebDriverAgent

git clone https://github.com/facebook/WebDriverAgent.git
cd WebDriverAgent
#不要加-d参数,那个只是放入后台不利于检查
./Scripts/bootstrap.sh
#启动
xcodebuild -project WebDriverAgent.xcodeproj \\
           -scheme WebDriverAgentRunner \\
           -destination 'platform=iOS Simulator,name=iPhone 6' \\
           test
#对于已经独立启动的webdriveragent,使用这个参数告诉appium,不让appum再启动wda
  capabilities.setCapability("webDriverAgentUrl", WDAServer.SERVER_URL);

参考连接:
https://github.com/facebook/WebDriverAgent
https://github.com/appium/appium/blob/master/docs/en/advanced-concepts/wda-custom-server.md

演练源代码参考

https://github.com/seveniruby/hogwarts_offline_2