Closed liqing380 closed 10 years ago
PageFactory.initElements(driver, this);
This invocation uses DefaultFieldDecorator (https://github.com/SeleniumHQ/selenium/blob/master/java/client/src/org/openqa/selenium/support/pagefactory/DefaultFieldDecorator.java). It doesn't decorate fields marked by @AndroidFindBy or @iOSFindBy.
Please try this:
PageFactory.initElements(new AppiumFieldDecorator(driver),
pageObject //an instance of PageObject.class
);
Getting Null Pointer Exception on line (String company = companyName.getText();) even though i am using pagefactory Problem with when i use (MobileElement companyName).
plz provide some solution, its blocker for me.
public LoginPage(AndroidDriver
@AndroidFindBy(id ="com.octanner.android.performance:id/identityEditText")
MobileElement companyName;
@AndroidFindBy(id ="com.octanner.android.performance:id/next_page_button")
@CacheLookup
MobileElement nextButton;
public void companyLogin(TestDataReader dataReader){
try{
companyName.sendKeys("xyz");
}catch(Exception e){
e.printStackTrace();
}
}
@Anand093 can you open new issue instead of commenting on closed one ? This way your issue will get noticed and tracked properly
@Anand093 Did you open or file any new issue in same regards? I am also facing NullPointer while accessing pageFactory elements. Pls share if you got any solution Thanks in advance!
@narendra-chandratre I figured it out
Before using @AndroidFindBy in page object class write below lines. Hope it will solve your problem, plz let me know if it solves ur issue
public PageObjectClassName(AndroidDriver
Note-> I am using appium 1.6.4
Still failing :( I am using Appium version 1.8.1, Java-Client version 6.1.0 On which versions its working for you? Can you share pls ?
@narendra-chandratre this is the pom dependencies & i am using appium 1.6.4
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-android-driver</artifactId>
<version>2.39.0</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
Appium 1.6.4 and all above dependancies are you able to run Page Objects and Page Factory comfortably for Android & iOS?
@narendra-chandratre
Android, its working perfectly, ios i dint try
Actually I am still trying to make it work but last hope is to downgrade the appium version :( Thanks a lot @Anand093 for your quick help.
@narendra-chandratre
Check with the 1.6.4 and mine pom dependencies, i think it should work, even i struggled with this alot, but finally it worked for me.
Below are few helps, if u can get anything out of it.
import statements
import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.pagefactory.AndroidFindBy; import io.appium.java_client.pagefactory.AppiumFieldDecorator;
Capablities
static AndroidDriver
public static AndroidDriver
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, "true");
capabilities.setCapability(AUTO_ACCEPT_ALERT, true);
capabilities.setCapability(AUTO_DISMISS_ALERT, true);
capabilities.setCapability(ANDROID_EXPORTED, true);
capabilities.setCapability(NO_RESET, "true");
capabilities.setCapability(FULL_RESET, "false");
capabilities.setCapability(NATIVE_WEB_TAP, true);
// to hide android keyboard
capabilities.setCapability(UNICODE_KEYBOARD, true);
capabilities.setCapability(RESET_KEYBOARD, true);
capabilities.setCapability(NEW_COMMAND_TIMEOUT, 120);
capabilities.setCapability(SESSION_OVERRIDE, true);
capabilities.setCapability(AVD, device);
androidDriver = new AndroidDriver
PageObject Class
public YourPageObjectClass(AndroidDriver
@AndroidFindBy(id = "")
@CacheLookup
MobileElement somButton;
Below is the test class from where you are trying to use page object class components.
driver = Capablities.getAppCapablities(device_name, IP2);
YourPageObjectClass= new YourPageObjectClass(driver);
Env: java-client:1.6.1 Appium:v1.2.0
1:Create class PageObjects
2:Create class FolderPage:
3. my test code:
error
My question: why is @AndroidFindBy not working?
when i use @FindBy ,it is ok!