不一样类型的应用 | 区别 |
---|---|
native app | 纯原声app,Android用Java些,iOS用object c写 |
hybrid app | 套用原声应用的外壳,既有原生的UI页面,又经过内置web view组件(至关于内置浏览器),能够访问本地和远程的html文件,Native Hardware Access能够访问本地文件和经过js脚本或html调用本地的函数方法。 |
web app | 只靠浏览器访问使用 |
微信小程序 | 微信内层嵌入的组件 |
模拟器默认支持
真机须要打开app内开关css
//必须从您的应用启用web view调试。要启用web view调试,请在web view类上调用静态方法setWebContentsDebuggingEnabled。 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ WebView.setWebContentDebuggingEnabled(true) }
@Test public void testWebView1() throws InterruptedException{ System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName()); WebDriverWait wait = new WebDriverWait(driver,10); String jiaoyi = "//*[@text='交易']"; wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(jiaoyi))); for(int i=0;i<3;i++) { System.out.println("首页: " + driver.getContextHandles());//查看当前页面有几个上下文 Thread.sleep(2000); } driver.findElementByXPath(jiaoyi).click(); for(int i=0;i<3;i++){ System.out.println("交易: "+driver.getContextHandles()); Thread.sleep(2000); } }
模拟器
使用真机,不会打印web view
html
@Test public void testWebview3() throws InterruptedException{ System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName()); WebDriverWait wait = new WebDriverWait(driver,10); WebElement el = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.TextView[@text=\"App\"]"))); WebElement list = driver.findElement(By.id("android:id/list")); MobileElement webview1 = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+"new UiSelector().text(\"Views\"));")); driver.findElementByXPath("//android.widget.TextView[@text=\"Views\"]").click(); MobileElement webview = list.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("+"new UiSelector().text(\"WebView\"));")); driver.findElementByXPath("//android.widget.TextView[@text=\"WebView\"]").click(); for(int i=0;i<5;i++){ System.out.println(driver.getContextHandles()); Thread.sleep(2000); } }
使用模拟器:
java
使用真机
python
public void testWebview2(){ System.out.println(Thread.currentThread().getStackTrace()[1].getMethodName()); WebDriverWait wait = new WebDriverWait(driver,10); String jiaoyi = "//*[@text='交易']"; wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(jiaoyi))); driver.findElementByXPath(jiaoyi).click(); System.out.println("Native page source:\n"+driver.getPageSource()); driver.context("WEBVIEW_com.xueqiu.android"); System.out.println("webview page source:\n"+driver.getPageSource()); }
native为xml
webview是html
android
#代码有错误 # 切换到web view webview = driver.contexts.last driver.switch_to.context(webview) #点击页面中class为green_button的控件 driver.find_element(:css,".green_button").click #切回原生页面 driver.switch_to.context(driver.contexts.first) driver.quit()
关于web view测试的内容等待补充git
io.appium.java_client.NoSuchContextExcetpion: An unknown server-side error occurred while processing the command. Original error: Failed to start Chromedriver session: A new session could not be created. (Original error:session not created exception:Chrome version must be >= 64.0.3282.0
(Driver info:chromedriver=2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85), platform=Mac OS X 10.13.3 X86-64))
当前Chromedriver版本为2.37对应Chrome版本64. Chrome版本低于64,session建立失败。在github中appium下搜索Chrome version,找到chromedriver.md文件,查看Chrome和driver对应关系
3.1 查看Chrome版本
方法1:开发者模式-WebView实现-查看Chrome版本
方法2:使用命令github
adb -s 406e8f3 shell pm list packages|grep webview adb -s 406e8f3 shell dumpsys package com.google.android.webview|grep versionName
webview版本为62.0,下载对应的2.35版本的driver便可。web
appium -g /tmp/csj527.log --session-override --chromedriver-executable /users/csj/Downloads/chromedriver.2.35/chromedriver