如何在Selendroid中验证Toast消息

4

我需要验证一个名为“创建成功”的toast消息。我尝试使用linktext,但它不起作用。有人能帮我吗?

2个回答

7
请在您的selendroid代码中使用以下代码:

waitForElement(By.partialLinkText("Your Toast message"), 4, driver);

第一个参数是您的toast消息。第二个参数是时间持续秒数,第三个参数是驱动程序。

有没有办法捕获Toast并将其打印出来? - user2632692
我会尝试捕捉并尽快更新..请投票支持答案,这将对其他人有所帮助。 - Sachin Tyagi

0
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toast_layout_root"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:background="#DAAA" >

    <ImageView android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="10dp" />

    <TextView android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:textColor="#FFF" />

</LinearLayout>

MainActivity.java

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
                               (ViewGroup) findViewById(R.id.toast_layout_root));

ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello! This is a custom toast!");

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show()

使用Selendroid自动化工具,我需要验证toast消息。 - user2632692

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接