简体   繁体   English

如何验证selendroid中的Toast消息

[英]How to verify a toast message in selendroid

I need to verify a toast message like "created successfully". 我需要验证像“已成功创建”的Toast消息。 I tried by using linktext. 我尝试使用linktext。 But its not working.Can anyone help me regarding this? 但它不起作用。任何人都可以帮我这个吗?

Please use following code in your selendroid code 请在您的selendroid代码中使用以下代码

waitForElement(By.partialLinkText("Your Toast message"), 4, driver); waitForElement(By.partialLinkText(“你的Toast消息”),4,驱动程序);

where first parameter is your toast message. 其中第一个参数是您的Toast消息。 Second parameter is Time duration in Seconds,third is driver. 第二个参数是以秒为单位的持续时间,第三个是驱动程序。

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

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

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