浓咖啡单击Textview中的特定子字符串

时间:2019-01-28 00:21:02

标签: android android-espresso android-testing

我有一个包含textview的布局,如下所示,它将在文本块中包含一些自动生成的链接。当用户单击链接时,将打开一个包含相关信息的窗口。

screenshot of app

但是,我根本不知道如何使Espresso单击链接。尝试了

之类的多种变体

matches(withText(containsString("45")))

但这只是不起作用或使浓缩咖啡仅单击文本框本身,什么都不做。

有没有办法做到这一点?在Espresso的限制范围内甚至有可能吗?

1 个答案:

答案 0 :(得分:2)

您可以使用openLinkWithText(String linkText)

  

返回一个操作,该操作打开与给定链接文本和uri匹配器匹配的链接。该操作是通过调用链接的onClick方法执行的(与实际在屏幕上发出单击相反)。

以下是使用方法的示例:

Scanning dependencies of target client_ed25519
[  0%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ed25519.c.o
[  1%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_0.c.o
[  2%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_isnegative.c.o
[  2%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_sub.c.o
[  3%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/ge_p1p1_to_p2.c.o
[  4%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/ge_p3_to_cached.c.o
[  4%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/open.c.o
In file included from /home/riley/mariadb-connector-c/plugins/auth/ref10/crypto_hash_sha512.h:2:0,
                 from /home/riley/mariadb-connector-c/plugins/auth/ref10/open.c:3:
/home/riley/mariadb-connector-c/include/ma_crypt.h:74:1: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
 MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *ctx);
 ^~~~~~~~~~~
 MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h:74:50: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
 MA_HASH_CTX *ma_hash_new(unsigned int algorithm, MA_HASH_CTX *ctx);
                                                  ^~~~~~~~~~~
                                                  MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h:83:19: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
 void ma_hash_free(MA_HASH_CTX *ctx);
                   ^~~~~~~~~~~
                   MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h:96:20: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
 void ma_hash_input(MA_HASH_CTX *ctx,
                    ^~~~~~~~~~~
                    MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h:108:21: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
 void ma_hash_result(MA_HASH_CTX *ctx, unsigned char *digest);
                     ^~~~~~~~~~~
                     MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h: In function ‘ma_hash’:
/home/riley/mariadb-connector-c/include/ma_crypt.h:155:3: error: unknown type name ‘MA_HASH_CTX’; did you mean ‘MA_HASH_MD5’?
   MA_HASH_CTX *ctx= NULL;
   ^~~~~~~~~~~
   MA_HASH_MD5
/home/riley/mariadb-connector-c/include/ma_crypt.h:160:8: warning: implicit declaration of function ‘ma_hash_new’; did you mean ‘ma_hash’? [-Wimplicit-function-declaration]
   ctx= ma_hash_new(algorithm, ctx);
        ^~~~~~~~~~~
        ma_hash
/home/riley/mariadb-connector-c/include/ma_crypt.h:160:6: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   ctx= ma_hash_new(algorithm, ctx);
      ^
/home/riley/mariadb-connector-c/include/ma_crypt.h:161:3: warning: implicit declaration of function ‘ma_hash_input’; did you mean ‘ma_hash’? [-Wimplicit-function-declaration]
   ma_hash_input(ctx, buffer, buffer_length);
   ^~~~~~~~~~~~~
   ma_hash
/home/riley/mariadb-connector-c/include/ma_crypt.h:162:3: warning: implicit declaration of function ‘ma_hash_result’; did you mean ‘ma_hash’? [-Wimplicit-function-declaration]
   ma_hash_result(ctx, digest);
   ^~~~~~~~~~~~~~
   ma_hash
/home/riley/mariadb-connector-c/include/ma_crypt.h:163:3: warning: implicit declaration of function ‘ma_hash_free’; did you mean ‘ma_hash’? [-Wimplicit-function-declaration]
   ma_hash_free(ctx);
   ^~~~~~~~~~~~
   ma_hash
CMakeFiles/client_ed25519.dir/build.make:206: recipe for target 'CMakeFiles/client_ed25519.dir/plugins/auth/ref10/open.c.o' failed
make[2]: *** [CMakeFiles/client_ed25519.dir/plugins/auth/ref10/open.c.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/client_ed25519.dir/all' failed
make[1]: *** [CMakeFiles/client_ed25519.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

参考文献:espresso-recipes-for-android