原文地址:https://github.com/appium/java-client/blob/master/docs/The-event_firing.md

since 4.1.0

The purpose

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.//这个功能是用来组织客户端事件日志,便于分析测试细节和撰写测试报告。

The API

The API was designed the way which allows end user to select events (searching, navigation, exception throwing etc.) which should be listened to. It contains the following list of interfaces (new items may be added further)://有如下API。

  • io.appium.java_client.events.api.Listener is the basic interface
  • io.appium.java_client.events.api.general.AlertEventListener is for the listening to alerts
  • io.appium.java_client.events.api.general.ElementEventListener is for the listening to actions related to elements
  • io.appium.java_client.events.api.general.JavaScriptEventListener is for the listening to java script executing
  • io.appium.java_client.events.api.general.ListensToException is for the listening to exceptions which are thrown
  • io.appium.java_client.events.api.general.NavigationEventListener is for the listening to events related to navigation
  • io.appium.java_client.events.api.general.SearchingEventListener is for the listening to events related to the searching.
  • io.appium.java_client.events.api.general.WindowEventListener is for the listening to actions on a window
  • io.appium.java_client.events.api.mobile.ContextEventListener is for the listening to the switching to mobile context
  • io.appium.java_client.events.api.mobile.RotationEventListener is for the listening to screen rotation
  • io.appium.java_client.events.api.general.AppiumWebDriverEventListener was added to provide the compatibility with user's implementation of org.openqa.selenium.support.events.WebDriverEventListener. Also it extends some interfaces above.

Briefly about the engine.

This is pretty similar solution as the org.openqa.selenium.support.events.EventFiringWebDriver of the Selenium project. You can read about this thing there The blog post.//这个功能来源于selenium,但克服了selenium中每次只能监听一个事件的缺点。

Here we were trying to improve existing drawbacks and restrictions using:

How to use

It is easy.//使用方法:将driver和被监听的事件传入EventFiringWebDriverFactory。

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);

What if there are listeners which used everywhere by default.

In order to avoid the repeating actions an end user is free to do these things://高级用法:将监听事件作为一种自动启动的服务,不必显式地监听。这种用法来源于java自身的SPI。

  • create folders /META-INF/services and put the file io.appium.java_client.events.api.Listener there. Please read aboutSPI.//创建/META-INF/services文件夹,把一个文件放到其中。

  • define the list of default listeners at the io.appium.java_client.events.api.Listener//在文件中定义默认的被监听的事件。

And then it is enough//使用监听事件。

//and so on
...
import io.appium.java_client.events.EventFiringWebDriverFactory;
... AndroidDriver driver = new AndroidDriver(parameters);
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver);

If there are listeners defined externally when this collection is merged with default set of listeners.

How to reuse customized WebDriverEventListener

If an end user has their own org.openqa.selenium.support.events.WebDriverEventListener implementation then in order to make it compatible with this engine it is enough to do the following.//高级用法:扩展被监听的事件。

import org.openqa.selenium.support.events.WebDriverEventListener;
import io.appium.java_client.events.api.general.AppiumWebDriverEventListener; public class UsersWebDriverEventListener implements WebDriverEventListener, AppiumWebDriverEventListener {
...
}

or just

import io.appium.java_client.events.api.general.AppiumWebDriverEventListener;

public class UsersWebDriverEventListener implements AppiumWebDriverEventListener {
...
}

appium()-The event firing的更多相关文章

  1. Programmatically Disable Event Firing on List Item Update in SharePoint 2010

    1. Microsoft.SharePoint.dll Create EventFiring.cs 1.Right-click on the project, select Add and click ...

  2. appium()-java-client-api

    //appium java-client-api 介绍 原文地址:http://appium.github.io/java-client/index-all.html#_S_ A B C D E F  ...

  3. appium(11)-java-client

    Welcome to the Appium Java client wiki! This framework is an extension of the Selenium Java client. ...

  4. AngularJS 系列 01 - HelloWorld和数据绑定

    目录导读: AngularJS 系列 学习笔记 目录篇 前言: 好记性不如烂键盘,随笔就是随手笔记,希望以后有用. 本篇目录: 1. Hello World 2. AngularJS中的数据绑定 3. ...

  5. seajs源码分析

    seajs主要做了2件事 1.定义什么是模块,如何声明模块:id.deps.factory.exports ----define=function(id,deps,factory){return ex ...

  6. 自己修改的两个js文件

    sea-base.js /** * Sea.js 2.2.3 | seajs.org/LICENSE.md */ (function(global, undefined) { // Avoid con ...

  7. HelloWorld和数据绑定

    HelloWorld和数据绑定 目录导读: AngularJS 系列 学习笔记 目录篇 前言: 好记性不如烂键盘,随笔就是随手笔记,希望以后有用. 本篇目录: 1. Hello World 2. An ...

  8. seajs源码

    /*** Sea.js 3.0.0 | seajs.org/LICENSE.md 中文注释由 李祥威 添加,为个人对细节的理解,官方解释很详细的地方就不说了 难免有错漏,联系我: chuangweil ...

  9. 5 Protocols For Event-Driven API Architectures

    The internet is a system of communication, and as such, the relationship between client and server, ...

随机推荐

  1. django中表变更后migrate无效的问题

    问题描述: 已有的model,修改之后,想重新建模,于是将migrations文件夹中除__init__.py之外其他文件都删掉,再次执行以下步骤python manage.py makemigrat ...

  2. Codeforces Gym 100733I The Cool Monkeys 拆点+最大流

    原题链接:http://codeforces.com/gym/100733/problem/I 题意 有两颗树(只是树,不是数据结构),每棵树上有不同高度的树枝,然后有m只猴子在某棵树的前m高的树枝上 ...

  3. spring mvc表单的展现、输入处理、校验的实现

    之前已经实现了spring mvc的入门例子及如何处理带参数的请求Controller编写.本文主要记录: 1)重定向请求 2)处理路径中含有变量的请求 3)使用JSR-303进行校验 ① 首先,编写 ...

  4. springboot使用Mybatis(xml和注解)全解析

    ​  刚毕业的第一份工作是 java 开发,项目中需要用到 mybatis,特此记录学习过程,这只是一个简单 demo,mybatis 用法很多不可能全部写出来,有更复杂的需求建议查看 mybatis ...

  5. XSY1659 [HNOI2012]永无乡

    题面 Description 永无乡包含 n 座岛,编号从 1 到 n. 每座岛都有自己的独一无二的重要度,按照重要度可以将这n座岛排名,名次用 1到n来表示.某些岛之间由巨大的桥连接,通过桥可以从一 ...

  6. mybatis表名反射实体

    package com.eshore.wbtimer.executor.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapp ...

  7. MySQL高可用之——keepalived+互为主从

    目标:配置一个keepalived双机热备架构,并配置主从复制 规划: master1     zlm177     192.168.17.177 master2     zlm188     192 ...

  8. mysql生产环境____主从同步修复案例

    一.   硬件环境 Master: Dell R720 Intel(R)Xeon(R) CPU E5-2640 v2 @ 2.00GHz MEM 64G.disk 4*2.5 SAS  网络4* 千兆 ...

  9. php自定义错误

    function myErrorHandler ( $errno , $errstr , $errfile , $errline ) { if (!( error_reporting () & ...

  10. 【每日Scrum】第三天(4.13) TD学生助手Sprint1站立会议

    TD学生助手Sprint1站立会议(4.13) 任务看板 站立会议内容 组员 昨天 今天 困难 签到 刘铸辉 (组长) 昨天完成了课程的增删改查功能 今天早晨静姐调整了下界面和配色,下午和宝月兄一起做 ...