【问题标题】:Creating own Customised MobileElement by extending from MobileElement通过从 MobileElement 扩展创建自己的自定义 MobileElement
【发布时间】:2018-11-09 08:32:50
【问题描述】:

我正在尝试拥有自己的自定义 MobileElement 类,我可以添加更多方法。 例如,我有一个名为 SamplePage 的类,它包含以下移动元素:

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

我在测试用例中使用它让我们说如下:

  samplePage.SettingsButton.click();

我想要的如下

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

我在 customisedMobileElement 类中使用 IsVisible() 方法或 CopyText() 方法的测试用例:

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

您能分享一下您的想法吗?

【问题讨论】:

    标签: java appium pageobjects page-factory


    【解决方案1】:

    首先定义页面如下:

    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();
        }
    }
    

    那么你可以这样使用:

    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();
      }
    
    }
    

    【讨论】:

    • 我用appium java client 7.2.0尝试了你建议的解决方案。仍然没有运气。我收到错误为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
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    • 2014-03-15
    • 1970-01-01
    • 2016-05-19
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多