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

appium#52 Add @FindBy annotations for appium's extra locator strategies #68

Merged
merged 1 commit into from
Jul 28, 2014
Merged

appium#52 Add @FindBy annotations for appium's extra locator strategies #68

merged 1 commit into from
Jul 28, 2014

Conversation

TikhomirovSergey
Copy link
Contributor

WebElement can be instantiated by these ways:

@FindBy(someStrategy) //for browser or Html UI
@AndroidFindBy(someStrategy) //for Android UI of the same application. Strategies are:
//uiAutomator, accessibility, id, name, className, tagName, xpath
//@AndroidFindBys({@AndroidFindBy(someStrategy1), @AndroidFindBy(someStrategy2)}) is for chained search

@iOSFindBy(someStrategy) //for iOS UI of the same application. Strategies are:
//uiAutomator, accessibility, id, name, className, tagName, xpath
//iOSFindBys({@iOSFindBy(someStrategy1), @iOSFindBy(someStrategy2)}) is for chained search
WebElement someElement;

or

@FindBy(someStrategy)
@AndroidFindBy(someStrategy) 
@iOSFindBy(someStrategy)
RemoteWebElement someElement;

or

@AndroidFindBy(someStrategy) 
@iOSFindBy(someStrategy)
MobileElement someElement;

Now old browser page objects can be reusable with this decorator:

PageFactory.initElements(new AppiumFieldDecorator(driver), 
pageObject //an instance of PageObject.class
);

or

PageFactory.initElements(new AppiumFieldDecorator(driver, 
          15, //default implicit waiting timeout for all strategies
        TimeUnit.SECONDS), 
            pageObject //an instance of PageObject.class
);

I made some tests. If there is not enough please add your own.

@bootstraponline
Copy link
Member

Please squash to one commit.

git reset --soft head~32
git commit -am "Fix #52"
git push -f

@jlipps
Copy link
Member

jlipps commented Jul 23, 2014

I think @Jonahss will want to review this and he's on vacation for a few more days--thanks a ton for the work!

@TikhomirovSergey
Copy link
Contributor Author

Is squashed.

@Jonahss Jonahss merged commit 70d9e03 into appium:master Jul 28, 2014
@Jonahss
Copy link
Member

Jonahss commented Jul 28, 2014

Awesome!

@prattpratt
Copy link
Contributor

Cool! Looks great!
Nice job, @TikhomirovSergey !

@hatti
Copy link

hatti commented Sep 1, 2014

Hello! I posted a question to the Annotations into https://discuss.appium.io/t/java-client-1-6-0-findby-annotations-vs-driver-find/88

@TikhomirovSergey
Copy link
Contributor Author

@email2vimalraj
Copy link
Contributor

I'm bit confused on this implementation. Correct me if I'm doing wrong here:

public class TestOne {
    private WebDriver driver;

    @FindBy(id="testid")
    @AndroidFindBy(id="testid")
    @iOSFindBy(id="testid")
    MobileElement testElement;

    @Before
    public void setup() {
        PageFactory.initElements(new AppiumFieldDecorator(driver, 15, TimeUnit.SECONDS), this);
    }

    @Test
    public void testHideKeyboard() {
        testElement.scrollTo("someText");   // Doesn't work, because the scrollTo is implemented in AndroidDriver
        driver.hideKeyboard();              // Doesn't work either, because hideKeyboard is implemented in AppiumDriver
    }
}

Are these annotations only works for web ui, not for native?
My native app and web ui have similar ui and the actions, only the locators are different. Kindly apologise me for the very basic question as I have started learning the Appium now.

@TikhomirovSergey
Copy link
Contributor Author

Hi @email2vimalraj
FindBy is supposed to be used for browser or web view. AndroidFindBy and IOSFindBy were designed to be used against NATIVE content . So the code below

@FindBy(id="testid") //id in HTML DOM
@AndroidFindBy(id="androidtestid") //id of Android native UI element
@iOSFindBy(id="iostestid") //id of iOS native UI element
RemoteWebElement testElement; //I advice you to use RemoteWebElement for super crossplatform 
//scripts because of problems with touch actions that are going to be resolved

should work. Otherwice please open an issue.
Please look at samples: https://github.com/appium/sample-code/tree/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium
Page object samples are here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants