android UiAutomator一个完整的个人信息修改测试用例

上周写了一个班级功能的测试用例,这周完成了个人信息的测试用例,刚试过,没什么问题,写出来分享一下,烦请指正。

public void myInfo() throws UiObjectNotFoundException {//完整个人信息测试

startApp();
checkLog();
alterName();
setGrade();
setSubject();
setSex();
alterTeachAge();
setIdentity();
setEducation();
alterUniversity();
alterSpecialty();
alterIntroduction();
alterTeachingFeature();

}

下面是具体的方法。

public void startApp() throws UiObjectNotFoundException {//启动app
UiDevice.getInstance().pressHome();
UiDevice.getInstance().pressHome();
clean();//清理后台程序
getUiObjectByText("点知教育").clickAndWaitForNewWindow();//打开app
outputNotable("app启动了!");
}

public void checkLog() throws UiObjectNotFoundException{//检查登录立即登录
setShort();
boolean log = true;
while(log){
UiObject me = new UiObject(new UiSelector().text("我"));
if (me.exists()) {//检查是否登录
outputNotable("已经登录了!");
log = false;
}else{
UiObject login = new UiObject(new UiSelector().resourceId("com.dianzhi.teacher.school:id/et_user"));
if (login.exists()) {//检查是否进入登录界面
login();//执行登录方法
Date start = new Date();
UiObject me1 = new UiObject(new UiSelector().text("我"));
while(!me1.exists()){//等待进入首页
sleep(100);
Date now = new Date();
long x = now.getTime() - start.getTime();
if (x>10000) {//超时提醒失败
outputNotable("登录失败!");
break;
}
}
}
}
}
setLong();
}

public void alterName() throws UiObjectNotFoundException{//修改名字
setShort();
getUiObjectByText("我").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String name = getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_name_my_infomation_activity").getText();
getUiObjectByText("老师:").clickAndWaitForNewWindow();
pressTimes(KeyEvent.KEYCODE_DEL, 6);
int a = new Random().nextInt(120);
if (a<40 && a >= 0) {
writeText("测试一");
getUiObjectByText("完成").clickAndWaitForNewWindow();
if (name == "测试一"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newname =  getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_name_my_infomation_activity").getText();
assertEquals("修改名字失败!", "测试一", newname);
outputNotable("修改名字成功!");
UiDevice.getInstance().pressBack();
}else if (a<80 && a >= 40) {
writeText("测试二");
getUiObjectByText("完成").clickAndWaitForNewWindow();
if (name == "测试二"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newname =  getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_name_my_infomation_activity").getText();
assertEquals("修改名字失败!", "测试二", newname);
outputNotable("修改名字成功!");
UiDevice.getInstance().pressBack();
}else if (a<120 && a >= 80) {
writeText("测试三");
getUiObjectByText("完成").clickAndWaitForNewWindow();
if (name == "测试三"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newname =  getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_name_my_infomation_activity").getText();
assertEquals("修改名字失败!", "测试三", newname);
outputNotable("修改名字成功!");
UiDevice.getInstance().pressBack();

setLong();
}

public void setGrade() throws UiObjectNotFoundException{//随机设置年级
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String grade = getUiObjextByResourceId("com.dianzhi.teacher.school:id/class_tv").getText();
getUiObjectByText("年级:").clickAndWaitForNewWindow();
int num = new Random().nextInt(3);
switch (num) {
case 0:
getUiObjectByText("初中").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String grade0 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/class_tv").getText();
assertEquals("修改年级失败!", "初中", grade0);
outputNotable("修改年级成功!");
UiDevice.getInstance().pressBack();
break;
case 1:
getUiObjectByText("高中").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String grade1 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/class_tv").getText();
assertEquals("修改年级失败!", "高中", grade1);
outputNotable("修改年级成功!");
UiDevice.getInstance().pressBack();
break;
case 2:
getUiObjectByText("取消").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newgrade = getUiObjextByResourceId("com.dianzhi.teacher.school:id/class_tv").getText();
assertEquals("修改年级失败!", grade, newgrade);
outputNotable("修改年级成功!");
UiDevice.getInstance().pressBack();
break;

default:
outputNotable("修改年级失败!");;
break;
}
setLong();
}

public void setSubject() throws UiObjectNotFoundException {//随机修改科目
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String subjectname = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
getUiObjectByText("科目:").clickAndWaitForNewWindow();
int num = new Random().nextInt(10);
switch (num) {
case 0:
getUiObjectByText("语文").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject0 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "语文", newsubject0);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 1:
getUiObjectByText("数学").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject1 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "数学", newsubject1);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 2:
getUiObjectByText("英语").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject2 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "英语", newsubject2);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 3:
getUiObjectByText("物理").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject3 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "物理", newsubject3);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 4:
getUiObjectByText("化学").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject4 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "化学", newsubject4);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 5:
getUiObjectByText("生物").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject5 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "生物", newsubject5);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 6:
getUiObjectByText("政治").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject6 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "政治", newsubject6);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 7:
getUiObjectByText("历史").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject7 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "历史", newsubject7);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 8:
getUiObjectByText("地理").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject8 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", "地理", newsubject8);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
case 9:
getUiObjectByText("取消").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newsubject9 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/subject_tv").getText();
assertEquals("修改学科失败!", subjectname, newsubject9);
outputNotable("修改学科成功!");
UiDevice.getInstance().pressBack();
break;
default:
outputNotable("修改学科失败!");;
break;
}
setLong();
}

public void setSex() throws UiObjectNotFoundException {//随机设置性别
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String text = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_sex_text_my_infomation_activity").getText();
getUiObjectByText("性别:").click();
int a = new Random().nextInt(160);
if (a<40 && a >= 0) {
getUiObjectByText("保密").click();
if (text == "保密"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
assertEquals("修改性别失败!", "保密", getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_sex_text_my_infomation_activity").getText());
UiDevice.getInstance().pressBack();
}else if (a<80 && a >= 40) {
getUiObjectByText("男").click();
if (text == "男"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
assertEquals("修改性别失败!", "男", getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_sex_text_my_infomation_activity").getText());
UiDevice.getInstance().pressBack();
}else if (a<120 && a >= 80) {
getUiObjectByText("女").click();
if (text == "女"){
UiDevice.getInstance().pressBack();
}else{
getUiObjectByText("保存").clickAndWaitForNewWindow();
}
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
assertEquals("修改性别失败!", "女", getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_sex_text_my_infomation_activity").getText());
UiDevice.getInstance().pressBack();
} else {
getUiObjectByText("取消").click();
UiDevice.getInstance().pressBack();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
assertEquals("修改性别失败!", text, getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_sex_text_my_infomation_activity").getText());
UiDevice.getInstance().pressBack();
}
outputNotable("修改性别成功!");
setLong();
}

public void alterTeachAge() throws UiObjectNotFoundException {//修改教龄
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
getUiObjectByText("教龄:").clickAndWaitForNewWindow();
int num = new Random().nextInt(100);
String age = ""+num;
writeText(age);
getUiObjectByText("完成").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String newage = getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_teaching_age_my_infomation_activity").getText();
assertEquals("修改教龄失败!", age, newage);
outputNotable("修改教龄成功!");
UiDevice.getInstance().pressBack();
setLong();
}

public void setIdentity() throws UiObjectNotFoundException {//随机设置身份
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
getUiObjectByText("身份:").clickAndWaitForNewWindow();
int num = new Random().nextInt(6);
switch (num) {
case 0:
getUiObjectByText("特级教师").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity0 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "特级教师", identity0);
outputNotable("修改身份成功!");
break;
case 1:
getUiObjectByText("高级教师").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity1 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "高级教师", identity1);
outputNotable("修改身份成功!");
break;
case 2:
getUiObjectByText("高级教师").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity2 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "高级教师", identity2);
outputNotable("修改身份成功!");
break;
case 3:
getUiObjectByText("专职教师").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity3 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "专职教师", identity3);
outputNotable("修改身份成功!");
break;
case 4:
getUiObjectByText("在校学生").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity4 = getUiScrollableByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "在校学生", identity4);
outputNotable("修改身份成功!");
break;
case 5:
getUiObjectByText("其他").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity5 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", "其他", identity5);
outputNotable("修改身份成功!");
break;
case 6:
getUiObjectByText("取消").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity6 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", identity, identity6);
outputNotable("修改身份成功!");
break;
default:
break;
}
UiDevice.getInstance().pressBack();
setLong();
}

public void setEducation() throws UiObjectNotFoundException {//修改学历
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String education = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_degree_my_infomation_activity").getText();
getUiObjectByText("学历:").clickAndWaitForNewWindow();
int num = new Random().nextInt(5);
switch (num) {
case 0:
getUiObjectByText("博士").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity0 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_degree_my_infomation_activity").getText();
assertEquals("修改身份失败!", "博士", identity0);
outputNotable("修改学历成功!");
break;
case 1:
getUiObjectByText("硕士").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity1 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_degree_my_infomation_activity").getText();
assertEquals("修改学历失败!", "硕士", identity1);
outputNotable("修改学历成功!");
break;
case 2:
getUiObjectByText("本科").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity2 = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_degree_my_infomation_activity").getText();
assertEquals("修改学历失败!", "本科", identity2);
outputNotable("修改学历成功!");
break;
case 3:
getUiObjectByText("其他").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String identity4 = getUiScrollableByResourceId("com.dianzhi.teacher.school:id/tv_degree_my_infomation_activity").getText();
assertEquals("修改学历失败!", "其他", identity4);
outputNotable("修改学历成功!");
break;
case 4:
getUiObjectByText("取消").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String neweducation = getUiObjextByResourceId("com.dianzhi.teacher.school:id/tv_Identity_my_infomation_activity").getText();
assertEquals("修改身份失败!", education, neweducation);
outputNotable("修改身份成功!");
break;
default:
break;
}
UiDevice.getInstance().pressBack();
setLong();
}


public void alterUniversity() throws UiObjectNotFoundException {//修改毕业院校
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
getUiObjectByText("毕业院校:").clickAndWaitForNewWindow();
int num = new Random().nextInt(100);
String info = "info" + num;
writeText(info);
getUiObjectByText("完成").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String university = getUiObjextByResourceId("com.dianzhi.teacher.school:id/ed_school_my_infomation_activity").getText();
assertEquals("修改毕业院校失败!", info, university);
outputNotable("修改毕业院校成功!");
UiDevice.getInstance().pressBack();
setLong();
}

public void alterSpecialty() throws UiObjectNotFoundException {//修改专业
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
getUiScrollabe().getChildByText(new UiSelector().text("专业:"), "专业:").clickAndWaitForNewWindow();
int num = new Random().nextInt(100);
String info = "info" + num;
writeText(info);
getUiObjectByText("完成").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String specialty = getUiScrollabe().getChildByText(new UiSelector().text("专业:"), "专业:").getFromParent(new UiSelector().resourceId("com.dianzhi.teacher.school:id/ed_study_field_my_infomation_activity")).getText();
assertEquals("修改专业失败!", info, specialty);
outputNotable("修改专业成功!");
UiDevice.getInstance().pressBack();
setLong();
}

public void alterIntroduction() throws UiObjectNotFoundException {//修改简介
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
getUiScrollabe().getChildByText(new UiSelector().text("简介:"), "简介:").clickAndWaitForNewWindow();
int num = new Random().nextInt(100);
String info = "info" + num;
writeText(info);
getUiObjectByText("完成").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String specialty = getUiScrollabe().getChildByText(new UiSelector().text("简介:"), "简介:").getFromParent(new UiSelector().resourceId("com.dianzhi.teacher.school:id/ed_rmarks_my_infomation_activity")).getText();
assertEquals("修改简介失败!", info, specialty);
outputNotable("修改简介成功!");
UiDevice.getInstance().pressBack();
setLong();
}

public void alterTeachingFeature() throws UiObjectNotFoundException {
setShort();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
getUiScrollabe().getChildByText(new UiSelector().text("教学特点:"), "教学特点:").clickAndWaitForNewWindow();
int num = new Random().nextInt(100);
String info = "info" + num;
writeText(info);
getUiObjectByText("完成").clickAndWaitForNewWindow();
getUiObjectByText("保存").clickAndWaitForNewWindow();
getUiObjectByText("个人资料 > ").clickAndWaitForNewWindow();
String specialty = getUiScrollabe().getChildByText(new UiSelector().text("教学特点:"), "教学特点:").getFromParent(new UiSelector().resourceId("com.dianzhi.teacher.school:id/ed_characteristic_my_infomation_activity")).getText();
assertEquals("修改教学特点失败!", info, specialty);
outputNotable("修改教学特点成功!");
UiDevice.getInstance().pressBack();
setLong();
}

阅读更多
个人分类: android uiautomator
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

android UiAutomator一个完整的个人信息修改测试用例

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭