forked from appium/java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
appium#242 fix: some fixes of API implementation. Preparation for the…
… testing.
- Loading branch information
1 parent
22a0f9e
commit 62c733d
Showing
21 changed files
with
936 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/io/appium/java_client/events/EventFiringWebDriverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* See the NOTICE file distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.appium.java_client.events; | ||
|
||
|
||
import io.appium.java_client.events.api.Listener; | ||
import org.openqa.selenium.WebDriver; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.context.support.AbstractApplicationContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
public class EventFiringWebDriverFactory { | ||
|
||
/** | ||
* This method makes an event firing instance of {@link org.openqa.selenium.WebDriver} | ||
* | ||
* @param driver an original instance of {@link org.openqa.selenium.WebDriver} that is | ||
* supposed to be listenable | ||
* @param <T> T | ||
* @return an instance of {@link org.openqa.selenium.WebDriver} that fires events | ||
*/ | ||
public static <T extends WebDriver> T getEventFiringWebDriver(T driver) { | ||
return getEventFiringWebDriver(driver, Collections.<Listener>emptyList()); | ||
} | ||
|
||
/** | ||
* This method makes an event firing instance of {@link org.openqa.selenium.WebDriver} | ||
* | ||
* @param driver an original instance of {@link org.openqa.selenium.WebDriver} that is | ||
* supposed to be listenable | ||
* @param listeners is a set of {@link io.appium.java_client.events.api.Listener} that | ||
* is supposed to be used for the event firing | ||
* @param <T> T | ||
* @return an instance of {@link org.openqa.selenium.WebDriver} that fires events | ||
*/ | ||
public static <T extends WebDriver> T getEventFiringWebDriver(T driver, Listener ... listeners) { | ||
return getEventFiringWebDriver(driver, Arrays.asList(listeners)); | ||
} | ||
|
||
/** | ||
* This method makes an event firing instance of {@link org.openqa.selenium.WebDriver} | ||
* | ||
* @param driver an original instance of {@link org.openqa.selenium.WebDriver} that is | ||
* supposed to be listenable | ||
* @param listeners is a collection of {@link io.appium.java_client.events.api.Listener} that | ||
* is supposed to be used for the event firing | ||
* @param <T> T | ||
* @return an instance of {@link org.openqa.selenium.WebDriver} that fires events | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <T extends WebDriver> T getEventFiringWebDriver(T driver, Collection<Listener> listeners) { | ||
List<Listener> listenerList = new ArrayList<>(); | ||
Iterator<Listener> providers = ServiceLoader.load( | ||
Listener.class).iterator(); | ||
|
||
while (providers.hasNext()) { | ||
listenerList.add(providers.next()); | ||
} | ||
|
||
listenerList.addAll(listeners); | ||
|
||
AbstractApplicationContext context = new AnnotationConfigApplicationContext( | ||
DefaultBeanConfiguration.class); | ||
return (T) context.getBean( | ||
DefaultBeanConfiguration.WEB_DRIVER_BEAN, driver, listenerList, context); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/appium/java_client/events/ListenerInvocationHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.appium.java_client.events; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.openqa.selenium.Alert; | ||
import org.openqa.selenium.security.Credentials; | ||
|
||
public class StubAlert implements Alert { | ||
@Override public void dismiss() { | ||
|
||
} | ||
|
||
@Override public void accept() { | ||
|
||
} | ||
|
||
@Override public String getText() { | ||
return StringUtils.EMPTY; | ||
} | ||
|
||
@Override public void sendKeys(String keysToSend) { | ||
|
||
} | ||
|
||
@Override public void setCredentials(Credentials credentials) { | ||
|
||
} | ||
|
||
@Override public void authenticateUsing(Credentials credentials) { | ||
|
||
} | ||
} |
Oops, something went wrong.