android stdio自动化,Android Studio 3.0+ Record Espresso Test 自动化测试,

packagecom.example.administrator.teagarden.activity.login;importandroid.support.test.espresso.ViewInteraction;importandroid.support.test.filters.LargeTest;importandroid.support.test.rule.ActivityTestRule;importandroid.support.test.runner.AndroidJUnit4;importandroid.view.View;importandroid.view.ViewGroup;importandroid.view.ViewParent;importcom.example.administrator.teagarden.R;importorg.hamcrest.Description;importorg.hamcrest.Matcher;importorg.hamcrest.TypeSafeMatcher;importorg.junit.Rule;importorg.junit.Test;importorg.junit.runner.RunWith;import staticandroid.support.test.espresso.Espresso.onView;import staticandroid.support.test.espresso.action.ViewActions.click;import staticandroid.support.test.espresso.action.ViewActions.closeSoftKeyboard;import staticandroid.support.test.espresso.action.ViewActions.replaceText;import staticandroid.support.test.espresso.matcher.ViewMatchers.isDisplayed;import staticandroid.support.test.espresso.matcher.ViewMatchers.withClassName;import staticandroid.support.test.espresso.matcher.ViewMatchers.withId;import staticandroid.support.test.espresso.matcher.ViewMatchers.withText;import staticorg.hamcrest.Matchers.allOf;import staticorg.hamcrest.Matchers.is;

@LargeTest

@RunWith(AndroidJUnit4.class)public classSplashActivityTest {

@Rulepublic ActivityTestRule mActivityTestRule = new ActivityTestRule<>(SplashActivity.class);

@Testpublic voidsplashActivityTest() {//Added a sleep statement to match the app's execution delay.//The recommended way to handle such scenarios is to use Espresso idling resources:// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

try{

Thread.sleep(6000);

}catch(InterruptedException e) {

e.printStackTrace();

}

ViewInteraction appCompatEditText=onView(

allOf(withId(R.id.login_edit_user),

childAtPosition(

childAtPosition(

withClassName(is("android.widget.LinearLayout")),2),0),

isDisplayed()));

appCompatEditText.perform(click());

ViewInteraction appCompatEditText2=onView(

allOf(withId(R.id.login_edit_user),

childAtPosition(

childAtPosition(

withClassName(is("android.widget.LinearLayout")),2),0),

isDisplayed()));

appCompatEditText2.perform(replaceText("152****3478"), closeSoftKeyboard());

ViewInteraction appCompatEditText3=onView(

allOf(withId(R.id.login_edit_mima),

childAtPosition(

allOf(withId(R.id.logint_edit_layout),

childAtPosition(

withClassName(is("android.widget.LinearLayout")),4)),0),

isDisplayed()));

appCompatEditText3.perform(replaceText("admin000"), closeSoftKeyboard());

ViewInteraction appCompatButton=onView(

allOf(withId(R.id.login_button), withText("登录"),

childAtPosition(

childAtPosition(

withClassName(is("android.widget.RelativeLayout")),1),2),

isDisplayed()));

appCompatButton.perform(click());//Added a sleep statement to match the app's execution delay.//The recommended way to handle such scenarios is to use Espresso idling resources:// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

try{

Thread.sleep(3000);

}catch(InterruptedException e) {

e.printStackTrace();

}

ViewInteraction radioButton=onView(

allOf(withId(R.id.main_home_radio2), withText("监控"),

childAtPosition(

allOf(withId(R.id.main_tab_group),

childAtPosition(

withClassName(is("android.widget.LinearLayout")),0)),1),

isDisplayed()));

radioButton.perform(click());//Added a sleep statement to match the app's execution delay.//The recommended way to handle such scenarios is to use Espresso idling resources:// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

try{

Thread.sleep(3000);

}catch(InterruptedException e) {

e.printStackTrace();

}

ViewInteraction radioButton2=onView(

allOf(withId(R.id.main_home_radio3), withText("动态"),

childAtPosition(

allOf(withId(R.id.main_tab_group),

childAtPosition(

withClassName(is("android.widget.LinearLayout")),0)),2),

isDisplayed()));

radioButton2.perform(click());//Added a sleep statement to match the app's execution delay.//The recommended way to handle such scenarios is to use Espresso idling resources:// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html

try{

Thread.sleep(3000);

}catch(InterruptedException e) {

e.printStackTrace();

}

ViewInteraction radioButton3=onView(

allOf(withId(R.id.main_home_radio4), withText("我的"),

childAtPosition(

allOf(withId(R.id.main_tab_group),

childAtPosition(

withClassName(is("android.widget.LinearLayout")),0)),3),

isDisplayed()));

radioButton3.perform(click());

}private static MatcherchildAtPosition(final Matcher parentMatcher, final intposition) {return new TypeSafeMatcher() {

@Overridepublic voiddescribeTo(Description description) {

description.appendText("Child at position " + position + " in parent ");

parentMatcher.describeTo(description);

}

@Overridepublic booleanmatchesSafely(View view) {

ViewParent parent=view.getParent();return parent instanceof ViewGroup &&parentMatcher.matches(parent)&&view.equals(((ViewGroup) parent).getChildAt(position));

}

};

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值