Java Code Examples for androidx.test.uiautomator.BySelector#pkg()

The following examples show how to use androidx.test.uiautomator.BySelector#pkg() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenApplication.java    From za-Farmer with MIT License 4 votes vote down vote up
@Override
protected void runSelf() throws Exception {

    //Part One 输入app版本log

    PackageInfo info = InstrumentationRegistry.getContext().getPackageManager().getPackageInfo(this.getPackageName(), 0);
    String appversion = info.versionName;
    LogUtils.getInstance().info("appversion" + appversion);


    int sdk = VERSION.SDK_INT;

    if (this.clear) {
        //清掉缓存

        if (sdk < 21) {
            //清缓存待定
            LogUtils.getInstance().info("sdk版本小于api21,清缓后续处理");
        } else {

            String clearoutput = getUiDevice().executeShellCommand("pm clear " + this.getPackageName());
            LogUtils.getInstance().info("pm clear " + clearoutput);
        }
    }


    Context mContext = InstrumentationRegistry.getContext();
    Intent myIntent = mContext.getPackageManager().getLaunchIntentForPackage(this.getPackageName());
    String AppStartActivity = myIntent.getComponent().getClassName();

    if (sdk < 21) {
        //安卓版本5.0以下的启动方式
        mContext.startActivity(myIntent);

    } else {
        //安卓版本5.0以上的启动方式
        String startNoClearoutput = getUiDevice().executeShellCommand("am start -n " + this.getPackageName() + "/" + AppStartActivity);
        LogUtils.getInstance().info(startNoClearoutput);
    }

    BySelector bySelector = By.base();
    bySelector.pkg(this.getPackageName());
    getElement(bySelector, 10000);


    screenshot(TYPE_LOG_SUCCESS);

}
 
Example 2
Source File: BaseElementHandler.java    From za-Farmer with MIT License 4 votes vote down vote up
public BySelector getElementSelector() {
    BySelector bySelector = By.base();

    if (this.elementId != null) {
        bySelector.res(this.elementId);
    }

    if (this.elementText != null) {
        bySelector.text(this.elementText);
    }

    if (this.elementDesc != null) {
        bySelector.desc(this.elementDesc);
    }

    if (this.elementClazz != null) {
        bySelector.clazz(this.elementClazz);
    }

    if (this.elementPackage != null) {
        bySelector.pkg(this.elementPackage);
    }

    if (this.elementTextDesc != null) {
        bySelector.setCustomCheckCriteria(new customCheckCriteria(this.elementTextDesc));
    }

    //contains

    if (this.elementIdContains != null) {
        bySelector.res(containsPattern(this.elementIdContains));
    }

    if (this.elementTextContains != null) {
        bySelector.textContains(this.elementTextContains);
    }

    if (this.elementDescContains != null) {
        bySelector.descContains(this.elementDescContains);
    }

    if (this.elementClazzContains != null) {
        bySelector.clazz(containsPattern(this.elementClazzContains));
    }

    if (this.elementPackageContains != null) {
        bySelector.pkg(containsPattern(this.elementPackageContains));
    }

    if (this.elementTextDescContains != null) {
        bySelector.setCustomCheckCriteria(
                new customCheckCriteria(containsPattern(this.elementTextDescContains))
        );
    }

    //pattern

    if (this.elementIdPattern != null) {
        bySelector.res(Pattern.compile(this.elementIdPattern));
    }

    if (this.elementTextPattern != null) {
        bySelector.text(Pattern.compile(this.elementTextPattern));
    }

    if (this.elementDescPattern != null) {
        bySelector.desc(Pattern.compile(this.elementDescPattern));
    }

    if (this.elementClazzPattern != null) {
        bySelector.clazz(Pattern.compile(this.elementClazzPattern));
    }

    if (this.elementPackagePattern != null) {
        bySelector.pkg(Pattern.compile(this.elementPackagePattern));
    }

    if (this.elementTextDescPattern != null) {
        bySelector.setCustomCheckCriteria(
                new customCheckCriteria(Pattern.compile(this.elementTextDescPattern))
        );
    }

    return bySelector;
}