Testing background color espresso Android

前端 未结 7 994
灰色年华
灰色年华 2020-12-11 14:50

Is it possible to check if the background color matches a given color with espresso?

Update:

I made a custom matcher, similar to what @Irfa

7条回答
  •  难免孤独
    2020-12-11 15:24

    I am not sure about that but we can retrieve the color of some of elements like button and text views `

    Button button = (Button) findViewById(R.id.my_button);
    Drawable buttonBackground = button.getBackground();
    

    and you can try like this

    ColorDrawable b_color = (ColorDrawable) button.getBackground();
    

    and then

    int color = b_color.getColor();
    if (color == R.color.green) {
        log("color is green");
    }
    

    Hope this will get you started.

提交回复
热议问题