首页 > 解决方案 > 获取 io.appium.uiautomator2.common.exceptions.UiAutomator2Exception 错误

问题描述

我为 Android TV 流媒体应用程序编写自动化程序,运行测试时遇到问题。当我尝试运行 test 时,出现错误:

org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:io.appium.uiautomator2.common.exceptions.UiAutomator2Exception:java.lang.IllegalArgumentException:尚未声明前缀为“com.onoapps.some.dev”的命名空间。

有谁知道问题是什么?

我在用着:

这就是我想要做的。

        public class RemoteControl extends AppiumBaseClass {

            public RemoteControl(AppiumDriver driver) {
                PageFactory.initElements(new AppiumFieldDecorator(driver), this);
            }

            @AndroidFindBy(xpath = "//com.onoapps.some.dev:id/topRootId[@focusable='true']")
            private MobileElement currentTab;

            public String getCurrentTabName() {
                MobileElement tabText = currentTab.findElement(By.id("com.onoapps.some.dev:id/topBarItemTextViewId"));
                return tabText.getText();
            }
        }

        public class SeriesScreenFlows extends BaseTestClass {
            public void getSeriesTab(){
        getCurrentTabName();
            }
        }

        public class BaseTestClass extends AppiumBaseClass {

            public WebDriverWait wait;
            public Series_screen series_screen;
            public RemoteControl remoteControl;


            @Before
            public void setUp() throws MalformedURLException {
                AppiumController.instance.start();
                series_screen = new Series_screen(driver());
                remoteControl = new RemoteControl(driver());
            }
        }

标签: javaandroidjunitautomationappium

解决方案


当您通过ID找到MobileElement时,您不需要包含您的应用程序包,因此请更改此行:

MobileElement tabText = currentTab.findElement(By.id("com.onoapps.some.dev:id/topBarItemTextViewId"));

对此

MobileElement tabText = currentTab.findElement(By.id("topBarItemTextViewId"));

并且您的测试应该按预期开始工作。

或者,如果您想使用XPath

MobileElement tabText = currentTab.findElement(By.xpath("//*[@id='com.onoapps.some.dev:id/topBarItemTextViewId']"));

更多信息:AS - 运行您现有的 Appium 测试


推荐阅读