Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#392 fix & #418 fix #423

Merged
merged 2 commits into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
<exclusions>
<exclusion>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -48,11 +54,6 @@
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
Expand All @@ -63,6 +64,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.2.3</version>
</dependency>
</dependencies>
<packaging>jar</packaging>
<name>java-client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -61,14 +60,6 @@ private static Class<? extends Widget> getConvenientClass(Class<? extends Widget
+ convenientClass.getName()));
}

int modifiers = convenientClass.getModifiers();
if (Modifier.isAbstract(modifiers)) {
throw new IllegalArgumentException(
new InstantiationException(convenientClass.getName()
+ " is abstract so "
+ "it can't be instantiated"));
}

return convenientClass;

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

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -56,7 +57,18 @@ class WidgetInterceptor extends InterceptorOfASingleElement {
.isLookUpCached())
|| cachedInstances.size() == 0) {
cachedElement = element;
Widget widget = instantiationMap.get(type).newInstance(cachedElement);

Constructor<? extends Widget> constructor = instantiationMap.get(type);
Class<? extends Widget> clazz = constructor.getDeclaringClass();

int modifiers = clazz.getModifiers();
if (Modifier.isAbstract(modifiers)) {
throw new InstantiationException(clazz.getName()
+ " is abstract so "
+ "it can't be instantiated");
}

Widget widget = constructor.newInstance(cachedElement);
cachedInstances.put(type, widget);
PageFactory.initElements(new AppiumFieldDecorator(widget, duration), widget);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package io.appium.java_client.pagefactory_tests.widgets;


import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.pagefactory.AppiumFieldDecorator;
import io.appium.java_client.pagefactory.TimeOutDuration;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.PageFactory;

import java.io.File;
import java.util.concurrent.TimeUnit;

public class PartiallyOverrideNegativeWidgetTest {

private static AndroidDriver<?> driver;
private static AppiumDriverLocalService service;
private static PartiallyOverrideRottenTomatoes rottenTomatoes;

/**
* initialization.
*/
@BeforeClass
public static void beforeClass() throws Exception {
service = AppiumDriverLocalService.buildDefaultService();
service.start();

File appDir = new File("src/test/java/io/appium/java_client");
File app = new File(appDir, "android-rottentomatoes-demo-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver<>(service.getUrl(), capabilities);

rottenTomatoes = new PartiallyOverrideRottenTomatoes();
PageFactory.initElements(
new AppiumFieldDecorator(driver, new TimeOutDuration(5, TimeUnit.SECONDS)),
rottenTomatoes);
}

/**
* finishing.
*/
@AfterClass
public static void afterClass() throws Exception {
if (driver != null) {
driver.quit();
}

if (service != null) {
service.stop();
}
}

@Test(expected = InstantiationException.class)
public void gettingOfAnElement() {
rottenTomatoes.checkSimpleReview();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package io.appium.java_client.pagefactory_tests.widgets;

import static org.junit.Assert.assertTrue;

import io.appium.java_client.pagefactory.AndroidFindBy;
import io.appium.java_client.pagefactory.AndroidFindBys;
import io.appium.java_client.pagefactory.OverrideWidget;
import io.appium.java_client.pagefactory_tests.widgets.html.annotated.AnnotatedHtmlMovies;
import io.appium.java_client.pagefactory_tests.widgets.html.annotated.AnnotatedHtmlReview;
import io.appium.java_client.pagefactory_tests.widgets.html.extended.ExtendedHtmlMovies;
import io.appium.java_client.pagefactory_tests.widgets.html.extended.ExtendedHtmlReview;
import io.appium.java_client.pagefactory_tests.widgets.html.simple.HtmlMovies;
import io.appium.java_client.pagefactory_tests.widgets.html.simple.HtmlReview;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.support.FindBy;

public class PartiallyOverrideRottenTomatoes implements RottenTomatoesAbstractApp {

@AndroidFindBy(id = "com.codepath.example.rottentomatoes:id/lvMovies")
@FindBy(id = "movies-collection")
@OverrideWidget(html = HtmlMovies.class)
private Movies simpleMovies;

@FindBy(id = "main_container")
@AndroidFindBys({@AndroidFindBy(id = "android:id/content"),
@AndroidFindBy(className = "android.widget.RelativeLayout")})
@OverrideWidget(html = HtmlReview.class)
private Review simpleReview;

@OverrideWidget(html = AnnotatedHtmlMovies.class)
private Movies annotatedMovies;

@OverrideWidget(html = AnnotatedHtmlReview.class)
private Review annotatedReview;

@OverrideWidget(html = ExtendedHtmlMovies.class)
private Movies extendedMovies;

@OverrideWidget(html = ExtendedHtmlReview.class)
private Review extendedReview;


@FindBy(id = "Fake_ID_For_All_Platforms")
@OverrideWidget(html = ExtendedHtmlMovies.class)
private Movies fakeMovies;

@FindBy(id = "Fake_ID_For_All_Platforms")
@OverrideWidget(html = ExtendedHtmlReview.class)
private Review fakeReview;

/**
* It gets movie count.
*/
public int getSimpleMovieCount() {
return simpleMovies.getMovieCount();
}

/**
* @param index is the desired index.
* @return a movie.
*/
public Movie getASimpleMovie(int index) {
return simpleMovies.getMovie(index);
}

/**
* It reads a review.
*/
public void checkSimpleReview() {
assertTrue(!StringUtils.isBlank(simpleReview.title()));
assertTrue(!StringUtils.isBlank(simpleReview.score()));
assertTrue(!StringUtils.isBlank(simpleReview.info()));
assertTrue(simpleReview.getPoster() != null);
}

/**
* It gets movie count.
*/
public int getAnnotatedMovieCount() {
return annotatedMovies.getMovieCount();
}

/**
* @param index is the desired index.
* @return a movie.
*/
public Movie getAnAnnotatedMovie(int index) {
return annotatedMovies.getMovie(index);
}

/**
* It reads a review.
*/
public void checkAnnotatedReview() {
assertTrue(!StringUtils.isBlank(annotatedReview.title()));
assertTrue(!StringUtils.isBlank(annotatedReview.score()));
assertTrue(!StringUtils.isBlank(annotatedReview.info()));
assertTrue(annotatedReview.getPoster() != null);
}

/**
* It gets movie count.
*/
public int getExtendeddMovieCount() {
return extendedMovies.getMovieCount();
}

/**
* @param index is the desired index.
* @return a movie.
*/
public Movie getAnExtendedMovie(int index) {
return extendedMovies.getMovie(index);
}

/**
* It reads a review.
*/
public void checkExtendedReview() {
assertTrue(!StringUtils.isBlank(extendedReview.title()));
assertTrue(!StringUtils.isBlank(extendedReview.score()));
assertTrue(!StringUtils.isBlank(extendedReview.info()));
assertTrue(extendedReview.getPoster() != null);
}

/**
* It gets movie count.
*/
public int getFakedMovieCount() {
return fakeMovies.getMovieCount();
}

/**
* It reads a review.
*/
public void checkFakeReview() {
assertTrue(!StringUtils.isBlank(fakeReview.title()));
assertTrue(!StringUtils.isBlank(fakeReview.score()));
assertTrue(!StringUtils.isBlank(fakeReview.info()));
assertTrue(fakeReview.getPoster() != null);
}

}
Loading