标签: android-uiautomator

UiAutomator getLastTraversedText()

我试图使用Android UiAutomator测试Android Webview.据我了解文档,滚动WebvView会生成UI遍历事件,这些事件应该是可读的getUiDevice().getLastTraversedText().

但是,当我使用getUiDevice().pressDPadDown()滚动浏览Web视图时,getUiDevice().getLastTraversedText()保持返回null.

我错过了什么?

如果有人接到这个电话,我会非常感谢一个简短的代码示例.

android ui-automation android-webview android-uiautomator

8
推荐指数
1
解决办法
4769
查看次数

一个Android应用程序可以通过UI Automator控制另一个应用程序吗?

我正在尝试编写可以部署在目标设备上的Android应用程序/服务.该应用程序可用作钩子来远程控制目标设备.从Jelly Bean版本开始,可以使用UI Automator实现,它提供了类似的功能.但是,似乎UI Automator只能通过ADB接口使用.在设备上运行的应用程序无法直接使用UI Automator(???).我试图找到一个可以在没有亚行帮助的情况下工作的解决方案.例如,挂钩可以将套接字监听为protobuf服务器.客户端可以向钩子发送命令以远程控制和设备.我查看了Andorid SDK源代码.看起来唯一的方法是使用android辅助功能API.我想知道是否有更好的方法?

android accessibility android-uiautomator

8
推荐指数
2
解决办法
6634
查看次数

写入Android UI Automator输出控制台

我正在Android UI Automator上写一个小包装器.通常我们可以在控制台中看到测试用例状态.我可以访问它并添加我自己的消息吗?我试过了System.out.println.但它没有用.有没有办法做到这一点?

android android-uiautomator

8
推荐指数
1
解决办法
2624
查看次数

如何使用Espresso访问外部网站上的元素

使用espresso,我们点击一​​个登录按钮,启动外部网站(Chrome自定义标签),您可以登录,然后重定向回我们的Android应用程序.

Espresso有没有办法:
1)验证正在启动的URL
2)访问网站上的元素,以便我可以输入登录信息并继续登录

在此输入图像描述

当我尝试在咖啡启动导航查看它,什么也不显示的页面,如果我尝试记录,它不会对我拿起进入页面上的任何内容.

这是我到目前为止(它在Kotlin(而不是Java)): 在此输入图像描述

这是显示的错误: 在此输入图像描述

它启动我的应用程序,选择登录按钮,打开网站,但它无法访问元素.

我也尝试过:

在此输入图像描述

更新:这是使用Chrome自定义标签(不是网络视图),因此Espresso Web无法使用.

android android-espresso android-uiautomator chrome-custom-tabs android-espresso-recorder

8
推荐指数
1
解决办法
2026
查看次数

HiltAndroidTest 中的同一个文件有多个活动的 DataStore

我刚刚将 DataStore 添加到我们的代码库中。之后,我发现所有顺序 UI 测试都失败 - 测试用例中的第一个测试通过,但下一个失败并显示There are multiple DataStores active for the same file.

\n

我使用 Hilt 提供一个数据存储实例

\n
@InstallIn(SingletonComponent::class)\n@Module\ninternal object DataStoreModule {\n\n    @Singleton\n    @Provides\n    internal fun provideConfigurationDataStore(\n        @ApplicationContext context: Context,\n        configurationLocalSerializer: ClientConfigurationLocalSerializer\n    ): DataStore<ClientConfigurationLocal> = DataStoreFactory.create(\n        serializer = configurationLocalSerializer,\n        produceFile = { context.dataStoreFile("configuration.pb") }\n    )\n}\n
Run Code Online (Sandbox Code Playgroud)\n

我猜这是因为In a Hilt test, the singleton component\xe2\x80\x99s lifetime is scoped to the lifetime of a test case rather than the lifetime of the Application.

\n

关于如何解决这个问题有什么想法吗?

\n

android datastore android-uiautomator dagger-hilt

8
推荐指数
1
解决办法
3048
查看次数

如何使用Google UiAutomator按两次按钮?

我使用以下脚本在Android中的计算器中使用UiAutomator键入"33".但是,只接受第一个'3',第二个按下完全被忽略.

import com.android.uiautomator.core.*;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class MyFirstUiAutomatorTest extends UiAutomatorTestCase {
    UiObject getByDescription(String description) {
        return new UiObject(new UiSelector().description(description));
    }

    UiObject getByText(String description) {
        return new UiObject(new UiSelector().text(description));
    }

    UiObject scrollableGetByText(String text ) throws UiObjectNotFoundException {
            UiScrollable uiScrollable = new UiScrollable(new UiSelector().scrollable(true));
            uiScrollable.setAsHorizontalList();
            return uiScrollable.getChildByText(new UiSelector().className(
                    android.widget.TextView.class.getName()),
                    text);      
    }

    public void testStuff() throws UiObjectNotFoundException {
        getUiDevice().pressHome();
        getByDescription("Apps").clickAndWaitForNewWindow();
        getByText("Apps").click();
        scrollableGetByText("Calculator").clickAndWaitForNewWindow();

        // pressing '+' and '=' effectively clears the previous input
        getByText("+").click();
        getByText("=").click();
        getByText("3").click();
        // this second '3' is ignored
        getByText("3").click();
    } …
Run Code Online (Sandbox Code Playgroud)

java android automated-tests android-virtual-device android-uiautomator

7
推荐指数
1
解决办法
5338
查看次数

UIAutomator根据索引点击listview

我正在尝试使用一般方法实现UIAutomator测试用例来执行ListView项目的单击(无论持有listitem的视图组的类型如何).

目前我有以下代码,但它一直点击第一项.

public void clickListViewItem(int index) throws UiObjectNotFoundException {
   UiObject listview = new UiObject(new UiSelector().className("android.widget.ListView"));
   if(index <= listview.getChildCount()){
      listview.getChild(new UiSelector().index(index)).click();
   }else{
       throw new UIObjectNotFoundException("Index is greater than listSize");
   }
}
Run Code Online (Sandbox Code Playgroud)

android listview android-uiautomator

7
推荐指数
1
解决办法
3905
查看次数

如何从UIAutomator运行"adb命令"

所以我有一个UIAutomator测试脚本,我在测试执行期间希望它运行一些adb命令.我该怎么做呢 ?

我在想有没有办法在UI自动化类中调用脚本?或者有没有办法直接执行"adb命令"?

这是我的代码:

package com.uia.example.my;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;

public class ADBCommandTest extends UiAutomatorTestCase{
    public void testDemo() throws UiObjectNotFoundException{

        System.out.println("Entering the shell script");
        try {
            ProcessBuilder pb = new ProcessBuilder("./run.sh");
            Process p = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null; 
                while ((line = reader.readLine()) != null)
                {
                    System.out.println(line);
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

    }

}
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误:

INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
INSTRUMENTATION_STATUS: …
Run Code Online (Sandbox Code Playgroud)

scripting android adb ui-automation android-uiautomator

7
推荐指数
2
解决办法
9751
查看次数

除了UIAutomator 2.0版本名称之外,UIObject和UIObject2之间的区别是什么?

我在Android开发者网站上做了一些谷歌搜索和搜索,但我无法找到合适的答案.任何人都可以帮我解决这个问题吗?提前致谢.

android android-uiautomator

7
推荐指数
1
解决办法
3473
查看次数

Appium - 如何使用 UiAutomator2 和 WebdriverIO 以及 React Native (Android) 和 JavaScript 向下滚动

无论我如何尝试,我都无法让我的 React Native (Android) 应用程序使用 Appium 向下滚动。

我正在使用 UiAutomator2 和 WebdriverIO。

我的代码如下所示:

scrollUntilDisplayed(element: WebdriverIO.Element) {
    const dimensions = driver.getWindowSize();
    touchScroll(10, 100);
}
Run Code Online (Sandbox Code Playgroud)

touchScroll我尝试了以下调用来代替:

  • driver.touchScroll(offsetX, offsetY)- 抛出错误 ( invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • driver.touchScroll(offsetX, offsetY, element)- 抛出错误 ( invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • browser.execute("mobile: scroll", {direction: 'down'});- 抛出错误 ( unknown error: An unknown server-side error occurred while processing the …

javascript appium webdriver-io android-uiautomator react-native

7
推荐指数
1
解决办法
1万
查看次数