Skip to content

Commit 35289a5

Browse files
#588 FIX
- update to Selenium 3.2.0 - excessive dependency on guava was removed - source code synchronization
1 parent 1e2c86e commit 35289a5

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ compileJava {
5454
}
5555

5656
dependencies {
57-
compile('org.seleniumhq.selenium:selenium-java:3.0.1'){
57+
compile('org.seleniumhq.selenium:selenium-java:3.2.0'){
5858
exclude module: 'cglib'
5959
exclude group: 'com.google.code.gson'
6060
}
6161
compile 'com.google.code.gson:gson:2.8.0'
6262
compile 'org.apache.httpcomponents:httpclient:4.5.2'
63-
compile 'com.google.guava:guava:20.0'
6463
compile 'cglib:cglib:3.2.4'
6564
compile 'commons-validator:commons-validator:1.5.1'
6665
compile 'org.apache.commons:commons-lang3:3.5'

src/main/java/io/appium/java_client/events/DefaultAspect.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public void afterScript(JoinPoint joinPoint) throws Throwable {
352352
public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable {
353353
try {
354354
listener.beforeAlertAccept(driver, castTarget(joinPoint));
355+
listener.beforeAlertAccept(driver);
355356
} catch (Throwable t) {
356357
throw getRootCause(t);
357358
}
@@ -361,6 +362,7 @@ public void beforeAlertAccept(JoinPoint joinPoint) throws Throwable {
361362
public void afterAlertAccept(JoinPoint joinPoint) throws Throwable {
362363
try {
363364
listener.afterAlertAccept(driver, castTarget(joinPoint));
365+
listener.afterAlertAccept(driver);
364366
} catch (Throwable t) {
365367
throw getRootCause(t);
366368
}
@@ -370,6 +372,7 @@ public void afterAlertAccept(JoinPoint joinPoint) throws Throwable {
370372
public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable {
371373
try {
372374
listener.beforeAlertDismiss(driver, castTarget(joinPoint));
375+
listener.beforeAlertDismiss(driver);
373376
} catch (Throwable t) {
374377
throw getRootCause(t);
375378
}
@@ -379,6 +382,7 @@ public void beforeAlertDismiss(JoinPoint joinPoint) throws Throwable {
379382
public void afterAlertDismiss(JoinPoint joinPoint) throws Throwable {
380383
try {
381384
listener.afterAlertDismiss(driver, castTarget(joinPoint));
385+
listener.afterAlertDismiss(driver);
382386
} catch (Throwable t) {
383387
throw getRootCause(t);
384388
}

src/main/java/io/appium/java_client/events/DefaultListener.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,38 @@ public void add(Collection<Listener> listeners) {
142142
((AlertEventListener) dispatcher).beforeAlertAccept(driver, alert);
143143
}
144144

145+
@Override
146+
public void beforeAlertAccept(WebDriver driver) {
147+
((WebDriverEventListener) dispatcher).beforeAlertAccept(driver);
148+
}
149+
145150
@Override public void afterAlertAccept(WebDriver driver, Alert alert) {
146151
((AlertEventListener) dispatcher).afterAlertAccept(driver, alert);
147152
}
148153

154+
@Override
155+
public void afterAlertAccept(WebDriver driver) {
156+
((WebDriverEventListener) dispatcher).afterAlertAccept(driver);
157+
}
158+
149159
@Override public void afterAlertDismiss(WebDriver driver, Alert alert) {
150160
((AlertEventListener) dispatcher).afterAlertDismiss(driver, alert);
151161
}
152162

163+
@Override
164+
public void afterAlertDismiss(WebDriver driver) {
165+
((WebDriverEventListener) dispatcher).afterAlertDismiss(driver);
166+
}
167+
153168
@Override public void beforeAlertDismiss(WebDriver driver, Alert alert) {
154169
((AlertEventListener) dispatcher).beforeAlertDismiss(driver, alert);
155170
}
156171

172+
@Override
173+
public void beforeAlertDismiss(WebDriver driver) {
174+
((WebDriverEventListener) dispatcher).beforeAlertDismiss(driver);
175+
}
176+
157177
@Override public void beforeAlertSendKeys(WebDriver driver, Alert alert, String keys) {
158178
((AlertEventListener) dispatcher).beforeAlertSendKeys(driver, alert, keys);
159179
}

src/test/java/io/appium/java_client/events/WebDriverEventListenerCompatibilityTest.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.appium.java_client.events;
22

33
import static org.hamcrest.core.Is.is;
4+
import static org.hamcrest.core.IsCollectionContaining.hasItems;
45
import static org.junit.Assert.assertThat;
56

67
import io.appium.java_client.events.listeners.AppiumListener;
@@ -9,6 +10,8 @@
910
import org.junit.FixMethodOrder;
1011
import org.junit.Test;
1112
import org.junit.runners.MethodSorters;
13+
import org.openqa.selenium.Alert;
14+
import org.openqa.selenium.security.Credentials;
1215

1316
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
1417
public class WebDriverEventListenerCompatibilityTest extends BaseListenerTest {
@@ -56,6 +59,51 @@ public void javaScriptEventTest() {
5659
is(true));
5760
}
5861

62+
@Test
63+
public void alertEventTest() {
64+
try {
65+
Alert alert = driver.switchTo().alert();
66+
alert.accept();
67+
alert.dismiss();
68+
alert.sendKeys("Keys");
69+
Credentials credentials = new Credentials() {
70+
@Override
71+
public int hashCode() {
72+
return super.hashCode();
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return "Test credentials 1";
78+
}
79+
};
80+
81+
Credentials credentials2 = new Credentials() {
82+
@Override
83+
public int hashCode() {
84+
return super.hashCode();
85+
}
86+
87+
@Override
88+
public String toString() {
89+
return "Test credentials 2";
90+
}
91+
};
92+
93+
alert.setCredentials(credentials);
94+
alert.authenticateUsing(credentials2);
95+
96+
assertThat(listener.messages,
97+
hasItems(WEBDRIVER_EVENT_LISTENER + "Attempt to accept alert",
98+
WEBDRIVER_EVENT_LISTENER + "The alert was accepted",
99+
WEBDRIVER_EVENT_LISTENER + "Attempt to dismiss alert",
100+
WEBDRIVER_EVENT_LISTENER + "The alert was dismissed"));
101+
assertThat(listener.messages.size(), is(4));
102+
} finally {
103+
listener.messages.clear();
104+
}
105+
}
106+
59107
@Test
60108
public void exceptionEventTest() {
61109
assertThat(super.assertThatExceptionListenerWorks(driver, listener, WEBDRIVER_EVENT_LISTENER),

src/test/java/io/appium/java_client/events/listeners/AppiumListener.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,26 @@ public class AppiumListener extends TestListener implements AppiumWebDriverEvent
1010
SingleListeners.listeners.put(AppiumListener.class, this);
1111
}
1212

13+
@Override
14+
public void beforeAlertAccept(WebDriver driver) {
15+
messages.add("WebDriverEventListener: Attempt to accept alert");
16+
}
17+
18+
@Override
19+
public void afterAlertAccept(WebDriver driver) {
20+
messages.add("WebDriverEventListener: The alert was accepted");
21+
}
22+
23+
@Override
24+
public void afterAlertDismiss(WebDriver driver) {
25+
messages.add("WebDriverEventListener: Attempt to dismiss alert");
26+
}
27+
28+
@Override
29+
public void beforeAlertDismiss(WebDriver driver) {
30+
messages.add("WebDriverEventListener: The alert was dismissed");
31+
}
32+
1333
@Override public void beforeNavigateTo(String url, WebDriver driver) {
1434
messages.add("WebDriverEventListener: Attempt to navigate to " + url);
1535
}

0 commit comments

Comments
 (0)