1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 20:11:20 +00:00

Merge pull request #494 from marcbonnici/uiautomator

Uiautomator
This commit is contained in:
setrofim 2017-10-03 11:20:18 +01:00 committed by GitHub
commit 1bd19d9af3
7 changed files with 81 additions and 20 deletions

View File

@ -0,0 +1,60 @@
/* Copyright 2014-2016 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.arm.wa.uiauto;
import android.os.Bundle;
import android.util.Log;
/**
* Basic marker API for workloads to generate start and end markers for
* deliminating and timing actions. Markers are output to logcat with debug
* priority. Actions represent a series of UI interactions to time.
*
* The marker API provides a way for instruments and result processors to hook into
* per-action timings by parsing logcat logs produced per workload iteration.
*
* The marker output consists of a logcat tag 'UX_PERF' and a message. The
* message consists of a name for the action and a timestamp. The timestamp
* is separated by a single space from the name of the action.
*
* Typical usage:
*
* ActionLogger logger = ActionLogger("testTag", parameters);
* logger.start();
* // actions to be recorded
* logger.stop();
*/
public class ActionLogger {
private String testTag;
private boolean enabled;
public ActionLogger(String testTag, Bundle parameters) {
this.testTag = testTag;
this.enabled = parameters.getBoolean("markers_enabled");
}
public void start() {
if (enabled) {
Log.d("UX_PERF", testTag + "_start " + System.nanoTime());
}
}
public void stop() throws Exception {
if (enabled) {
Log.d("UX_PERF", testTag + "_end " + System.nanoTime());
}
}
}

View File

@ -79,6 +79,12 @@ public class BaseUiAutomation {
SystemClock.sleep(second * 1000);
}
//Generate a package ID
public String getPackageID(Bundle parameters) {
String packageName = parameters.getString("package_name");
return packageName + ":id/";
}
public boolean takeScreenshot(String name) {
Bundle params = getArguments();
String png_dir = params.getString("workdir");

Binary file not shown.

View File

@ -26,7 +26,6 @@ import android.support.test.uiautomator.UiWatcher;
import android.util.Log;
import com.arm.wa.uiauto.BaseUiAutomation;
import com.arm.wa.uiauto.UxPerfUiAutomation;
import org.junit.Test;
import org.junit.Before;
@ -42,19 +41,18 @@ public class UiAutomation extends BaseUiAutomation {
public static ArrayList<String> scores = new ArrayList();
public static Boolean wasError = false;
protected UxPerfUiAutomation uxPerf;
Bundle parameters;
String version;
Boolean browser;
Boolean metal;
Boolean multicore;
Integer browserToUse;
protected Bundle parameters;
protected String version;
protected Boolean browser;
protected Boolean metal;
protected Boolean multicore;
protected Integer browserToUse;
protected String packageID;
@Before
public void initialize(){
uxPerf = new UxPerfUiAutomation();
parameters = getParams();
packageID = getPackageID(parameters);
version = parameters.getString("version");
browser = parameters.getBoolean("browser");
metal = parameters.getBoolean("metal");
@ -81,7 +79,7 @@ public class UiAutomation extends BaseUiAutomation {
startTest();
dismissNetworkConnectionDialogIfNecessary();
dismissExplanationDialogIfNecessary();
waitForTestCompletion(15 * 60, "com.quicinc.vellamo:id/act_ba_results_btn_no");
waitForTestCompletion(15 * 60, packageID + "act_ba_results_btn_no");
} else {
if (browser) {
startBrowserTest(browserToUse, version);
@ -166,7 +164,7 @@ public class UiAutomation extends BaseUiAutomation {
public void startTestV3(int run, String version) throws Exception {
UiSelector selector = new UiSelector();
UiObject thirdRunButton = mDevice.findObject(selector.resourceId("com.quicinc.vellamo:id/card_launcher_run_button").instance(2));
UiObject thirdRunButton = mDevice.findObject(selector.resourceId(packageID + "card_launcher_run_button").instance(2));
if (!thirdRunButton.waitForExists(TimeUnit.SECONDS.toMillis(5))) {
if (!thirdRunButton.exists()) {
throw new UiObjectNotFoundException("Could not find three \"Run\" buttons.");
@ -174,7 +172,7 @@ public class UiAutomation extends BaseUiAutomation {
}
//Run benchmarks
UiObject runButton = mDevice.findObject(selector.resourceId("com.quicinc.vellamo:id/card_launcher_run_button").instance(run));
UiObject runButton = mDevice.findObject(selector.resourceId(packageID + "card_launcher_run_button").instance(run));
if (!runButton.waitForExists(TimeUnit.SECONDS.toMillis(5))) {
if (!runButton.exists()) {
throw new UiObjectNotFoundException("Could not find correct \"Run\" button.");
@ -209,12 +207,12 @@ public class UiAutomation extends BaseUiAutomation {
}
public void proccessTest(String metric) throws Exception{
waitForTestCompletion(15 * 60, "com.quicinc.vellamo:id/button_no");
waitForTestCompletion(15 * 60, packageID + "button_no");
//Remove watcher
mDevice.removeWatcher("stoppedWorkingDialogWatcher");
getScore(metric, "com.quicinc.vellamo:id/card_score_score");
getScore(metric, packageID + "card_score_score");
mDevice.pressBack();
mDevice.pressBack();
mDevice.pressBack();
@ -279,7 +277,7 @@ public class UiAutomation extends BaseUiAutomation {
public void dismissArrow() throws Exception {
UiSelector selector = new UiSelector();
UiObject cardContainer = mDevice.findObject(selector.resourceId("com.quicinc.vellamo:id/cards_container")) ;
UiObject cardContainer = mDevice.findObject(selector.resourceId(packageID + "cards_container")) ;
if (!cardContainer.waitForExists(TimeUnit.SECONDS.toMillis(5))) {
if (!cardContainer.exists()) {
throw new UiObjectNotFoundException("Could not find vellamo main screen");

View File

@ -25,7 +25,6 @@ import android.support.test.uiautomator.UiSelector;
import com.arm.wa.uiauto.BaseUiAutomation;
import com.arm.wa.uiauto.ActionLogger;
import com.arm.wa.uiauto.UxPerfUiAutomation;
import org.junit.Before;
import org.junit.Test;
@ -46,16 +45,14 @@ public class UiAutomation extends BaseUiAutomation {
public static final int VIDEO_SLEEP_SECONDS = 3;
public static final int LIST_SWIPE_COUNT = 5;
protected UxPerfUiAutomation uxPerf;
protected Bundle parameters;
protected String packageID;
@Before
public void initilize() {
uxPerf = new UxPerfUiAutomation();
parameters = getParams();
packageID = uxPerf.getPackageID(parameters);
packageID = getPackageID(parameters);
}
@Test