- 入门指南
- 设置和配置
- 自动化项目
- 依赖项
- 工作流类型
- 控制流程
- 文件比较
- 自动化最佳实践
- 源代码控件集成
- 调试
- 日志记录
- 诊断工具
- 工作流分析器
- 变量
- 参数
- 导入的命名空间
- 编码自动化
- 基于触发器的 Attended 自动化
- 对象存储库
- ScreenScrapeJavaSupport 工具
- 扩展程序
- Studio 测试
- 故障排除

Studio 用户指南
在编码自动化中使用导入的库项目
本教程将向您介绍如何在编码自动化中使用导入库项目中的对象。该示例演示了如何使用导入的库项目中的对象存储库元素和工作流。给定的场景涉及自动化 Acme 网站,会填写学生记分卡并将其添加到数据库中。
先决条件
- 安装“用户界面自动化活动”版本 23.10.13 或更高版本。
备注:
我们建议您使用与您正在处理的主版本相对应的最新次要版本。 例如,如果您正在使用活动包的 23.10 主要版本,我们建议您将其升级到可用的最新次要版本(
23.10.x)。 - 发布 Acme 库示例,并将其安装在您正在进行的项目中。
1. 创建库项目
创建一个库项目以存储自动化 Acme 应用所必需的用户界面元素,特别是用于填写学生记分卡的元素。此外,在库项目中创建低代码 (.xaml) 或编码工作流 (.cs),以便稍后在另一个编码自动化中使用。
- 创建一个名为
AcmeLibrary的库项目。 - 捕获要在“对象存储库”和“描述符”部分中使用的所有用户界面元素。
- 从“文件”组创建新的编码工作流。 此步骤对于在另一个项目中导入库时,在编码自动化中启用对对象存储库的访问至关重要。
- 将主要的低代码工作流重命名为
Send message box,并添加具有以下文本的“消息框”活动:“您已为 Acme 中的学生添加了新的计分卡。”备注:您也可以按照本教程中概述的步骤将“消息框”活动重新创建为编码工作流。
- 将库项目保存并发布到订阅源。 您将在编码自动化中的另一个项目中安装和使用此已发布库。
2. 创建编码自动化
创建库项目后,将其安装到另一个项目中以利用其可重用资产,包括对象存储库元素和工作流,低代码 (.xaml) 和编码 (.cs) 均可。
使用 UI Automation 编码的自动化 API 时,请记住,带有 IScreenDescriptor 或 IElementDescriptor 的重载旨在与对象存储库元素一起使用,而带有 TargetAnchorableModel 的重载旨在与通过 UI Explorer 获取的原生选取器一起使用。请访问“用户界面自动化的编码自动化 API”,了解如何通过用户界面自动化的编码自动化 API 使用选取器。
-
在“文件”组中,新建编码工作流。
-
转到“管理包”,然后安装您之前创建的库项目。
-
在“文件”组中,新建工作流。
- 将工作流命名为
notifyStudentScoreCardAdded。 - 导航到“活动”面板,然后进入“已安装”部分。
- 搜索您导入的库项目的名称(在此示例中为
AcmeLibrary)。 - 将
Send message box活动拖放到notifyStudentScoreCardAdded。现在,notifyStudentScoreCardAdded具有与导入的库项目中的Send message box工作流相同的行为。
- 将工作流命名为
-
为了增强可读性,您可以在工作流开头应用
using语句,将导入的对象存储库应用程序定义为变量。示例如下:using app = <ProjectName>.ObjectRepository.Descriptors。
使用此方法,您可以轻松地按以下格式调用描述符:app.<AppName>.<ScreenName>.<UiElementName>
在此示例中,我们定义了 Acme 对象存储库,如下所示:
namespace UsingImportedLibraryProjects
{
using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors;
namespace UsingImportedLibraryProjects
{
using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors;
- 现在,您可以在 Acme 中对给定场景进行自动化。首先使用 Open 编码自动化 API 打开 Acme 登录屏幕。
[Workflow] public void Execute() { // 1.Open the Acme app on the Login screen var AcmeLoginScreen = uiAutomation.Open(AcmeApp.Acme.LoginScreen);[Workflow] public void Execute() { // 1.Open the Acme app on the Login screen var AcmeLoginScreen = uiAutomation.Open(AcmeApp.Acme.LoginScreen); - 使用 TypeInto 编码自动化 API 键入登录 Acme 所需的凭据。
// 2.Type in the necessary credentials AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Email, "john.doe2023@uipath.com"); AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Password, "12345678");// 2.Type in the necessary credentials AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Email, "john.doe2023@uipath.com"); AcmeLoginScreen.TypeInto(AcmeApp.Acme.LoginScreen.Password, "12345678"); - 使用 Click 编码自动化 API 和原生选取器,单击“登录”按钮。
// 3.Use a native selector to click the Login button AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>"));// 3.Use a native selector to click the Login button AcmeLoginScreen.Click(Target.FromSelector("<webctrl tag='BUTTON' type='submit'/>")); - 登录流程将转到 Acme Web 应用程序中的“仪表板”屏幕。因此,您可以使用 Attach 编码自动化 API,专注于新打开的屏幕。
// 4. Focus on the Dashboard screen var DashboardScreen = uiAutomation.Attach(AcmeApp.Acme.Dashboard);// 4. Focus on the Dashboard screen var DashboardScreen = uiAutomation.Attach(AcmeApp.Acme.Dashboard); - 使用 Click 编码自动化 API,选择网站上的“学生”条目。
// 5. Click the Students entry DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students);// 5. Click the Students entry DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students); - 选择“分数卡”,以使用 Click 编码自动化 API 打开“学生 - 分数卡”表单。
// 6. Click Score card, to start filling in a student score card DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students.ScoreCard);// 6. Click Score card, to start filling in a student score card DashboardScreen.Click(AcmeApp.Acme.Dashboard.Students.ScoreCard); - 使用 Attach 编码自动化 API,专注于“学生 - 分数卡”屏幕。
// 7. Focus on the Score Card screen where you fill in the necessary information var ScoreCardScreen = uiAutomation.Attach(AcmeApp.Acme.StudentsScoreCard);// 7. Focus on the Score Card screen where you fill in the necessary information var ScoreCardScreen = uiAutomation.Attach(AcmeApp.Acme.StudentsScoreCard); - 使用 TypeInto 编码自动化 API 和对象存储库中的元素填写“学生 - 分数卡”表单中的一半字段。
ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.FirstName, "John"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.LastName, "Doe"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.Tuition, "Private");ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.FirstName, "John"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.LastName, "Doe"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com"); ScoreCardScreen.TypeInto(AcmeApp.Acme.StudentsScoreCard.Tuition, "Private"); - 将 TypeInto 编码自动化 API 与通过 UI Explorer 发现的原生选取器配合使用,填写表单中的其余字段。
ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best");ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='mathematics' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='physics' tag='INPUT' />"), "B"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='biology' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='chemistry' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='geography' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='history' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='english' tag='INPUT' />"), "A"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='computer Science' tag='INPUT' />"), "C"); ScoreCardScreen.TypeInto(Target.FromSelector("<webctrl id='professorComments' tag='INPUT' />"), "The student is doing okay, very hardworking and does its best"); - 使用 Click 编码自动化 API,选择“添加分数卡详情”。
// 10. Click the "Add score card details" button using an Object Repository descriptor ScoreCardScreen.Click(AcmeApp.Acme.StudentsScoreCard.AddScoreCardDetailsButton);// 10. Click the "Add score card details" button using an Object Repository descriptor ScoreCardScreen.Click(AcmeApp.Acme.StudentsScoreCard.AddScoreCardDetailsButton); - 使用
RunWorkflow()方法调用从库项目导入的工作流。为方法提供项目内工作流的路径。// 11. Invoke imported workflow from library RunWorkflow("notifyStudentScoreCardAdded.xaml");// 11. Invoke imported workflow from library RunWorkflow("notifyStudentScoreCardAdded.xaml"); - 关闭您打开的浏览器标签页,以便使用
Dispose()编码自动化 API 对该场景进行自动化。// 12. Close the applications/browsers you opened, to finish he automation ScoreCardScreen.Dispose();// 12. Close the applications/browsers you opened, to finish he automation ScoreCardScreen.Dispose();
示例项目
要按照步骤操作并自行尝试本教程,请参阅以下示例项目:在编码自动化中使用导入的库项目。该文件还包含库项目。