UiAutomator简单实例----进入Settings->Language&input

本文详细介绍如何使用Eclipse和UI Automator从零开始搭建自动化UI测试环境,并通过具体示例演示了自动化测试脚本的编写、编译及在Android设备上的执行过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、新建Java工程


         Eclipse新建一个Java Project注意,不是Android Project
         Project name为AutoRunner。

2、添加JUnit库

        Libraries-->Add Library,把JUnit添加进来。


3、添加jar包

        Libraries-->Add External JARs,找到Android SDK路径,Android-SDK\platforms\android-21下面的android.jar和uiautomator.jar添加进来。


4、编辑代码

        工程路径在e:\workspace\AutoRunner,在src中新建Package,名称为com.Runner。
        在com.Runner包下新建class,名称为Runne。
        类Runner的代码如下:

package com.Runner;

import com.android.uiautomator.core.UiDevice;
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 Runner  extends UiAutomatorTestCase {
	
	public void testDemo() throws UiObjectNotFoundException {  
		//进入操作前,先用Home键进入待机界面  
		UiDevice device = getUiDevice();
		device.pressHome();
		
		//进入“系统设置”菜单
		UiObject settingApp = new UiObject(new UiSelector().text("Settings"));  
		settingApp.click();  
		//休眠3秒  
		try {  
			Thread.sleep(3000);  			
		} catch (InterruptedException e1) { 
			// TODO Auto-generated catch block  
			e1.printStackTrace();  
		}
		
		//用滚动的方式查找并进入“语言和输入法设置”菜单  
		UiScrollable settingItems = new UiScrollable( new UiSelector().scrollable(true));  
		UiObject languageAndInputItem = settingItems.getChildByText(  
				new UiSelector().text("Language & input"), "Language & input", true);  
		languageAndInputItem.clickAndWaitForNewWindow();  
	}

}

5、找到Android4.0对应的SDK id值

        Android4.0(API>=16)以上的SDK支持Uiautomator,需要找到API=16对应的SDK id值。
        cmd进入命令提示符,进入\Android-sdk\tools\目录,运行命令:
        andrid list。
        查看API大于等于16的SDK值,当前是24。


6、创建Build文件

       Android-sdk\tools\目录下,运行命令:
            android  create  uitest-project  -n  <name>  -t  <android-sdk-ID>  -p  <path>
        对应当前的实例,命令为:
        android  create  uitest-project  -n  AutoRunner  -t  24  -p  e:\workspace\AutoRunner
        其中,name指生成jar包的名字,可以自定义,android-sdk-ID就是上面看到的24pathEclipse新建的工程的路径。
        运行命令后,将会在工程的根目录下生成build.xml文件。

7、编译生成jar包

        cmd进入命令提示符,进入AutoRunner的工程目录,运行ant  build,使用ant编译生成jar包
        在e:\workspace\AutoRunner\bin目录下,生成AutoRunner.jar包
        



8、push到手机并运行jar

        adb  push  <jar文件路径>  data/local/tmp
        adb  shell  uiautomator  runtest  <jar文件名>  -c <工程中的类名,包含包名>
        对应当前的实例,命令为:
        adb  push  e:\workspace\AutoRunner\bin\AutoRunner.jar  /data/local/tmp/
        adb  shell  uiautomator  runtest  AutoRunner.jar  -c  com.Runner.Runner

        测试前提是在Home界面放置Settings的图标,步骤就是在Home界面打开Settings-->Language&input。

/**************************************************************************** ** ** This file is part of the LibreCAD project, a 2D CAD program ** ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl) ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. ** ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file gpl-2.0.txt included in the ** packaging of this file. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ** ** This copyright notice MUST APPEAR in all copies of the script! ** **********************************************************************/ #include "main.h" #include <qapplication.h> #include <QSplashScreen> QSplashScreen *splash; #ifdef RS_SCRIPTING #include <qsproject.h> #endif #include "rs_fontlist.h" #include "rs_patternlist.h" #include "rs_scriptlist.h" #include "rs_settings.h" #include "rs_system.h" #include "rs_fileio.h" #include "rs_filtercxf.h" #include "rs_filterdxf.h" #include "rs_filterdxf1.h" #include "rs_filterlff.h" #include "qg_dlginitial.h" #include "qc_applicationwindow.h" #ifndef QC_SPLASH_TXTCOL # define QC_SPLASH_TXTCOL Qt::black #endif // for image mime resources from png files extern void QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // extern void qInitImages_LibreCAD(); #endif #ifdef QC_BUILTIN_STYLE extern void applyBuiltinStyle(); #endif /** * Main. Creates Application window. * * Cleaning up #defines. */ int main(int argc, char** argv) { RS_DEBUG->setLevel(RS_Debug::D_WARNING); RS_DEBUG->print("param 0: %s", argv[0]); QCoreApplication::setApplicationName(XSTR(QC_APPNAME)); QCoreApplication::setApplicationVersion(XSTR(QC_VERSION)); QApplication app(argc, argv); // for image mime resources from png files // TODO: kinda dirty to call that explicitly QINITIMAGES_LIBRECAD(); #ifdef RS_SCRIPTING // qInitImages_librecad(); #endif for (int i=0; i<app.argc(); i++) { if (QString("--debug") == app.argv()[i]) { RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING); } } QFileInfo prgInfo( QFile::decodeName(argv[0]) ); QString prgDir(prgInfo.dirPath(true)); RS_SETTINGS->init(XSTR(QC_COMPANYKEY), XSTR(QC_APPKEY)); RS_SYSTEM->init(XSTR(QC_APPNAME), XSTR(QC_VERSION), XSTR(QC_APPDIR), prgDir); RS_FILEIO->registerFilter(new RS_FilterLFF()); RS_FILEIO->registerFilter(new RS_FilterCXF()); RS_FILEIO->registerFilter(new RS_FilterDXF()); RS_FILEIO->registerFilter(new RS_FilterDXF1()); // parse command line arguments that might not need a launched program: QStringList fileList = handleArgs(argc, argv); QString lang; QString langCmd; QString unit; RS_SETTINGS->beginGroup("/Defaults"); #ifndef QC_PREDEFINED_UNIT unit = RS_SETTINGS->readEntry("/Unit", "Invalid"); #else unit = RS_SETTINGS->readEntry("/Unit", QC_PREDEFINED_UNIT); #endif RS_SETTINGS->endGroup(); // show initial config dialog: if (unit=="Invalid") { RS_DEBUG->print("main: show initial config dialog.."); QG_DlgInitial di(NULL); di.setText("<font size=\"+1\"><b>Welcome to " XSTR(QC_APPNAME) "</b></font>" "<br>" "Please choose the unit you want to use for new drawings and your " "preferred language.<br>" "You can changes these settings later in the " "Options Dialog of " XSTR(QC_APPNAME) "."); QPixmap pxm(":/main/intro_librecad.png"); di.setPixmap(pxm); if (di.exec()) { RS_SETTINGS->beginGroup("/Defaults"); unit = RS_SETTINGS->readEntry("/Unit", "None"); RS_SETTINGS->endGroup(); } RS_DEBUG->print("main: show initial config dialog: OK"); } #ifdef QSPLASHSCREEN_H RS_DEBUG->print("main: splashscreen.."); QPixmap* pixmap = new QPixmap(":/main/splash_librecad.png"); # endif RS_DEBUG->print("main: init fontlist.."); RS_FONTLIST->init(); RS_DEBUG->print("main: init fontlist: OK"); RS_DEBUG->print("main: init patternlist.."); RS_PATTERNLIST->init(); RS_DEBUG->print("main: init patternlist: OK"); RS_DEBUG->print("main: init scriptlist.."); RS_SCRIPTLIST->init(); RS_DEBUG->print("main: init scriptlist: OK"); RS_DEBUG->print("main: loading translation.."); RS_SETTINGS->beginGroup("/Appearance"); #ifdef QC_PREDEFINED_LOCALE lang = RS_SETTINGS->readEntry("/Language", ""); if (lang.isEmpty()) { lang=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/Language", lang); } langCmd = RS_SETTINGS->readEntry("/LanguageCmd", ""); if (langCmd.isEmpty()) { langCmd=QC_PREDEFINED_LOCALE; RS_SETTINGS->writeEntry("/LanguageCmd", langCmd); } #else lang = RS_SETTINGS->readEntry("/Language", "en"); langCmd = RS_SETTINGS->readEntry("/LanguageCmd", "en"); #endif RS_SETTINGS->endGroup(); RS_SYSTEM->loadTranslation(lang, langCmd); RS_DEBUG->print("main: loading translation: OK"); #ifdef QSPLASHSCREEN_H splash = new QSplashScreen(*pixmap); splash->show(); splash->message(QObject::tr("Loading.."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: splashscreen: OK"); #endif //QApplication::setStyle(new QWindowsStyle()); //QApplication::setStyle(new QPlatinumStyle()); #ifdef QC_BUILTIN_STYLE //js: RS_DEBUG->print("main: applying built in style.."); applyBuiltinStyle(); #endif RS_DEBUG->print("main: creating main window.."); QC_ApplicationWindow * appWin = new QC_ApplicationWindow(); RS_DEBUG->print("main: setting caption"); appWin->setCaption(XSTR(QC_APPNAME)); RS_DEBUG->print("main: show main window"); appWin->show(); RS_DEBUG->print("main: set focus"); appWin->setFocus(); RS_DEBUG->print("main: creating main window: OK"); #ifdef QSPLASHSCREEN_H if (splash) { RS_DEBUG->print("main: updating splash.."); splash->message(QObject::tr("Loading..."), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); RS_DEBUG->print("main: processing events"); qApp->processEvents(); RS_DEBUG->print("main: updating splash: OK"); } #endif // Set LC_NUMERIC so that enetring numeric values uses . as teh decimal seperator setlocale(LC_NUMERIC, "C"); RS_DEBUG->print("main: loading files.."); bool files_loaded = false; for (QStringList::Iterator it = fileList.begin(); it != fileList.end(); ++it ) { #ifdef QSPLASHSCREEN_H if (splash) { splash->message(QObject::tr("Loading File %1..") .arg(QDir::convertSeparators(*it)), Qt::AlignRight|Qt::AlignBottom, QC_SPLASH_TXTCOL); qApp->processEvents(); } #endif appWin->slotFileOpen(*it, RS2::FormatUnknown); files_loaded = true; } RS_DEBUG->print("main: loading files: OK"); #ifdef QSPLASHSCREEN_H # ifndef QC_DELAYED_SPLASH_SCREEN if (splash) { splash->finish(appWin); delete splash; splash = 0; } # endif delete pixmap; #endif //app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); RS_DEBUG->print("main: app.exec()"); if (!files_loaded) { appWin->slotFileNew(); } appWin->slotRunStartScript(); int r = app.exec(); RS_DEBUG->print("main: Temporary disabled delete appWin"); // delete appWin; RS_DEBUG->print("main: finished"); return r; } /** * Handles command line arguments that might not require a GUI. * * @return list of files to load on startup. */ QStringList handleArgs(int argc, char** argv) { RS_DEBUG->print("main: handling args.."); QStringList ret; bool doexit = false; QString machine; QString input; QString output; for (int i=1; i<argc; i++) { if (QString(argv[i]).startsWith("-")==false) { QString fname = QDir::convertSeparators( QFileInfo(QFile::decodeName(argv[i])).absFilePath() ); ret.append(fname); } else if (QString(argv[i])=="--exit") { doexit = true; } } if (doexit) { exit(0); } RS_DEBUG->print("main: handling args: OK"); return ret; } 给出完整代码的注释
最新发布
07-04
<think>好的,我需要帮助用户查找关于VRFC错误代码10-634的具体信息。首先,根据用户提供的引用内容,现有的引用中并没有直接提到VRFC 10-634的错误。因此,我需要分析现有的错误代码模式,并推测可能的原因和解决方法。 首先,查看用户提供的引用内容,VRFC相关的错误通常与模块实例化、依赖关系、语法问题或配置设置有关。例如,错误10-213涉及找不到主单元,10-928涉及索引范围中的空格,10-2063是模块未找到,10-1342涉及Verilog版本声明问题,而USF-XSim-62可能与仿真器配置有关。这些错误多与模块名称拼写、路径设置、语法兼容性或工具配置相关。 考虑到错误代码10-634未被明确提及,我需要基于相似错误进行推断。可能的场景包括: 1. **模块或依赖项未正确配置**:类似10-213,可能涉及缺少必要的IP核或库文件。 2. **语法或格式问题**:如10-928中的空格问题,可能存在字符或格式错误。 3. **工具设置或版本兼容性**:像10-1342需要调整Verilog版本设置,可能需要检查项目设置或工具版本。 4. **路径或文件引用错误**:如果模块路径未正确包含,可能导致无法找到相关组件。 建议用户首先检查模块实例化的名称和路径是否正确,确认所有依赖项已正确添加。其次,检查代码中的语法是否符合工具要求的版本,如Verilog与SystemVerilog的差异。此外,检查工具配置,如仿真语言设置,可能需要切换至Verilog模式。若问题仍未解决,参考官方文档或社区资源,查找10-634的具体定义。 最后,生成相关问题以帮助用户进一步排查,例如询问配置步骤、路径设置或类似错误处理经验。需要确保回答结构清晰,并引用提供的参考资料中的相关错误案例,尽管10-634未被直接提及,但可基于现有知识进行合理建议。</think>关于VRFC错误代码10-634的具体信息,在现有公开资料中暂无明确记录[^1][^2][^3][^4][^5]。但根据Vivado工具中VRFC(Vivado Register Flow Checks)的常见错误模式,可推测以下可能原因及解决方法: ### 推测原因 1. **模块实例化冲突** - 可能因模块名与IP核名称冲突,或模块未在工程路径中正确声明。 - 检查模块命名是否与IP核重复,并确认文件路径是否包含在工程设置中[^3]。 2. **依赖项配置错误** - 类似错误`VRFC 10-213`,可能缺少必要的依赖单元(如未正确生成IP核输出文件)。 - 尝试在IP核配置中点击**Generate Output Products**,确保所有依赖文件已生成[^1]。 3. **语法兼容性问题** - 若使用SystemVerilog特性但工具设置为Verilog模式,可能触发此错误。 - 在**Project Settings > General**中,将`Target Language`改为`SystemVerilog`或调整仿真器语言设置[^4]。 ### 操作建议 1. **验证代码结构** ```verilog // 示例:检查模块声明与实例化是否匹配 module example_module(input clk, output reg data); // 实现代码 endmodule ``` - 确保实例化时名称完全一致,如`example_module inst_name(...);`。 2. **检查工程配置** - 确认IP核状态为“锁定(Locked)”且输出文件完整。 - 在Tcl控制台中运行`report_ip_status`,查看缺失的依赖项。 3. **工具版本与语法模式** - 若使用`include`或宏定义,需将文件设置为全局可见(如将`parameter.vh`放在顶层模块外)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值