robotium android apk software test sample
来源:互联网 发布:php oa办公系统 编辑:程序博客网 时间:2024/05/22 14:33
/*
* This is an example test project created in Eclipse to test NotePad which is a sample
* project located in AndroidSDK/samples/android-11/NotePad
*
*
* You can run these test cases either on the emulator or on device. Right click
* the test project and select Run As --> Run As Android JUnit Test
*
* @author Renas Reda, renas.reda@jayway.com
*
*/
package com.jayway.test;
import com.example.android.notepad.NotesList;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList>{
private Solo solo;
public NotePadTest() {
super(NotesList.class);
}
@Override
public void setUp() throws Exception {
//setUp() is run before a test case is started.
//This is where the solo object is created.
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
//tearDown() is run after a test case has finished.
//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
solo.finishOpenedActivities();
}
public void testAddNote() throws Exception {
solo.clickOnMenuItem("Add note");
//Assert that NoteEditor activity is opened
solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");
//In text field 0, add Note 1
solo.enterText(0, "Note 1");
solo.goBack();
//Clicks on menu item
solo.clickOnMenuItem("Add note");
//In text field 0, add Note 2
solo.enterText(0, "Note 2");
//Go back to first activity named "NotesList"
solo.goBackToActivity("NotesList");
//Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
solo.takeScreenshot();
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
//Assert that Note 1 & Note 2 are found
assertEquals("Note 1 and/or Note 2 are not found", expected, actual);
}
public void testEditNote() throws Exception {
// Click on the second list line
solo.clickInList(2);
// Change orientation of activity
solo.setActivityOrientation(Solo.LANDSCAPE);
// Change title
solo.clickOnMenuItem("Edit title");
//In first text field (0), add test
solo.enterText(0, " test");
solo.goBack();
boolean expected = true;
// (Regexp) case insensitive
boolean actual = solo.waitForText("(?i).*?note 1 test");
//Assert that Note 1 test is found
assertEquals("Note 1 test is not found", expected, actual);
}
public void testRemoveNote() throws Exception {
//(Regexp) case insensitive/text that contains "test"
solo.clickOnText("(?i).*?test.*");
//Delete Note 1 test
solo.clickOnMenuItem("Delete");
//Note 1 test & Note 2 should not be found
boolean expected = false;
boolean actual = solo.searchText("Note 1 test");
//Assert that Note 1 test is not found
assertEquals("Note 1 Test is found", expected, actual);
solo.clickLongOnText("Note 2");
//Clicks on Delete in the context menu
solo.clickOnText("Delete");
actual = solo.searchText("Note 2");
//Assert that Note 2 is not found
assertEquals("Note 2 is found", expected, actual);
}
}
* This is an example test project created in Eclipse to test NotePad which is a sample
* project located in AndroidSDK/samples/android-11/NotePad
*
*
* You can run these test cases either on the emulator or on device. Right click
* the test project and select Run As --> Run As Android JUnit Test
*
* @author Renas Reda, renas.reda@jayway.com
*
*/
package com.jayway.test;
import com.example.android.notepad.NotesList;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList>{
private Solo solo;
public NotePadTest() {
super(NotesList.class);
}
@Override
public void setUp() throws Exception {
//setUp() is run before a test case is started.
//This is where the solo object is created.
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
//tearDown() is run after a test case has finished.
//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
solo.finishOpenedActivities();
}
public void testAddNote() throws Exception {
solo.clickOnMenuItem("Add note");
//Assert that NoteEditor activity is opened
solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");
//In text field 0, add Note 1
solo.enterText(0, "Note 1");
solo.goBack();
//Clicks on menu item
solo.clickOnMenuItem("Add note");
//In text field 0, add Note 2
solo.enterText(0, "Note 2");
//Go back to first activity named "NotesList"
solo.goBackToActivity("NotesList");
//Takes a screenshot and saves it in "/sdcard/Robotium-Screenshots/".
solo.takeScreenshot();
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
//Assert that Note 1 & Note 2 are found
assertEquals("Note 1 and/or Note 2 are not found", expected, actual);
}
public void testEditNote() throws Exception {
// Click on the second list line
solo.clickInList(2);
// Change orientation of activity
solo.setActivityOrientation(Solo.LANDSCAPE);
// Change title
solo.clickOnMenuItem("Edit title");
//In first text field (0), add test
solo.enterText(0, " test");
solo.goBack();
boolean expected = true;
// (Regexp) case insensitive
boolean actual = solo.waitForText("(?i).*?note 1 test");
//Assert that Note 1 test is found
assertEquals("Note 1 test is not found", expected, actual);
}
public void testRemoveNote() throws Exception {
//(Regexp) case insensitive/text that contains "test"
solo.clickOnText("(?i).*?test.*");
//Delete Note 1 test
solo.clickOnMenuItem("Delete");
//Note 1 test & Note 2 should not be found
boolean expected = false;
boolean actual = solo.searchText("Note 1 test");
//Assert that Note 1 test is not found
assertEquals("Note 1 Test is found", expected, actual);
solo.clickLongOnText("Note 2");
//Clicks on Delete in the context menu
solo.clickOnText("Delete");
actual = solo.searchText("Note 2");
//Assert that Note 2 is not found
assertEquals("Note 2 is found", expected, actual);
}
}
- robotium android apk software test sample
- Android Robotium测试APK方法
- Android Test Automation Robotium VS. UIAutomator
- Android Robotium测试单个的APK方法
- Android Robotium测试单个的APK方法
- Robotium 测试Android apk安装包
- Android Robotium黑盒测试封装为Apk
- Android APK JNI sample (JAVA JNI)
- Android APK JNI sample (JAVA JNI)
- Software Test
- software test
- test(software)
- Software Test
- robotium ant创建android-test的测试方法
- 【Robotium测试】环境配置和Android test project项目创建
- Android 自动化测试—robotium(六)只有APK存在
- Android 自动化测试—robotium(六)只有APK存在
- 重签名android apk,利用robotium进行自动化测试
- java基础类型
- 别再犹豫,传智为你开启崭新未来!
- IP地址与网络分类
- Hibernate之HQL和QBC
- 使用eclipse远程调试weblogic
- robotium android apk software test sample
- 机械指令对机械的定义
- DIV与SPAN之间有什么区别
- VC中如何配置可调试项目
- 避免构造/析构函数调用虚函数(转)
- 不用插件实现类似的source insight的方法
- NodeJS 常用模块
- 机械指令对危险机械的划分
- C#制作高仿360安全卫士窗体<二>