博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Automating hybrid apps
阅读量:5310 次
发布时间:2019-06-14

本文共 3805 字,大约阅读时间需要 12 分钟。

Automating hybrid apps

One of the core principles of Appium is that you shouldn’t have to change your app to test it. In line with that methodology, it is possible to test hybrid web apps (e.g., the elements in an iOS app) the same way you can with Selenium for web apps. There is a bit of technical complexity required so that Appium knows whether you want to automate the native aspects of the app or the web views, but thankfully, we can stay within the WebDriver protocol for everything.

Here are the steps required to talk to a web view in your Appium test://测试混合应用的步骤

  1. Navigate to a portion of your app where a web view is active
  2. Call
  3. This returns a list of contexts we can access, like 'NATIVE_APP’ or 'WEBVIEW_1’
  4. Call with the id of the context you want to access
  5. (This puts your Appium session into a mode where all commands are interpreted as being intended for automating the web view, rather than the native portion of the app. For example, if you run getElementByTagName, it will operate on the DOM of the web view, rather than return UIAElements. Of course, certain WebDriver methods only make sense in one context or another, so in the wrong context you will receive an error message).
  6. To stop automating in the web view context and go back to automating the native portion of the app, simply call context again with the native context id to leave the web frame.
1 // java 2 // assuming we have a set of capabilities 3 driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); 4  5 Set
contextNames = driver.getContextHandles(); 6 for (String contextName : contextNames) { 7 System.out.println(contextNames); //prints out something like NATIVE_APP \n WEBVIEW_1 8 } 9 driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_110 11 //do some web testing12 String myText = driver.findElement(By.cssSelector(".green_button")).click();13 14 driver.context("NATIVE_APP");15 16 // do more native testing if we want17 18 driver.quit();
1 # python 2 # assuming we have an initialized `driver` object for an app 3  4 # switch to webview 5 webview = driver.contexts.last 6 driver.switch_to.context(webview) 7  8 # do some webby stuff 9 driver.find_element(:css, ".green_button").click10 11 # switch back to native view12 driver.switch_to.context(driver.contexts.first)13 14 # do more native testing if we want15 16 driver.quit()

 

Automating hybrid Android apps

Appium comes with built-in hybrid support via Chromedriver. Appium also uses Selendroid under the hood for webview support on devices older than 4.4. (In that case, you’ll want to specify "automationName": "selendroid" as a desired capability).//低于4.4的安卓版本,需要用Selendroid测试混合应用。其余的版本,通过内置的Chromedriver测试混合应用。

Make sure is set to true as described in the .//如果没法访问,就看。

Once you’ve set your desired capabilities and started an appium session, follow the generalized instructions above.

 

Automating hybrid iOS apps

To interact with a web view appium establishes a connection using a remote debugger. When executing against a simulator this connection is established directly as the simulator and the appium server are on the same machine.//同一个电脑上的iOS模拟器与appium server会直接建立连接。

Once you’ve set your desired capabilities and started an appium session, follow the generalized instructions above.

 

Execution against a real iOS device

When executing against a real iOS device appium is unable to access the web view directly. Therefore the connection has to be established through the USB lead. To establish this connection we use the .//iOS真机通过代理与appium server取得连接。

For instruction on how to install and run ios-webkit-debugger-proxy see documentation.

Now you can start an appium test session and follow the generalized instructions above.

转载于:https://www.cnblogs.com/superbaby11/p/6072501.html

你可能感兴趣的文章
判断9X9数组是否是数独的java代码
查看>>
00-自测1. 打印沙漏
查看>>
UNITY在VS中调试
查看>>
SDUTOJ3754_黑白棋(纯模拟)
查看>>
Scala入门(1)Linux下Scala(2.12.1)安装
查看>>
如何改善下面的代码 领导说了很耗资源
查看>>
Quartus II 中常见Warning 原因及解决方法
查看>>
php中的isset和empty的用法区别
查看>>
Android ViewPager 动画效果
查看>>
pip和easy_install使用方式
查看>>
博弈论
查看>>
Redis sentinel & cluster 原理分析
查看>>
我的工作习惯小结
查看>>
把word文档中的所有图片导出
查看>>
浏览器的判断;
查看>>
ubuntu 18.04取消自动锁屏以及设置键盘快捷锁屏
查看>>
Leetcode 589. N-ary Tree Preorder Traversal
查看>>
机器学习/深度学习/其他开发环境搭建记录
查看>>
xml.exist() 实例演示
查看>>
判断是否为空然后赋值
查看>>