【问题标题】:How Appium Page factory will pick correct xpath when both Android & IOS Xpaths are defined定义 Android 和 IOS Xpath 时,Appium Page factory 如何选择正确的 xpath
【发布时间】:2020-03-05 22:53:01
【问题描述】:

我是 Appium 的新手,并计划使用 Appium 页面工厂在 android 和 IOS 中使用相同的脚本执行我的测试,目前我正在使用 Android 设备,所以我将 IOS xpath 保持为空,当我执行我的脚本时抛出错误 "userNameTextBox=null" 。我这里有两个问题 1.根据什么标准Appium页面工厂会知道选择android还是IOS的xpath 2. 为什么在我的代码中它会抛出“userNameTextBox as Null”,尽管我使用的是 Android 驱动程序。

 private AndroidDriver<AndroidElement> driver;

    @AndroidFindBy(className = "android.widget.EditText")
    @iOSBy(className = "")
    private AndroidElement userNameTextBox;


  public void login(String userName, String password) throws InterruptedException {
        userNameTextBox.sendKeys(userName);
}


public static void main(String[] args) throws IOException, InvalidFormatException, InterruptedException {
        LaunchApplication.launchApp("samsungtablet");--This code will launch the app based on device passed
        LoginPage lp= new LoginPage();


        lp.login("test", "test");---Failing here 

}

【问题讨论】:

  • 显示初始化和/或传递对驱动程序的引用的代码...
  • 感谢您的提示,这就是问题所在,我已修复并且成功了

标签: java selenium appium appium-android


【解决方案1】:

以前应用程序没有正确设置驱动程序实例,结果我将 xpath 值设为 null,我添加了下面的函数以从 launchapplication 类调用驱动程序,它可以使用它。

public void login(String userName, String password) throws InterruptedException {
 this.driver = LaunchApplication.driver;
         PageFactory.initElements(new AppiumFieldDecorator(driver), this);

        userNameTextBox.sendKeys(userName);
}

【讨论】:

    猜你喜欢
    • 2014-08-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 2015-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多