Skip to content

Commit

Permalink
appium#242 fix: some fixes of API implementation. Preparation for the…
Browse files Browse the repository at this point in the history
… testing.
  • Loading branch information
TikhomirovSergey authored and pfoster-youitv committed Jul 29, 2016
1 parent 22a0f9e commit 62c733d
Show file tree
Hide file tree
Showing 21 changed files with 936 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

@Aspect
Expand Down Expand Up @@ -107,7 +108,7 @@ private List<Object> returnProxyList(List<Object> originalList) {

}

void add(List<Listener> listeners) {
void add(Collection<Listener> listeners) {
listener.add(listeners);
}

Expand Down Expand Up @@ -459,6 +460,7 @@ public void afterRotation(JoinPoint joinPoint) throws Throwable {
+ "execution(* org.openqa.selenium.WebDriver.Window.*(..)) || "
+ "execution(* io.appium.java_client.android.AndroidElement.*(..)) || "
+ "execution(* io.appium.java_client.ios.IOSElement.*(..)) || "
+ "execution(* org.openqa.selenium.remote.RemoteWebDriver.*(..)) || "
+ "execution(* org.openqa.selenium.Alert.*(..))")
public Object doAround(ProceedingJoinPoint point) throws Throwable {
Throwable t = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <T extends WebDriver> T getListenableWebdriver(T driver, List<Listener> listener
AbstractApplicationContext context) {
this.driver = driver;
this.listeners.addAll(listeners);
this.context = context;
return driver;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class DefaultListener implements AppiumWebDriverEventListener, AlertEventListener,
Expand Down Expand Up @@ -120,7 +121,7 @@ public class DefaultListener implements AppiumWebDriverEventListener, AlertEvent
((ListensToException) dispatcher).onException(throwable, driver);
}

void add(List<Listener> listeners) {
void add(Collection<Listener> listeners) {
this.listeners.addAll(listeners);
}

Expand Down
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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;
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/io/appium/java_client/events/StubAlert.java
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) {

}
}
Loading

0 comments on commit 62c733d

Please sign in to comment.