当前位置:网站首页>E regression test of this featured app
E regression test of this featured app
2022-06-11 07:52:00 【zljun8210】
2013 In E people E This is a regression automation test for the characteristic applications in the tablet , Automated scripts use Java Language writing . The code is as follows :
/*
* Copyright (C)2013 Ebensz Auto Test
*
* create by [email protected]
*
* V0.2(20131108): optimize and Refactoring code:With an array called;
* V0.1(20131105): create this program;
*
* Function:
* 1. connect wlan network;
* 2. set launage;
* 3. run apps;
* 4. screencap to sdcard;
*
*/
package com.ebensz.regressiontest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiScrollable;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
public class AppTest extends UiAutomatorTestCase
{
// set varilable
static String SSID = "QAC_TS";
static String PASSWORD = "8888888888";
static String[] LEFT_SCREEN_NAME = {"Camera","device","People","Messaging","EReader","Eben Security Guards",
"Gallery"};
static String[] MID_SCREEN_NAME = {"Handwriting suite","Calendar","HwOffice","Browser","HwMail"};
public void testDemo() throws UiObjectNotFoundException
{
// press home key
int i;
getUiDevice().pressHome();
wifiConnect();
deviceInfo();
for (i=0; i<=LEFT_SCREEN_NAME.length; i++)
{
leftMove();
startLaunchApk(LEFT_SCREEN_NAME[i]);
}
for (i=0; i<=MID_SCREEN_NAME.length; i++)
{
startLaunchApk(MID_SCREEN_NAME[i]);
}
startAllApp("EnoteWriter");
startAllApp("ThemeController");
}
private void wifiConnect() throws UiObjectNotFoundException
{
getUiDevice().pressHome();
// select all apps
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
// select all apps tab
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// click all apps tab
appsTab.click();
// set screen display mode
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// set horiz mode
// appViews.setAsHorizontalList();
if (allAppsButton.exists() && allAppsButton.isEnabled()) {
// allAppsButton not display,don't exec it
allAppsButton.click();
}
// find "settings" and click it
UiObject settingsApp = appViews.getChildByText(
new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
settingsApp.clickAndWaitForNewWindow();
// verify Open screen is Settings
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.settings"));
// if not exists,then print error message
assertTrue("Unable to detect Settings", settingsValidation.exists());
// click WLAN switch wifiOn
UiObject wifiText = new UiObject(new UiSelector().text("WLAN"));
wifiText.click();
getUiDevice().click(150,150);
sleep(2000);
UiObject wifiSsid = new UiObject(new UiSelector().text(SSID));
wifiSsid.click();
// set the SSID's password
UiObject passWord = new UiObject(new UiSelector().index(1).className("android.widget.EditText"));
passWord.setText(PASSWORD);
// connect the network
UiObject connBotton = new UiObject(new UiSelector().text("Connect"));
connBotton.click();
sleep(2000);
getUiDevice().pressHome();
}
private void deviceInfo() throws UiObjectNotFoundException
{
getUiDevice().pressHome();
// select all apps
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
// select all apps tab
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// click all apps tab
appsTab.click();
// set screen display mode
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// set horiz mode
// appViews.setAsHorizontalList();
if (allAppsButton.exists() && allAppsButton.isEnabled()) {
// allAppsButton not display,don't exec it
allAppsButton.click();
}
// find "settings" and click it
UiObject settingsApp = appViews.getChildByText(
new UiSelector().className(android.widget.TextView.class.getName()), "Settings");
settingsApp.clickAndWaitForNewWindow();
// verify Open screen is Settings
UiObject settingsValidation = new UiObject(new UiSelector().packageName("com.android.settings"));
// if not exists,then print error message
assertTrue("Unable to detect Settings", settingsValidation.exists());
getUiDevice().swipe(100,900,100,200,2);
UiObject devicesInfo = new UiObject(new UiSelector().text("About phone"));
devicesInfo.click();
sleep(500);
Screencap("deviceInfo");
sleep(1000);
getUiDevice().pressHome();
}
private void startLaunchApk(String apks) throws UiObjectNotFoundException
{
// move to left home page
//leftMove();
UiObject apksButton = new UiObject(new UiSelector().text(apks));
apksButton.clickAndWaitForNewWindow();
Screencap(apks);
getUiDevice().pressBack();
getUiDevice().pressHome();
}
private void startAllApp(String apks) throws UiObjectNotFoundException
{
// run all apps page apk
// press home key
getUiDevice().pressHome();
// select all apps
UiObject allAppsButton = new UiObject(new UiSelector().description("Apps"));
allAppsButton.clickAndWaitForNewWindow();
// select all apps tab
UiObject appsTab = new UiObject(new UiSelector().text("Apps"));
// click all apps tab
appsTab.click();
// set screen display mode
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
// set horiz mode
// appViews.setAsHorizontalList();
if (allAppsButton.exists() && allAppsButton.isEnabled()) {
// allAppsButton not display,don't exec it
allAppsButton.click();
}
// find "settings" and click it
UiObject startApps = appViews.getChildByText(
new UiSelector().className(android.widget.TextView.class.getName()), apks);
startApps.clickAndWaitForNewWindow();
sleep(2000);
Screencap(apks);
getUiDevice().pressBack();
getUiDevice().pressHome();
}
private void leftMove() throws UiObjectNotFoundException
{
// press home key
getUiDevice().pressHome();
getUiDevice().pressHome();
sleep(1000);
getUiDevice().swipe(200,500,700,500,2);
sleep(1000);
}
private void Screencap(String apps) throws UiObjectNotFoundException
{
SimpleDateFormat idt = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
String SCREENCAP_PATH = "/sdcard/EAT/" + apps + "_" + idt.format(new Date());
File screen_path = new File(SCREENCAP_PATH + ".png");
sleep(1000);
getUiDevice().takeScreenshot(screen_path);
assertTrue("Screenshot file not detected in store", screen_path.exists());
sleep(1000);
}
}
边栏推荐
- 【AtCoder2387】+/- Rectangle
- 2021-10-24
- Return in foreach and break in for
- Implementation of stack (C language)
- Zero foundation self-study SQL course | outer join external connection
- How to prepare for the new PMP syllabus exam?
- Modular linear equations (Chinese remainder theorem + general solution)
- Using Tkinter to realize guessing numbers game
- 134. gas station
- 2. Graduated from this course, and the bank has outsourced testing work for more than 4 months. Talk about some real feelings
猜你喜欢

C language to achieve a simple game - minesweeping

学习《缠解论语》

批量拼接字符串

C language Yanghui triangle code

You got 8K in the 3-year function test, but you were actually pretending to work hard

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language

Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np

空间几何

Tutoriel de démarrage bladed (vidéo)

Return in foreach and break in for
随机推荐
SOCKET【5】- struct linger 用法
2022.6.6 特长生模拟
Using Tkinter to realize guessing numbers game
Tutoriel de démarrage bladed (vidéo)
[atcoder2000] leftmost ball (dp+ combination number)
A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
C language lesson 2
mpi
[atcoder1984] wide swap
Import on CSDN MD file
Detailed explanation of character function and string function (including simulation implementation)
【AtCoder2304】Cleaning
.NET C#基础(6):命名空间 - 有名字的作用域
2022.6.7 special student simulation
[atcoder2376] black and white tree (game)
Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
Socket [5] - struct linker usage
Wc2020 guessing game
Wc2020 course selection
. Net C Foundation (6): namespace - scope with name