简体   繁体   English

获取io.appium.uiautomator2.common.exceptions.UiAutomator2Exception错误

[英]Getting io.appium.uiautomator2.common.exceptions.UiAutomator2Exception error

I write automation for Android TV streaming app, I have problem to run the test. 我为Android TV流应用程序编写了自动化程序,运行测试时遇到问题。 When I'm trying to run test , i got error: 当我尝试运行test时,出现错误:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。 Original error: io.appium.uiautomator2.common.exceptions.UiAutomator2Exception: java.lang.IllegalArgumentException: Namespace with prefix 'com.onoapps.some.dev' has not been declared. 原始错误:io.appium.uiautomator2.common.exceptions.UiAutomator2Exception:java.lang.IllegalArgumentException:尚未声明前缀为'com.onoapps.some.dev'的命名空间。

Anyone know what the problem is? 有人知道是什么问题吗?

I'm using: 我正在使用:

  • Xiaomi miBox. 小米miBox。
  • Java 爪哇
  • Appium 阿皮
  • JUnit JUnit的

That's what I was trying to do. 那就是我想做的。

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

You don't need to include you app package when you locate a MobileElement by ID so change this line: 通过ID查找MobileElement时,无需包含应用程序包,因此请更改以下行:

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

to this 对此

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

and your test should start working as expected. 并且您的测试应该按预期开始工作。

Alternatively if you want to use XPath 或者,如果您想使用XPath

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

More information: AS - Run your existing Appium tests 详细信息: AS-运行现有的Appium测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM