Appium Page 工厂在定义 Android 和 IOS Xpath 时将如何选择正确的 xpath



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

 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 
}

以前应用程序没有正确设置驱动程序实例,因此我将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);
}

最新更新