Skip to content

Commit fe01575

Browse files
Merge pull request #582 from TikhomirovSergey/master
#574 FIX
2 parents 92082bf + 615ef51 commit fe01575

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ public List<WebElement> findElements() {
151151
return shouldCache;
152152
}
153153

154+
@Override public String toString() {
155+
return String.format("Located by %s", by);
156+
}
157+
154158

155159
// This function waits for not empty element list using all defined by
156160
private static class WaitingFunction<T> implements Function<Supplier<T>, T> {

src/main/java/io/appium/java_client/pagefactory/ElementInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19+
import static io.appium.java_client.pagefactory.ThrowableUtil.extractReadableException;
20+
1921
import io.appium.java_client.pagefactory.interceptors.InterceptorOfASingleElement;
2022
import org.openqa.selenium.WebDriver;
2123
import org.openqa.selenium.WebElement;
@@ -37,7 +39,7 @@ class ElementInterceptor extends InterceptorOfASingleElement {
3739
try {
3840
return method.invoke(element, args);
3941
} catch (Throwable t) {
40-
throw ThrowableUtil.extractReadableException(t);
42+
throw extractReadableException(t);
4143
}
4244
}
4345
}

src/main/java/io/appium/java_client/pagefactory/ElementListInterceptor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19+
import static io.appium.java_client.pagefactory.ThrowableUtil.extractReadableException;
20+
1921
import io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements;
2022
import org.openqa.selenium.WebElement;
2123
import org.openqa.selenium.support.pagefactory.ElementLocator;
@@ -37,7 +39,7 @@ class ElementListInterceptor extends InterceptorOfAListOfElements {
3739
try {
3840
return method.invoke(elements, args);
3941
} catch (Throwable t) {
40-
throw ThrowableUtil.extractReadableException(t);
42+
throw extractReadableException(t);
4143
}
4244
}
4345

src/main/java/io/appium/java_client/pagefactory/WidgetInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19+
import static io.appium.java_client.pagefactory.ThrowableUtil.extractReadableException;
1920
import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getCurrentContentType;
2021

2122
import io.appium.java_client.pagefactory.bys.ContentType;
@@ -76,7 +77,7 @@ class WidgetInterceptor extends InterceptorOfASingleElement {
7677
method.setAccessible(true);
7778
return method.invoke(cachedInstances.get(type), args);
7879
} catch (Throwable t) {
79-
throw ThrowableUtil.extractReadableException(t);
80+
throw extractReadableException(t);
8081
}
8182
}
8283

src/main/java/io/appium/java_client/pagefactory/WidgetListInterceptor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.appium.java_client.pagefactory;
1818

19+
import static io.appium.java_client.pagefactory.ThrowableUtil.extractReadableException;
1920
import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getCurrentContentType;
2021

2122
import io.appium.java_client.pagefactory.bys.ContentType;
@@ -70,7 +71,7 @@ class WidgetListInterceptor extends InterceptorOfAListOfElements {
7071
try {
7172
return method.invoke(cachedWidgets, args);
7273
} catch (Throwable t) {
73-
throw ThrowableUtil.extractReadableException(t);
74+
throw extractReadableException(t);
7475
}
7576
}
7677
}

src/main/java/io/appium/java_client/pagefactory/interceptors/InterceptorOfASingleElement.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.openqa.selenium.internal.WrapsDriver;
2424
import org.openqa.selenium.support.pagefactory.ElementLocator;
2525

26-
import java.lang.reflect.InvocationTargetException;
2726
import java.lang.reflect.Method;
2827

2928

@@ -37,14 +36,19 @@ public InterceptorOfASingleElement(ElementLocator locator, WebDriver driver) {
3736
}
3837

3938
protected abstract Object getObject(WebElement element, Method method, Object[] args)
40-
throws InvocationTargetException, IllegalAccessException, InstantiationException, Throwable;
39+
throws Throwable;
4140

4241
/**
4342
* Look at
4443
* {@link net.sf.cglib.proxy.MethodInterceptor#intercept(Object, Method, Object[], MethodProxy)}
4544
*/
4645
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
4746
throws Throwable {
47+
48+
if (method.getName().equals("toString") && args.length == 0) {
49+
return locator.toString();
50+
}
51+
4852
if (Object.class.equals(method.getDeclaringClass())) {
4953
return proxy.invokeSuper(obj, args);
5054
}

0 commit comments

Comments
 (0)