- 入门指南
- 设置和配置
- 自动化项目
- 依赖项
- 工作流类型
- 控制流程
- 文件比较
- 自动化最佳实践
- 源代码控件集成
- 调试
- 日志记录
- 诊断工具
- 工作流分析器
- 变量
- 参数
- 导入的命名空间
- 编码自动化
- 基于触发器的 Attended 自动化
- 录制
- 用户界面元素
- 选取器
- 对象存储库
- 数据抓取
- 图像与文本自动化
- Citrix 技术自动化
- RDP 自动化
- VMware Horizon 自动化
- Salesforce 自动化
- SAP 自动化
- macOS 用户界面自动化
- ScreenScrapeJavaSupport 工具
- Webdriver 协议
- 扩展程序
- Studio 测试
- 故障排除

Studio 用户指南
简介
Coded automations allow you to create automations using code instead of drag-and-drop activities, allowing collaborative work on complex projects. In coded workflows and test cases, you can use UiPath services (equal to activity packages), coded automation APIs (similar to activities), external .NET NuGet packages, and your custom C# classes in UiPath Studio. This makes it easy to integrate with external systems, databases, APIs, and other services.
编码工作流的行为与标准工作流相同,这意味着也可以使用“调用工作流文件”活动从标准 UiPath 工作流调用编码工作流,反之亦然。
此外,代码中定义的类型(例如枚举)可以用作标准 UiPath 工作流中的输入。
编码自动化可以分为三种类型:
- 编码工作流 – 用于以代码形式设计工作流。
- 编码测试用例 – 用于设计测试用例。
- 代码源文件 – 用于创建稍后可以在其他编码文件类型中调用的代码。
以下是使用编码自动化的一些好处:
- 提高生产力 – 如果您熟悉编码或脚本编写,则可以利用您的技能来提高生产力。在熟悉的编码环境中工作可让您开发更高效的自动化。
- 复杂性管理 – 编码自动化为管理复杂的自动化场景提供了灵活的解决方案。通过使用代码,您可以实现自定义逻辑、管理异常并创建可重用的函数。
- 混合自动化 – 您可以将编码自动化与低代码自动化互换使用。这促进了两种方法之间的无缝集成,使您能够创建灵活的自动化解决方案。
- 提高性能 – 编码自动化使您能够优化自动化工作流以提高性能。通过使用代码,您可以实施特定算法,以更快地执行自动化。
- 可读性 – 编码自动化允许您创建结构化代码,从而提高代码可读性。如果您组织代码并记录,则可以轻松维护代码并与其他协作者共享。
编码自动化采用结构化设计,其中包含命名空间、帮助程序类和入口点方法。编码自动化框架允许您使用 C# 编程语言编写自动化。
请遵循以下部分所述的编码自动化的详细结构。
创建编码自动化时,系统会使用 Studio 项目的名称自动生成命名空间。例如,如果您的 Studio 项目名为“我的项目”,则所有编码自动化的命名空间均为“我的项目”。
此外,如果您在 Studio 项目的文件夹中创建编码自动化,则命名空间将是项目的名称和文件夹的名称。例如,如果您的 Studio 项目名为“我的项目”,而文件夹名为“位置”,则命名空间将为“我的项目.位置”。
CodedWorkflow
部分类。根据项目中已安装的活动包,此类为自动化提供对服务(相当于活动包)必要接口的访问权限。
编码工作流
CodedWorkflow
部分类,创建类型为 CodedAutomationExample : CodedWorkflow
的关系。这意味着 CodedAutomationExample
类从 CodedWorkflow
类继承了属性、方法和功能。本质上,该类可以访问和利用 CodedWorkflow
类中定义的功能,从而为编码自动化奠定了基础,使构建和自定义自动化的行为变得更加容易。
CodedWorkflow
类被声明为部分类,从而允许您通过在代码源文件中定义相同的部分 CodedWorkflow
类来扩展其功能。通过这种方式,您可以添加新的字段和方法,以进一步自定义编码自动化的行为。您可以使用此方法实现专门用于编码测试用例的“前”和“后”接口。
CodedWorkflow
分部类继承 CodedWorkflowBase
类。
编码工作流库
CodedWorkflowBase
类包含编码自动化继承的内置功能。此类包含用于管理工作流实例、运行时访问、处理服务容器以及配置环境上下文的方法和特定属性。CodedWorkflowBase
类还提供了另一种单独的日志记录方法,您可以自定义该方法。
CodedWorkflowBase
类。
CodedWorkflowBase
方法:
方法 | 描述 |
---|---|
ICodedWorkflowServices services 注意:我们建议您通过
services 类及其相应服务使用 Log 、BuildClient 和 RunWorkflow 方法,而不是将其用作独立的现成方法。
| 提供对编码工作流可用服务的访问权限,例如:
|
serviceContainer(ICodedWorkflowServiceContainer) 注意:这已替换为
ICodedWorkflowServices services 。如果继续使用此语法,您将收到警告,警告会提示您使用新的 services.Container 语法。
| 提供对特定于当前编码工作流的依赖项注入容器的访问权限。此容器称为服务容器,可用于检索已在其中注册的服务实例。 |
GetRunningJobInformation() | 在编码工作流的上下文中检索当前正在运行的作业的相关信息。该方法访问 executorRuntime 对象的 RunningJobInformation 属性,该属性保存有关作业状态、进度、参数和时间戳的信息。
|
Log(string message, LogLevel level = LogLevel.Info, IDictionary<string, object> additionalLogFields = null) | 将其他日志字段添加到具有指定属性的日志消息。 |
RunWorkflow(string
workflowFilePath, IDictionary<string, object> inputArguments = null, TimeSpan? timeout = null, bool isolated = false,
InvokeTargetSession targetSession = InvokeTargetSession.Current) | 提供在给定工作流运行时的上下文中执行工作流的结构。它可以设置参数,处理潜在的隔离并启动工作流执行。返回的任务提供已执行工作流的结果,包括其输出和输入/输出参数。 |
RunWorkflowAsync(string
workflowFilePath, IDictionary<string, object> inputArguments = null, TimeSpan? timeout = null, bool isolated = false,
InvokeTargetSession targetSession = InvokeTargetSession.Current) | 提供在给定工作流运行时的上下文中异步执行工作流的结构。它可以设置参数,处理潜在的隔离并启动工作流执行。返回的任务提供已执行工作流的结果,包括其输出和输入/输出参数。 |
DelayAsync(TimeSpan time) 和 DelayAsync(int delayMs) | 在指定的一段时间内异步暂停执行。 |
Delay(TimeSpan time) 和 Delay(int delayMs) | 在指定的时间段内暂停执行。 |
HttpClient BuildClient (string scope = "Orchestrator", bool force = true) | 构建具有指定作用域和访问令牌的 HTTP 客户端。 |
RegisterServices (ICodedWorkflowsServiceLocator serviceLocator) | 将服务(活动包)注册到编码工作流的服务定位器。当您要将自定义服务注入依赖项注入容器时,可以覆盖它。在此处了解如何创建和使用自定义服务(编码活动包)。 |
相关文章
Execute()
,并属性化为 Workflow
或 TestCase
。您可以更改方法的名称,只要将其归为 Workflow
或 TestCase
。
Coded Workflow
类的 Execute()
方法([TestCase]
或 [Workflow]
)。
在此方法中,您可以添加输入和/或输出参数,这些参数相当于低代码自动化中的 In、Out 或 In/Out 参数。浏览“使用输入和输出参数”教程,了解如何在编码自动化中使用参数。
Execute()
方法,这使编码工作流和测试用例易于识别为入口点。
项目兼容性
您只能在 Windows 和跨平台项目中使用编码自动化。
System.Activities
is not only an activity package in low-code automations, but also a service in coded automations. Similarly to the activities inside an activity package, a service has coded automation APIs that you can use to create coded automations.
可在编码自动化内部使用的服务如下:
服务 | 版本 |
---|---|
System.Activities | 23.10.2 及更高版本 |
UiAutomation.Activities | 23.10.3 及更高版本 |
Testing.Activities | 23.10.0 及更高版本 |
MobileAutomation.Activities | 24.10.0 及更高版本 |
Mail.Activities | 1.22.1 及更高版本 |
Excel.Activities | 2.24.1 及更高版本 |
GSuite.Activities | 2.6.21 及更高版本 |
Presentations.Activities | 1.14.1 及更高版本 |
MicrosoftOffice365.Activities | 2.6.21 及更高版本 |
要在编码自动化中使用活动包,请执行以下步骤:
- Download the activity package, equal to a service, similar to how you would in low-code automations. This provides you with a collection of coded automation APIs to use in your code.
- Call the coded automation APIs within the services using the format: service.API. For instance, if you want to use the GetAsset coded automation API, you would call it as
system.GetAsset
. - Coded automation APIs have parameters instead of properties. After calling a coded automation API, you can configure its parameters by providing values between parentheses. For example, if you have an asset in the Orchestrator instance that you’re connected to, called
Email Address
, then you can pass this asset’s name as aString
to the coded automation API:system.GetAsset("Email Address")
.