2017-01-21 89 views
1

我正在测试我的活动内部片段的启动,因此在执行点击按钮以启动片段后,我测试了内部视图中文本的存在情况尽管该片段是我的手机上,甚至在视图层次推出的推出的片段,但测试甚至无法被显示的文本存在:Android:Espresso,层次结构中找不到匹配的视图

View Hierarchy: 

+--------->AppCompatTextView{id=2131886318, res-name=text3_textView, visibility=VISIBLE, width=768, height=68, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=695.0, text=Pour finaliser votre inscription nous avons besion 
d'une photo de profil, input-type=0, ime-target=false, has-links=false} 

测试失败的位置:

onView(withText("photo de profil")).check(matches(isDisplayed())); 

我想知道为什么咖啡不能通过这项测试,是因为它不会等待洗车片段?

btw我把动画关掉了。

回答

2

espresso withText方法匹配所有字符串相等。

在你的情况下,如果字符串以字符串结尾,则需要匹配。

您的代码应该是这样的:

onView(withText(endsWith("photo de profil"))).check(matches(isDisplayed())); 

这里有更多的例子:http://qathread.blogspot.com.br/2014/01/discovering-espresso-for-android.html

+1

人,由于一吨,我简直不敢相信我浪费了上一整天。 –

+1

@ AbdenaceurLichiheb它对于这个我们有堆栈溢出的东西,大家也都觉得这个,我很乐意帮忙:D – jonathanrz