Studio
2023.10
False
横幅背景图像
Studio 用户指南
上次更新日期 2024年4月26日

在编码自动化中使用导入的库项目

本教程将向您介绍如何在编码自动化中使用导入库项目中的对象。该示例演示了如何使用导入的库项目中的对象存储库元素和工作流。给定的场景涉及自动化 Acme 网站,会填写学生记分卡并将其添加到数据库中。

先决条件

安装 UIAutomation 活动 23.10.3 或更高版本。

1. 创建库项目

创建一个库项目以存储自动化 Acme 应用所必需的用户界面元素,特别是用于填写学生记分卡的元素。此外,在库项目中创建低代码 (.xaml) 或编码工作流 (.cs),以便稍后在另一个编码自动化中使用。
  1. 创建一个名为 AcmeLibrary 的库项目。
  2. 捕获要在“对象存储库”和“描述符”部分中使用的所有用户界面元素。
  3. “文件”组中新建一个“编码工作流”。

    在另一个项目中导入库时,此步骤对于启用对编码自动化中的对象存储库的访问至关重要。

  4. 主要的低代码工作流重命名为 Send message box,并添加具有以下文本的“消息框”活动:“您已为 Acme 中的学生添加了新的计分卡。”
    注意:您也可以按照本教程中列出的步骤将“消息框”活动重新创建为编码工作流。
  5. 保存库项目并将其发布到订阅源。

    您将在编码自动化的另一个项目中安装并使用此已发布的库。

2. 创建编码自动化

创建库项目后,将其安装到另一个项目中以利用其可重用资产,包括对象存储库元素和工作流,低代码 (.xaml) 和编码 (.cs) 均可。
提示:使用用户界面自动化 API 时,请记住,带有 IScreenDescriptorIElementDescriptor 的重载旨在与对象存储库元素一起使用,而带有 TargetAnchorableModel 的重载旨在与通过 UI Explorer 获取的原生选取器一起使用。请访问用户界面自动化 API,了解如何通过用户界面自动化 API 来利用选取器。
  1. 在“文件”组中,新建编码工作流
  2. 转到“管理包”并安装先前创建的库项目。
  3. 在“文件”组中,新建工作流
    1. 将工作流命名为 notifyStudentScoreCardAdded
    2. 导航至“活动”面板的“已安装”部分。
    3. 搜索您导入的库项目的名称(在此示例中为 AcmeLibrary)。
    4. Send message box 活动拖放到 notifyStudentScoreCardAdded 中。
      现在,notifyStudentScoreCardAdded 具有与导入的库项目中的 Send message box 工作流相同的行为。
  4. 为了增强可读性,您可以在工作流开头应用 using 语句,将导入的对象存储库应用程序定义为变量。示例如下:using app = <ProjectName>.ObjectRepository.Descriptors.<AppName>
    使用此方法,您可以轻松地按以下格式调用描述符:app.<ScreenName>.<UiElementName>
    在此示例中,我们定义了 Acme 对象存储库,如下所示:
    namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;namespace UsingImportedLibraryProjects
    {
        using AcmeApp = AcmeLibrary.ObjectRepository.Descriptors.Acme;
  5. 现在,您可以在 Acme 中自动化给定场景。首先使用开启 API 打开 Acme 登录画面。
    [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.LoginScreen); [Workflow]
            public void Execute()
            {
              // 1.Open the Acme app on the Login screen
              var AcmeLoginScreen = uiAutomation.Open(AcmeApp.LoginScreen);
  6. 使用键入 API 键入登录 Acme 所需的凭据。
    // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Password, "12345678");  // 2.Type in the necessary credentials
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Email, "john.doe2023@uipath.com");
             AcmeLoginScreen.TypeInto(AcmeApp.LoginScreen.Password, "12345678");
  7. 使用单击 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'/>"));
  8. 登录流程将转到 Acme Web 应用程序中的“仪表板”画面。因此,请使用附加 API 将焦点放在新屏幕上。
    // 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Dashboard);// 4. Focus on the Dashboard screen
    var DashboardScreen = uiAutomation.Attach(AcmeApp.Dashboard);
  9. 使用单击 API 选择网站上的“学生”条目。
    // 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);// 5. Click the Students entry
    DashboardScreen.Click(AcmeApp.Dashboard.Students);
  10. 选择“分数卡”以使用单击 API 打开“学生 - 分数卡”表单。
    // 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Dashboard.Students.ScoreCard);// 6. Click Score card, to start filling in a student score card
    DashboardScreen.Click(AcmeApp.Dashboard.Students.ScoreCard);
  11. 使用附加 API 聚焦学生 - 记分卡画面。
    // 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.StudentsScoreCard);// 7. Focus on the Score Card screen where you fill in the necessary information
    var ScoreCardScreen = uiAutomation.Attach(AcmeApp.StudentsScoreCard);
  12. 使用键入 API 和对象存储库中的元素填写“学生 - 记分卡”表单中的一半字段。
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.Tuition, "Private");ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.StudentEmail, "john.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.FirstName, "John");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.LastName, "Doe");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.ParentEmail, "johnny.doe@uipath.com");
    ScoreCardScreen.TypeInto(AcmeApp.StudentsScoreCard.Tuition, "Private");
  13. 结合使用键入 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");
  14. 使用单击 API,选择“添加分数卡详情”。
    // 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.StudentsScoreCard.AddScoreCardDetailsButton);// 10. Click the "Add score card details" button using an Object Repository descriptor
    ScoreCardScreen.Click(AcmeApp.StudentsScoreCard.AddScoreCardDetailsButton);
  15. 使用 RunWorkflow() 方法调用从库项目导入的工作流。为方法提供项目内工作流的路径。
    // 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");// 11. Invoke imported workflow from library
    RunWorkflow("notifyStudentScoreCardAdded.xaml");
  16. 关闭您打开的浏览器标签页,以便使用 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();

示例项目

要按照步骤操作并自行尝试本教程,请参阅以下示例项目:在编码自动化中使用导入的库项目。该文件还包含库项目。

  • 先决条件
  • 1. 创建库项目
  • 2. 创建编码自动化
  • 示例项目

此页面是否有帮助?

获取您需要的帮助
了解 RPA - 自动化课程
UiPath Community 论坛
Uipath 白色徽标
信任与安全
© 2005-2024 UiPath. All rights reserved.