Skip to content

Commit ab46e03

Browse files
appium#242 fix: The new WIKI chapter
1 parent 1351cf2 commit ab46e03

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

docs/The-event_firing.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
since 4.1.0
2+
3+
# The purpose
4+
5+
This feature allows end user to organize the event logging on the client side. Also these feature may be useful in a binding with standard or custom reporting
6+
frameworks.
7+
8+
9+
# The API
10+
11+
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
12+
the following list of interfaces (new items may be added further):
13+
14+
- `io.appium.java_client.events.api.Listener` is the basic interface
15+
- `io.appium.java_client.events.api.general.AlertEventListener` is for the listening to alerts
16+
- `io.appium.java_client.events.api.general.ElementEventListener` is for the listening to actions related to elements
17+
- `io.appium.java_client.events.api.general.JavaScriptEventListener` is for the listening to java script executing
18+
- `io.appium.java_client.events.api.general.ListensToException` is for the listening to exceptions which are thrown
19+
- `io.appium.java_client.events.api.general.NavigationEventListener` is for the listening to events related to navigation
20+
- `io.appium.java_client.events.api.general.SearchingEventListener` is for the listening to events related to the searching.
21+
- `io.appium.java_client.events.api.general.WindowEventListener` is for the listening to actions on a window
22+
- `io.appium.java_client.events.api.mobile.ContextEventListener` is for the listening to the switching to mobile context
23+
- `io.appium.java_client.events.api.mobile.RotationEventListener` is for the listening to screen rotation
24+
- `io.appium.java_client.events.api.general.AppiumWebDriverEventListener` was added to provide the compatibility with
25+
user's implementation of `org.openqa.selenium.support.events.WebDriverEventListener`. Also it extends some interfaces above.
26+
27+
# Briefly about the engine.
28+
29+
This is pretty similar solution as the `org.openqa.selenium.support.events.EventFiringWebDriver` of the Selenium project. You
30+
can read about this thing there [The blog post](http://seleniumworks.blogspot.ru/2014/02/eventfiringwebdriver.html).
31+
32+
Here we were trying to improve existing drawbacks and restrictins using:
33+
34+
- API splitting, see above.
35+
36+
- the binding of some [Spring framework engines](https://projects.spring.io/spring-framework/) with [AspectJ](https://en.wikipedia.org/wiki/AspectJ).
37+
38+
# How to use
39+
40+
It is easy.
41+
42+
```java
43+
import io.appium.java_client.events.api.general.AlertEventListener;
44+
45+
public class AlertListener implements AlertEventListener {
46+
...
47+
}
48+
49+
...
50+
import io.appium.java_client.events.api.general.ElementEventListener;
51+
52+
public class ElementListener implements ElementEventListener {
53+
...
54+
}
55+
56+
//and so on
57+
...
58+
import io.appium.java_client.events.EventFiringWebDriverFactory;
59+
import io.appium.java_client.events.api.Listener;
60+
...
61+
62+
AndroidDriver driver = new AndroidDriver(parameters);
63+
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver, new AlertListener(),
64+
new ElementListener());
65+
66+
//or
67+
AndroidDriver driver2 = new AndroidDriver(parameters);
68+
List<Listener> listeners = new ArrayList<>();
69+
listeners.add(new AlertListener());
70+
listeners.add(new ElementListener());
71+
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver2, listeners);
72+
```
73+
74+
## What if there are listeners which uses everywhere by default.
75+
76+
In order to avoid the repeating actions an end user is free to do these things:
77+
78+
- create folders `/META-INF/services` and put the file `io.appium.java_client.events.api.Listener` there. Please read about
79+
[SPI](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html).
80+
81+
![image](https://cloud.githubusercontent.com/assets/4927589/16731325/24eab680-4780-11e6-8551-a3c72d4b9c38.png)
82+
83+
- define the list of default listeners at the `io.appium.java_client.events.api.Listener`
84+
85+
![image](https://cloud.githubusercontent.com/assets/4927589/16731509/2734a4e0-4781-11e6-81cb-ab64a5924c35.png)
86+
87+
And then it is enough
88+
89+
```java
90+
91+
//and so on
92+
...
93+
import io.appium.java_client.events.EventFiringWebDriverFactory;
94+
...
95+
96+
AndroidDriver driver = new AndroidDriver(parameters);
97+
driver = EventFiringWebDriverFactory.getEventFiringWebDriver(driver);
98+
```
99+
100+
If there are listeners defined externally when this collection is merged with default set of listeners.

0 commit comments

Comments
 (0)