小编kgg*_*goh的帖子

Espresso测试禁用动画

在此输入图像描述

@Test
    public void test3_PaySuccessful(){
        init();

    ViewInteraction amountEditText = onView(
            allOf(withId(R.id.et_amount), isDisplayed()));
    amountEditText.perform(replaceText("SGD 0.010"), closeSoftKeyboard());

    //, withText("Proceed")
    ViewInteraction appCompatButton = onView(
            allOf(withId(R.id.btn_confirm), isDisplayed()));
    appCompatButton.perform(click());

    //, withText("Pay")
    ViewInteraction appCompatButton2 = onView(
            allOf(withId(R.id.btn_confirm), isDisplayed()));
    appCompatButton2.perform(click());

    //dialog
    ViewInteraction appCompatButton3 = onView(
            allOf(withId(R.id.confirm_button), withText("Confirm"), isDisplayed()));
    appCompatButton3.perform(click());

    //have to disable animation in order to pass this.
    intended(CoreMatchers.allOf(hasComponent(PaymentSelectionActivity2.class.getName())));

}
Run Code Online (Sandbox Code Playgroud)

我在使用涉及动画的视图进行Espresso测试时遇到了一个问题,我知道Espresso无法处理动画,所以我在下面做了. - 禁用我的测试设备窗口动画,过渡动画和动画设计持续时间缩放都设置为OFF(这不起作用) - 然后我尝试在我的代码中添加一个标志,例如.espresso_testing = true.如果为true,我的代码将跳过调用所有startAnimation()函数调用.--->这是有效的.但是,在编写espresso测试用例时,我无法更改应用程序中的代码.包括上面的测试用例.

有没有其他方法可以做到这一点?提前致谢.

animation android android-testing android-espresso

18
推荐指数
3
解决办法
1万
查看次数

在ViewFlipper中动态创建imageView获取imageView id

我在我的ViewFlipper中动态创建了imageView,它运行顺畅.但是,当我想点击图像时,我需要对图像进行放大并对其进行处理.我如何获得身份证明.我需要能够区分哪些图像我已经陈词滥调.

提前致谢.

    public class Home_Fragment extends Fragment{

.....

   private ViewFlipper vf;

    int gallery_grid_Images[]={R.drawable.a,R.drawable.b,R.drawable.c,
            R.drawable.d};

  private void setFlipperImage(int res) {
        //Log.i("Set Filpper Called", res+"");
        ImageView image = new ImageView(getActivity());



        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 
                LayoutParams.MATCH_PARENT);
        image.setLayoutParams(lp);

        image.setAdjustViewBounds (true);
        image.setScaleType(ScaleType.CENTER_INSIDE);
        image.setClickable(true);

        image.setBackgroundResource(res);

        image.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                int id=(Integer) v.getTag();     //---> This will crash if i click the image
                //Toast.makeText(getActivity(), id+"", Toast.LENGTH_LONG).show();

            }
        });


        vf.setTag(res);

        vf.addView(image);
    }
Run Code Online (Sandbox Code Playgroud)

android onclick imageview viewflipper

2
推荐指数
1
解决办法
3655
查看次数