Closed justintilson closed 9 years ago
Hey, could you post your capabilities as well? I've been using page factory extensively and haven't encountered this issue.
System.out.println(driver.getCapabilities().toString());
outputs for an Android test:
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.4.4, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=192.168.56.101:5555, platform=LINUX}]
and for an iOS test:
Capabilities [{networkConnectionEnabled=false, desired={}, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, platform=MAC}]
I also dug a bit deeper into the debugger for the particular field I've included above as it's being decorated by the PageFactory and it shows no annotations (I'm not sure if it should):
@justintilson Hi! Is it native app? Maybe hybrid. Maybe you are trying to run test with mobile browser?
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.4.4, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=192.168.56.101:5555, platform=LINUX}]
Are you tryng to use iOSFindBy for Android
@iOSFindBy(accessibility = "home_landing_my_favorites_count_label")
?
Please improve your page object as follows
@iOSFindBy(accessibility = "home_landing_my_favorites_count_label")
@AndroidFindBy(your locator for android)
private WebElement myFavoritesCountLabel;
What the result?
@TikhomirovSergey, I'm testing native apps on Android and iOS.
I have separate tests and page objects for Android and iOS and use the appropriate @FindBy in each.
Here are the desired capabilities that are passed into the Android driver:
and for the iOS
And if it helps:
Ok. If I clearly understand you
Appuim features allow to implement one page object for Android/iOS/browser testing. Please look at this
@iOSFindBy(locator_for_ios) //this locater is used when here is iOS native content
@AndroidFindBy(locator_for_android)//this locator is used when here
//is Android native content
@FindBy(locator_for_HTML)//this locator is used when here mobile
//or desktop browser or webview
private WebElement myFavoritesCountLabel;
Ok. Is this used with Android
public class HomePhonePage extends BaseHomePage {
public HomePhonePage(AppiumDriver driver) {
super(driver);
PageFactory.initElements(new AppiumFieldDecorator(driver,
IMPLICIT_WAIT,
TimeUnit.SECONDS),
this
);
}
@iOSFindBy(accessibility = "home_landing_my_favorites_count_label")
private WebElement myFavoritesCountLabel;
public String getMyFavoritesCountLabel() {
return myFavoritesCountLabel.getText();
}
}
?
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.4.4, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=192.168.56.101:5555, platform=LINUX}]
...I am just trying to understand your problem and usecase :)
@TikhomirovSergey - I understand that I can use a single page object to test both platforms but I've found in this particular instance it didn't work out well because the implementations are somewhat different and evolving at different rates.
Here is the Android page object (same as iOS in this instance but in a different package):
public class HomePhonePage extends BaseHomePage {
public HomePhonePage(AppiumDriver driver) {
super(driver);
PageFactory.initElements(new AppiumFieldDecorator(driver,
IMPLICIT_WAIT,
TimeUnit.SECONDS),
this
);
}
@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.wholefoods.wholefoodsmarket:id/tvFavOrangeBubble\")")
private MobileElement myFavoritesCountLabel;
public String getMyFavoritesCountLabel() {
return myFavoritesCountLabel.getText();
}
}
ok. Now it is clear. Is your app hybrid? Appium-specific annotations were designed for native contents. What does return .getContext() method before your test is failed?
System.out.println(driver.getContext());
prints: NATIVE_APP
Ok. Is it possible that your project is still depending on java_client 2.2.0 or lower? Please look at your dependencies hierarchy.
I thought that might have had something to do with it so I upgraded yesterday. Here is my build.gradle file:
dependencies {
testCompile 'org.testng:testng:6.8.21'
testCompile 'org.seleniumhq.selenium:selenium-java:2.46.0'
testCompile 'io.appium:java-client:3.0.0'
testCompile 'com.google.code.gson:gson:2.3.1'
testCompile 'org.json:json:20140107'
testCompile 'org.apache.httpcomponents:httpclient:4.3.6'
testCompile 'net.sf.opencsv:opencsv:2.3'
}
and the gradle cache:
And when you are running
System.out.println(driver.getCapabilities().toString());
it is printing
Capabilities [{networkConnectionEnabled=true, desired={}, platformVersion=4.4.4, warnings={}, webStorageEnabled=false, locationContextEnabled=false, browserName=Android, takesScreenshot=true, javascriptEnabled=true, databaseEnabled=false, deviceName=192.168.56.101:5555, platform=LINUX}]
Am I right? It interesting where is platformName = "Android".
Ok. I have two things to say. The first it is my fault that I forgot to improve this: https://github.com/appium/java-client/blob/master/src/main/java/io/appium/java_client/pagefactory/AppiumElementLocator.java#L74 It is outdated thing from times when there weren't AndroidDriver/IOSFriver (there was only AppiumDriver). I can change it and propese PR soon.
The second. If I am right then there is the strange difference between given and printed capabilities. The absence of "platformName" parameter causes your problem.
I changed the 'platformName' desired capability to 'platform' with no difference and then tried both platform and platformName with the same result.
Here is the DesiredCapabilities instance that is passed to the AndroidDriver's constructor:
and this is how they read after the driver has been instantiated:
I'm not sure where LINUX is coming from but it's not something I seem to be able to control.
I tried switching to node server (instead of Appium.app) and got the same results. It's still trying to use the property name of the page object to find elements instead of using the values provided in the annotations.
@justintilson The PR is proposed and now it is waiting for the merging.
@TikhomirovSergey - thanks for the update and your speedy fix. How long is typical for a merge? Our tiny team of two is somewhat blocked by this issue.
It is depending on @Jonahss
@justintilson merged! Are you ok compiling on your own from this repo? Or would you prefer we do a full release to the Maven Central Repository?
@Jonahss - our current gradle build script pulls from the Maven repo. I could probably tweak it to download the source and compile it if you weren't planning to do a release for a while. If it's relatively effortless to do a release, that would accelerate things on my side.
@justintilson Yeah I can do a release :) It's relatively effortless compared to gardening in my backyard. But is an incredible amount of effort compared to using npm :P
I'll start running the test suite now.
@justintilson Ok, released version 3.1.0
It works! I tested on both Android and iOS. @TikhomirovSergey, @Jonahss Thanks so much for moving this issue through so quickly!
Yay!
On Mon, Jul 6, 2015 at 3:57 PM, Justin Tilson notifications@github.com wrote:
It works! I tested on both Android and iOS. @TikhomirovSergey https://github.com/TikhomirovSergey, @Jonahss https://github.com/Jonahss Thanks so much for moving this issue through so quickly!
— Reply to this email directly or view it on GitHub https://github.com/appium/java-client/issues/211#issuecomment-119022425.
I'm happy :)
one question. Do I need to change the context of the driver before I try to locate webview elements (hybrid app - like FB login) by using Page Objects/Factory as mentioned above?
FindBy(locator_for_HTML)//this locator is used when here mobile //or desktop browser or webview private WebElement myFavoritesCountLabel;
I've been trying for a couple of days to get iOSFindBy & AndroidFindBy annotations working with page objects and the PageFactory. I've tried versions 2.2.0 and 3.0.0 of the java-client and tests for Android and iOS, all with the same result - which is the same as not including any annotations.
Here is a truncated version of one of my page objects
My test code:
When I debug into PageFactory.initElements, I see [unknown locator] for each property that is a WebElement. Then the PageFactory defaults to looking for each page object's property name as the id or name of the WebElement and fails to find anything.
I suspect "I'm doing it wrong" but I can't figure out where. It is behaving as if the annotations are not even there.