Skip to content

Widget is trying to be located by variable name #307

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

Closed
fabianaapateanu opened this issue Feb 2, 2016 · 10 comments
Closed

Widget is trying to be located by variable name #307

fabianaapateanu opened this issue Feb 2, 2016 · 10 comments

Comments

@fabianaapateanu
Copy link

The gist is here:
https://gist.github.com/fabianaapateanu/2566308f12437ccc7007

I have one widget that is trying to be located by variable name, when it should be located only by AndroidFindBy locator. This happens when I am debugging the test. There is a server log snippet in the gist that contains the logs for searching after variable name.

@TikhomirovSergey
Copy link
Contributor

Hi @fabianaapateanu
I have some questions?

Is your app native or hybrid? Is this native or HTML content?

Also

It is failed when you are trying to test app version for Android (I know that this question is silly, but I'm seeing iOSFindBy)? Have you read the text of this PR?

Do you use exactly AndroidDriver? Is there your own subclass of the AppiumDriver? Can I take a look at full server output (gist)?

@fabianaapateanu
Copy link
Author

Hi,

I am using a native iOS & Android app. I use only native context. This happens when I run from iOS context, my driver is an instance of IODriver or AndroidDriver exactly, depending on the device I want to run the test.

When I get back to the office I will upload full log for both cases:

  • when I run the test on android
  • when I run the test on iOS

And yes, I have read the documentation. I have 3 types of widgets in my code:

  • one that uses only iOS locator
  • on that uses only Android locator
  • one that uses both
    Isn't this ok?

@TikhomirovSergey
Copy link
Contributor

one that uses both Isn't this ok?

Yeah. It is ok. i'm waiting for your logs...

@fabianaapateanu
Copy link
Author

Sorry for delay, updated gist
https://gist.github.com/fabianaapateanu/2566308f12437ccc7007

@TikhomirovSergey
Copy link
Contributor

Ok. It was difficult to read logs but I managed to do it :)
And I see two problems.

  • The first problem:

These strings were taken from files serveriOSLog.log and serverLog.log

2016-02-01 14:12:52:237 - info: [debug] Id selector, 'mNavigationDrawer', not found in Localizable.strings.
2016-02-01 14:12:52:237 - info: [debug] Pushing command to appium work queue: "au.getElementsById('mNavigationDrawer')"
2016-02-01 14:12:52:238 - info: [debug] Sending command to instruments: au.getElementsById('mNavigationDrawer')
2016-02-01 14:12:53:134 - info: [debug] [INST] 2016-02-01 2:12:55 PM +0000 Debug: Got new command 5 from instruments: au.getElementsById('mNavigationDrawer')
2016-02-01 14:12:53:136 - info: [debug] [INST] 2016-02-01 2:12:55 PM +0000 Debug: evaluating au.getElementsById('mNavigationDrawer')

This is iOS log. (!!!) It looks like you are trying to use Android widget-object against iOS app. It seems that this sample proofs my concerns: https://gist.github.com/fabianaapateanu/2566308f12437ccc7007#file-navigationdrawer-java-L2. Here is only AndroidFindBy

How to resolve

  1. If the widget (Android and iOS versions) do same things the same way then you are free to
@iOSFindBy(locator for ios)
@AndroidFindBy(locator for android)
public class NavigationDrawer extends Widget {
    // ------------------------------------------------------------------------
    // TYPES
    // ------------------------------------------------------------------------

    // ------------------------------------------------------------------------
    // STATIC FIELDS
    // ------------------------------------------------------------------------

    // ------------------------------------------------------------------------
    // STATIC INITIALIZERS
    // ------------------------------------------------------------------------

    // ------------------------------------------------------------------------
    // STATIC METHODS
    // ------------------------------------------------------------------------

    // ------------------------------------------------------------------------
    // FIELDS
    // ------------------------------------------------------------------------
    @iOSFindBy(locator for ios)
    @AndroidFindBy(locator for android)
    @CacheLookup
    protected MobileElement mChartMenuItemTxtView;

    @iOSFindBy(locator for ios)
    @AndroidFindBy(locator for android)
    @CacheLookup
    protected MobileElement mLogbookMenuItemTxtView;

//and so on
  1. If the widget do same things the same way you are free to
    If Android and iOS widgens do same things at high-level, but ways thisngs are done have some special things then you can
public abstract class NavigationDrawer extends Widget {
@AndroidFindBy(locator for android)
public class AndroidNavigationDrawer extends NavigationDrawer  {
    @AndroidFindBy(locator for android)
    @CacheLookup
    protected MobileElement mChartMenuItemTxtView;

    @AndroidFindBy(locator for android)
    @CacheLookup
    protected MobileElement mLogbookMenuItemTxtView;

//and so on
@iOSFindBy(locator for ios)
public class IOSNavigationDrawer extends NavigationDrawer  {
    @iOSFindBy(locator for ios)
    @CacheLookup
    protected MobileElement mChartMenuItemTxtView;

    @iOSFindBy(locator for ios)
    @CacheLookup
    protected MobileElement mLogbookMenuItemTxtView;

//and so on

and then

    @WithTimeout(time = 2, unit = TimeUnit.SECONDS)
    @CacheLookup
    @OverrideWidget(androidUIAutomator = AndroidNavigationDrawer.class,
    iOSUIAutomation = IOSNavigationDrawer.class)
    NavigationDrawer mNavigationDrawer;

Please read this text again #267. Also you can take a look at current tests: https://github.com/appium/java-client/tree/master/src/test/java/io/appium/java_client/pagefactory_tests/widgets

  • The second problem:

It looks like you are using invalid ids for Android. I've read Android logs and seems that it couldn't find element by id="navigation_view". But I'm not sure. If it is true so please try with this id:
your.app.package:id/navigation_view

@TikhomirovSergey
Copy link
Contributor

@fabianaapateanu
I'm waiting for your response.

I've got some idea. What about Java client wiki?

@fabianaapateanu
Copy link
Author

Hello @TikhomirovSergey,

Many thanks for looking into this, your help is much appreciated.
Yes, the serverLog was iOS log as well.

I was thinking that if I create a widget that uses only AndroidFindBy locator then this one will be searched only when in Android and when being in iOS that won't be searched at all. Actually that widget does not exist in the iOS version of the app.

I will use the abstract implementation or something else, no worries there. What about the Java wiki?

@TikhomirovSergey
Copy link
Contributor

There are many cases such as yours that should be documented. I think it is not convinient to search in PR descriptions. So I want to aggregate info at WIKI.

@fabianaapateanu
Can I close this ticket?

@fabianaapateanu
Copy link
Author

Oh, ok I see, sure.
@TikhomirovSergey
Please do close it, yes. Many many thanks!!!

@TikhomirovSergey
Copy link
Contributor

Closed!

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

No branches or pull requests

2 participants