2

I am trying to have own customized MobileElement class that i can add more methods. For example I have a class named SamplePage and it contains below mobile element:

  @iOSFindBy(accessibility = "Settings")
  @AndroidFindBy(id = "Settings")
  public MobileElement SettingsButton;

I use it in test case lets say as below:

  samplePage.SettingsButton.click();

What I want to have is as below

   @iOSFindBy(accessibility = "Settings")
   @AndroidFindBy(id = "Settings")
   public customisedMobileElement SettingsButton;

A test case with IsVisible() method or CopyText() method I have in customisedMobileElement class:

   Assert.isTrue(samplePage.SettingsButton.IsVisible(), "not visible");
   samplePage.LoginTextInput.CopyText();

Could you please share your ideas about how to do it?

Bill Hileman
  • 2,798
  • 2
  • 17
  • 24
Random
  • 31
  • 3

1 Answers1

0

First define the page as follow:

public class SettingPage{       

    @AndroidFindBy(accessibility = "Settings")
    @iOSFindBy(accessibility = "Settings")
    private MobileElement setting;

    public SettingPage(AppiumDriver<MobileElement> driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }

    public boolean isScreenDisplayed(){
        try {
            return setting.isDisplayed();
        }catch (Exception e){
            return false;
        }
    }

    public void click(){
         setting.click();
    }
}

Then you can use this as following:

public class Test(){
  AppiumDriver<MobileElement> driver;

  //define your desiredCapabilities and appium driver

  private SettingPage settingPage;

  public void displayTest(
   settingPage= new SettingPage(driver);
   settingPage.isScreenDisplayed();
  }

  public void clickTest(
   settingPage= new SettingPage(driver);
   settingPage.click();
  }

}
Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
  • I tried the solution that you suggested with appium java client 7.2.0. still no luck. I am getting the error as `Error Message: java.lang.IllegalArgumentException: Can not set xx.xxx.xxxx.utils.platform.app.AppElement field xx.xxx.xxxx.utils.pagefactory.pages.passcodepage.PasscodePage.pin1 to io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$b598166c` – user3262242 Sep 19 '19 at 14:25