appium 版本更新后的方法变化更新收集 ---持续更新
在高版本的android手机(例如android 7.0 , 8.0等等),必须使用高版本的appium, 以及对应的selenium版本,那么很多的appium或者selenium方法会变得无法直接调用,这里是一个汇总收集。
本文以io.appium.java-client 3.14.0版本为例,为2018年最新版本
最新引入了
PointOption
ElementOption
WaitOptions
KeyEvent
TouchAction
The-event firing (时间与元素监听)
AppiumFunction (新的等待元素的方法)
//老版本的操作线,从元素附近的某个点移动到元素中心,新版本不允许出现: press(element,x,y)的语法
// TouchAction action0 = (new TouchAction(driver)).press(el, center.getX(), center.getY() - yOffset).moveTo(el).release();
// TouchAction action1 = (new TouchAction(driver)).press(el, center.getX(), center.getY() + yOffset).moveTo(el).release(); TouchAction action0 = (new TouchAction(driver)).press(PointOption.point(center.getX(), center.getY() - yOffset)).moveTo(ElementOption.element(el)).release();
TouchAction action1 = (new TouchAction(driver)).press(PointOption.point(center.getX(), center.getY() + yOffset)).moveTo(ElementOption.element(el)).release();
action.press(PointOption.point(x, y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).perform();
KeyEvent key=new KeyEvent();
key.withKey(AndroidKey.KEYCODE_ZOOM_IN);
//driver.pressKeyCode(KEYCODE_ZOOM_IN);//老版操作: 放大键
JAVA-Client 在新版里面提供了如下(等待元素)方法:
//waiting for elements
private final AppiumFunction<WebDriver, List<WebElement>> searchingFunction = input -> {
List<WebElement> result = input.findElements(By.tagName("a")); if (result.size() > 0) {
return result;
}
return null;
}; //waiting for some context using regular expression pattern
private final AppiumFunction<Pattern, WebDriver> contextFunction = input -> {
Set<String> contexts = driver.getContextHandles();
String current = driver.getContext();
contexts.forEach(context -> {
Matcher m = input.matcher(context);
if (m.find()) {
driver.context(context);
}
});
if (!current.equals(driver.getContext())) {
return driver;
}
return null;
};
等待元素可以直接使用:
//using one function as pre-condition
@Test public void tezt() {
....
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
.withTimeout(30, TimeUnit.SECONDS);
List<WebElement> elements = wait.until(searchingFunction.compose(contextFunction));
....
}
//using one function as post-condition
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait; @Test public void tezt() {
....
Wait<Pattern> wait = new FluentWait<>(Pattern.compile("WEBVIEW"))
.withTimeout(30, TimeUnit.SECONDS);
List<WebElement> elements = wait.until(contextFunction.andThen(searchingFunction));
....
}
TouchAction
private final ActionSupplier<TouchAction> horizontalSwipe = () -> {
driver.findElementById("io.appium.android.apis:id/gallery");
AndroidElement gallery = driver.findElementById("io.appium.android.apis:id/gallery");
List<MobileElement> images = gallery
.findElementsByClassName("android.widget.ImageView");
Point location = gallery.getLocation();
Point center = gallery.getCenter();
return new TouchAction(driver).press(images.get(2), -10, center.y - location.y)
.waitAction(2000).moveTo(gallery, 10, center.y - location.y).release();
};
private final ActionSupplier<TouchAction> verticalSwiping = () ->
new TouchAction(driver).press(driver.findElementByAccessibilityId("Gallery"))
.waitAction(2000).moveTo(driver.findElementByAccessibilityId("Auto Complete")).release();
//水平与垂直的swipe
@Test public void tezt() {
...
horizontalSwipe.get().perform();
...
verticalSwiping.get().perform();
...
}
//普通的tap
import io.appium.java_client.TouchAction; ...
//tap
new TouchAction(driver)
.tap(driver
.findElementById("io.appium.android.apis:id/start")).perform();
...
//swipe
TouchAction swipe = new TouchAction(driver).press(images.get(2), -10, center.y - location.y)
.waitAction(2000).moveTo(gallery, 10, center.y - location.y).release();
swipe.perform();
...
//tap by few fingers
MultiTouchAction multiTouch = new MultiTouchAction(driver); for (int i = 0; i < fingers; i++) {
TouchAction tap = new TouchAction(driver);
multiTouch.add(tap.press(element).waitAction(duration).release());
} multiTouch.perform();
public class GestureUtils {
public static ActionSupplier<TouchAction> swipe(final AppiumDriver<?> driver, final params) {
return () -> {
new TouchAction(driver).press(params)
.waitAction(params).moveTo(params).release();
};
}
}
//可以直接使用如下方法进行swipe
public class SomeTest {
@Test public void tezt() {
...
GestureUtils.swipe(driver, params).get().perform();
...
}
}
Java-client 更新了The-event firing (新增了element/event的监听)
This feature allows end user to organize the event logging on the client side. Also this feature may be useful in a binding with standard or custom reporting frameworks.
import io.appium.java_client.events.api.general.AlertEventListener;
public class AlertListener implements AlertEventListener {
...
}
...
import io.appium.java_client.events.api.general.ElementEventListener;
public class ElementListener implements ElementEventListener {
...
}
//and so on
...
import io.appium.java_client.events.EventFiringWebDriverFactory;
import io.appium.java_client.events.api.Listener;
...
AndroidDriver driver = new AndroidDriver(parameters);
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver, new AlertListener(),
new ElementListener());
//or
AndroidDriver driver2 = new AndroidDriver(parameters);
List<Listener> listeners = new ArrayList<>();
listeners.add(new AlertListener());
listeners.add(new ElementListener());
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver2, listeners);
如何使用事件监听呢?
//and so on
...
import io.appium.java_client.events.EventFiringWebDriverFactory;
... AndroidDriver driver = new AndroidDriver(parameters);
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver);
如果你自己想封装的话,可以如下操作:
import org.openqa.selenium.support.events.WebDriverEventListener;
import io.appium.java_client.events.api.general.AppiumWebDriverEventListener; public class UsersWebDriverEventListener implements WebDriverEventListener, AppiumWebDriverEventListener {
...
}
//或者如下操作 import io.appium.java_client.events.api.general.AppiumWebDriverEventListener; public class UsersWebDriverEventListener implements AppiumWebDriverEventListener {
...
}
appium 版本更新后的方法变化更新收集 ---持续更新的更多相关文章
- 关于苹果macOS更新到Catalina后出现的各种问题(持续更新)
一.Mac系统更新后 Git 不能用,提示 missing xcrun at:xxx xcrun: error: invalid active developer path (/Library/Dev ...
- iPadOS 更新日志 - 持续更新中
本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iPadOS 13.1 - 2019年9月25日 经全新命名的 iPadOS 是一款强 ...
- iOS 更新日志 - 持续更新中
本文只是为了简单记录一下每个正式版本发布时间和更新内容,只有这个初衷,从2019年9月25日开始,将会持续更新. iOS 13.1 - 2019年9月25日 iOS 13.1 iOS 13.1 包括错 ...
- appium 测试过程中遇到的几个问题 ---持续更新!
一. appium自带的Chromedriver版本和设备Android System Webview版本不一致的问题 报错信息: io.appium.java_client.NoSuchContex ...
- 程序员使用IDEA这些插件后,办公效率提升100%(持续更新中)
IDEA一些不错的插件分享 目录 IDEA一些不错的插件分享 插件集合 CamelCase Translation LiveEdit MarkDown Navigator Jrebel CheckSt ...
- IIS发布站点错误收集(持续更新)
本文主要收集IIS在发布站点过程中遇到的错误,并提供解决办法.并亲测可行.如果您也在使用IIS发布站点的过程中遇到了一些问题,欢迎留言提问. (1.) HTTP错误500.21-Internal Se ...
- 2017.3.27 集成modeler后的一些主要路径(持续更新)
1.设计器访问路径 项目名:wfs_web edtor-app和modeler.html的存放位置:webapp/designer/editor-app app-cfg.js中根路径设置:'conte ...
- Java中时间方法大全01(持续更新)
下面这些方法都可以封装到一个工具类中 /** * 获取当前时间的时间戳 */ public static int getCurrentTimeIntValue() { return (int) (Sy ...
- 【mysql】 操作 收集持续更新
一个字段可能对应多条数据,用mysql实现将多行数据合并成一行数据 GROUP_CONCAT(Name SEPARATOR ',') 需注意: 1.GROUP_CONCAT()中的值为你要合并的数据的 ...
随机推荐
- IDEA注册码分享
IntelliJ IDEA IDEA 2018 激活注册码分享鼠标连续 三下左键点击 选中,再Ctrl+C 即可复制. CSDN在末尾会带上博客的说明,请删除后,复制到 IDEA中激活. 注册码激活: ...
- win10更新后出现System.ComponentModel.Win32Exception
win10更新后出现System.ComponentModel.Win32Exception 我的环境是由于“sql server2012 无法连接到WMI提供程序”引起的 参考http://www. ...
- Java中static、final、static final的区别(转)
说明:不一定准确,但是最快理解. final: final可以修饰:属性,方法,类,局部变量(方法中的变量) final修饰的属性的初始化可以在编译期,也可以在运行期,初始化后不能被改变. final ...
- How to setup Tensorflow inception-v3 model on Windows
There is Inception-v3 model python implementation on GitHub at: https://github.com/tensorflow/models ...
- Sublime Text 3安装Package Control
Package Control官网:https://packagecontrol.io/installation#st3 ctrl + ` 或者 View > Show Console呼出控制台 ...
- 排错技能:任务管理器中追踪某w3wp.exe是哪个IIS站点的application pool
如果Windows的任务管理器中发现某个w3wp.exe占用了100%CPU,那我们就要揪出这是那个网站的application pool在作怪, 首先,每个站点一定要单独使用各自的applicati ...
- TCP流量控制
TCP的流量控制,是为了更好的传输数据,控制流量不要发送太快而至于接收端没有足够的缓存的接收. 利用滑动窗口,可以很方便的控制传输 rwnd:可以控制接收窗口大小.ACK代表确认位,ack代表确认字段 ...
- selenium常用的模块
from selenium import webdriver #select模块处理下拉框from selenium.webdriver.support.ui import Select # Keys ...
- frist Django app — 一、 创建工程
缘起 既然python都学了,学习python的时候感觉是相见恨晚,一种新的编程语言带给我一种新的思考问题的方式,为了巩固学过的东西并进一步学习python,就想学学Django,看看会不会带给我关于 ...
- 必做作业3:短视频编辑app原型化系统
本app立足于打造短视频分享交流社区,app不仅有视频编辑的功能,还有视频的分享和收藏功能.系统有登录.注册.找回密码的功能,可以进行账号资料管理,并可以管理自己的视频.分享和收藏.系统可以对视频进行 ...