package com.mumux.androidtesting.actions.impl;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase;
import com.mumux.androidtesting.actions.Action;
import com.mumux.androidtesting.actions.argument.ActionArgument;
import com.mumux.androidtesting.actions.argument.ArgumentType;
@SuppressWarnings("unused")
public class AssertExistAction extends Action {
private String value;
public AssertExistAction() {
super("ASSERT_EXIST", false, "Assertion about a string", Category.TEST, null);
}
@Override
public ActionArgument[] getArguments() {
ActionArgument valueArgument = new ActionArgument("value", ArgumentType.STRING);
valueArgument.setValue(value);
return new ActionArgument[]{valueArgument};
}
@Override
public void setValues(Object[] values) {
value = values[0].toString();
}
@Override
public String run(UiAutomatorTestCase uiAutomatorTestCase, Runtime runtime) {
// Find a specific String in the screen
UiObject uiObject = new UiObject(new UiSelector().textContains(value));
if (!uiObject.exists()) {
return "value " + value + " not found";
}
return null;
}
}