本代码使用易测云进行代码录制(R2.7),然后进行修改,代码如下:
package com.aaa.bbb_test;
import android.app.Activity;
import com.jayway.android.robotium.solo.*;
import android.app.Activity;
import android.view.*;
import android.widget.*;
/***/
@SuppressWarnings("unchecked")
public class SignTest extends Test {
private static final String LAUNCHER_ACTIVITY_CLASSNAME = "com.aaa.bbb.ccc.activities.SplashActivity";
private static Class<Activity> launchActivityClass;
static {
try {
launchActivityClass = (Class<Activity>)Class.forName(LAUNCHER_ACTIVITY_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public SignTest() {
super("com.aaa.bbb.cccc", launchActivityClass);
}
public void testRecorded() {
//等待 Activity "GuideActivity" 启动
System.out.println("now is:"+solo.waitForActivity("GuideActivity", 30000));
if(solo.waitForActivity("GuideActivity", 30000)==true){
assertTrue("Activity \"GuideActivity\" is not started.", solo.waitForActivity("GuideActivity", 30000));
solo.sleep(2000);
//拖拽:从 (79.91%, 55.16%) 到 (6.20%, 52.92%)
solo.drag(toX(0.799074f), toX(0.062037f), toY(0.551562f), toY(0.529167f), 5);
solo.sleep(2000);
//拖拽:从 (82.13%, 57.71%) 到 (5.65%, 55.26%)
solo.drag(toX(0.821296f), toX(0.056481f), toY(0.577083f), toY(0.552604f), 6);
solo.sleep(2000);
//拖拽:从 (85.56%, 52.03%) 到 (5.74%, 57.81%)
solo.drag(toX(0.855556f), toX(0.057407f), toY(0.520312f), toY(0.578125f), 7);
solo.sleep(2000);
//按下 图片(路径: com.aaa.bbb:id/my_slider[0]) 控件中操作点:X: 0.59814817, Y: 0.56964767)
solo.clickInView(solo.getViewByPath("com.aaa.bbb:id/my_slider[0]"), 0.59814817f, 0.56964767f);
solo.sleep(2000);
}
else{
//等待 Activity "SplashActivity" 启动
//assertTrue("Activity \"SplashActivity\" is not started.", solo.waitForActivity("SplashActivity", 30000));
//solo.sleep(2000);
//System.out.println("SplashActivity is:"+solo.waitForActivity("SplashActivity", 5000));
//System.out.println("MainTabActivity is:"+solo.waitForActivity("MainTabActivity", 5000));
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 10000));
solo.sleep(5000);
//按下 RadioButton(路径: com.aaa.bbb:id/main_radio[3]) 控件中操作点:X: 0.44074073, Y: 0.91935486)
solo.clickInView(solo.getViewByPath("com.aaa.bbb:id/main_radio[3]"), 0.44074073f, 0.91935486f);
solo.sleep(2000);
//等待 Activity "UserCenterActivity" 启动
assertTrue("Activity \"UserCenterActivity\" is not started.", solo.waitForActivity("UserCenterActivity", 10000));
solo.sleep(2000);
//若是用户已经登录,则进行注销
if(solo.searchText("我的积分")==true){
//按下 LinearLayout (ID: rlayout_login)
solo.clickInView(solo.getView("rlayout_login"), 0.89074075f, 0.385f);
solo.sleep(2000);
//等待 Activity "UserAccountActivity" 启动
assertTrue("Activity \"UserAccountActivity\" is not started.", solo.waitForActivity("UserAccountActivity", 30000));
solo.sleep(2000);
//按下 TextView "注销". View Path: com.aaa.bbb:id/tv_logout
solo.clickOnText("^注销$");
solo.sleep(5000);
}
//注销后继续走登录流程
//按下 图片 (ID: tv_unlogin)
solo.clickInView(solo.getView("tv_unlogin"), 0.5543478f, 0.24489796f);
solo.sleep(2000);
//等待 Activity "UserLoginActivity" 启动
assertTrue("Activity \"UserLoginActivity\" is not started.", solo.waitForActivity("UserLoginActivity", 30000));
solo.sleep(2000);
//按下 EditText (ID: edit_usename)
solo.clickInView(solo.getView("edit_usename"), 0.21764706f, 0.2f);
solo.sleep(5000);
//输入文字:"test02"
enterText((EditText)solo.getView("edit_usename"), "tesafsfs");
solo.sleep(2000);
//按下 EditText (ID: edit_passwrod)
solo.clickInView(solo.getView("edit_passwrod"), 0.17745098f, 0.2761905f);
solo.sleep(2000);
//输入文字:"fsfsfw"
enterText((EditText)solo.getView("edit_passwrod"), "1fsfsf");
solo.sleep(2000);
//按下 按钮 "登 录". View Path: com.aaa.bbb:id/btn_login
solo.clickOnButton("^登 录$");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(2000);
//按下 TextView (ID: tv_sign)
solo.clickInView(solo.getView("tv_sign"), 0.6215686f, 0.26744187f);
solo.sleep(2000);
//等待 Activity "NewSignActivity" 启动
assertTrue("Activity \"NewSignActivity\" is not started.", solo.waitForActivity("NewSignActivity", 30000));
solo.sleep(2000);
//按下 TextView "44". View Path: com.aaa.bbb.ccc:id/tv_integral
solo.clickInView(solo.getView("iv_bg_sign"), 0.5261438f, 0.23114754f);
solo.sleep(5000);
//按下 TextView (ID: title_left_tv)
solo.clickOnView("title_left_tv");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(2000);
//按下 LinearLayout (ID: rlayout_login)
solo.clickInView(solo.getView("rlayout_login"), 0.9037037f, 0.295f);
solo.sleep(2000);
//等待 Activity "UserAccountActivity" 启动
assertTrue("Activity \"UserAccountActivity\" is not started.", solo.waitForActivity("UserAccountActivity", 30000));
solo.sleep(2000);
//按下 TextView "注销". View Path: com.aaa.bbb.ccc:id/tv_logout
solo.clickOnText("^注销$");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(2000);
//按下 图片 (ID: tv_unlogin)
solo.clickInView(solo.getView("tv_unlogin"), 0.6195652f, 0.12244898f);
solo.sleep(2000);
//等待 Activity "UserLoginActivity" 启动
assertTrue("Activity \"UserLoginActivity\" is not started.", solo.waitForActivity("UserLoginActivity", 30000));
solo.sleep(2000);
//按下 ScrollView (ID: scroller_content)
solo.clickInView(solo.getView("scroller_content"), 0.4148148f, 0.050380785f);
solo.sleep(2000);
//按下 EditText "test02". View Path: com.aaa.bbb:id/edit_usename
solo.clickOnText("^test02$");
solo.sleep(5000);
//输入文字:"130924111"
enterText((EditText)solo.getView("edit_usename"), "130924111");
solo.sleep(2000);
//按下 EditText (ID: edit_passwrod)
solo.clickInView(solo.getView("edit_passwrod"), 0.2784314f, 0.2f);
solo.sleep(2000);
//输入文字:"123456"
enterText((EditText)solo.getView("edit_passwrod"), "123456");
solo.sleep(2000);
//按下 按钮 "登 录". View Path: com.aaa.bbb:id/btn_login
solo.clickOnButton("^登 录$");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(2000);
//按下 TextView (ID: tv_sign)
solo.clickInView(solo.getView("tv_sign"), 0.6245098f, 0.27325583f);
solo.sleep(2000);
//等待 Activity "NewSignActivity" 启动
assertTrue("Activity \"NewSignActivity\" is not started.", solo.waitForActivity("NewSignActivity", 30000));
solo.sleep(2000);
//按下 图片 (ID: iv_bg_sign)
solo.clickInView(solo.getView("iv_bg_sign"), 0.5261438f, 0.23114754f);
solo.sleep(2000);
//按下 TextView (ID: title_left_tv)
solo.clickOnView("title_left_tv");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(2000);
//按下 LinearLayout (ID: rlayout_login)
solo.clickInView(solo.getView("rlayout_login"), 0.92314816f, 0.355f);
solo.sleep(2000);
//等待 Activity "UserAccountActivity" 启动
assertTrue("Activity \"UserAccountActivity\" is not started.", solo.waitForActivity("UserAccountActivity", 30000));
solo.sleep(2000);
//按下 TextView "注销". View Path: com.aaa.bbb:id/tv_logout
solo.clickOnText("^注销$");
solo.sleep(2000);
//等待 Activity "MainTabActivity" 启动
assertTrue("Activity \"MainTabActivity\" is not started.", solo.waitForActivity("MainTabActivity", 30000));
solo.sleep(5000);
}
}
}
Robotium_客户端登录注销代码(1)
最新推荐文章于 2022-03-12 13:33:06 发布