Skip to content

Commit

Permalink
Merge pull request #2 from arachnidium/master
Browse files Browse the repository at this point in the history
AndroidPageObjectTest improvement.
  • Loading branch information
Jonahss committed Sep 29, 2014
2 parents 88197f7 + 1d45e63 commit f7687da
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;

class AppiumElementLocatorFactory implements ElementLocatorFactory, ResetsImplicitlyWaitTimeOut {
private static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;
private static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;

private final SearchContext searchContext;
private final SearchContext searchContext;
private final TimeOutContainer timeOutContainer;

public AppiumElementLocatorFactory(SearchContext searchContext,
Expand All @@ -21,7 +18,8 @@ public AppiumElementLocatorFactory(SearchContext searchContext,
}

public AppiumElementLocatorFactory(SearchContext searchContext) {
this(searchContext, DEFAULT_IMPLICITLY_WAIT_TIMEOUT, DEFAULT_TIMEUNIT);
this(searchContext, AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT,
AppiumFieldDecorator.DEFAULT_TIMEUNIT);
}

public ElementLocator createLocator(Field field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class AppiumFieldDecorator implements FieldDecorator, ResetsImplicitlyWai

private final AppiumElementLocatorFactory factory;

public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;

public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;

public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut, TimeUnit timeUnit) {
factory = new AppiumElementLocatorFactory(context, implicitlyWaitTimeOut, timeUnit);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.File;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -140,7 +141,8 @@ public void setUp() throws Exception {
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

PageFactory.initElements(new AppiumFieldDecorator(driver), this);
//This time out is set because test can be run on slow Android SDK emulator
PageFactory.initElements(new AppiumFieldDecorator(driver, 5, TimeUnit.SECONDS), this);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.FindAll;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class TimeOutResetTest {
private WebDriver driver;
private final static long ACCEPTABLE_DELTA_MILLS = 500;

/**
* Default time out parameters
*/

private static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;
private static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;

@FindBy(className = "ClassWhichDoesNotExist")
@FindAll({@FindBy(className = "ClassWhichDoesNotExist"),
@FindBy(className = "OneAnotherClassWhichDoesNotExist")})
private List<WebElement> stubElements;
private AppiumFieldDecorator afd;

Expand Down Expand Up @@ -69,10 +65,10 @@ private long getBenchMark() {

@Test
public void test() {
checkTimeDifference(DEFAULT_IMPLICITLY_WAIT_TIMEOUT, DEFAULT_TIMEUNIT,
checkTimeDifference(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT, AppiumFieldDecorator.DEFAULT_TIMEUNIT,
getBenchMark());
System.out.println(String.valueOf(DEFAULT_IMPLICITLY_WAIT_TIMEOUT)
+ " " + DEFAULT_TIMEUNIT.toString() + ": Fine");
System.out.println(String.valueOf(AppiumFieldDecorator.DEFAULT_IMPLICITLY_WAIT_TIMEOUT)
+ " " + AppiumFieldDecorator.DEFAULT_TIMEUNIT.toString() + ": Fine");

afd.resetImplicitlyWaitTimeOut(15500000, TimeUnit.MICROSECONDS);
checkTimeDifference(15500000, TimeUnit.MICROSECONDS, getBenchMark());
Expand Down

0 comments on commit f7687da

Please sign in to comment.