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

创建第一个编码测试用例

This tutorial provides step-by-step instructions for creating a coded test case that types information into a web form and verifies it using UiPath® Test Manager. To automate the web form and access it, the example uses Object Repository elements and UIAutomation. You can access the sample form here.
先决条件
  1. 创建编码测试用例。从“文件”组中,选择“新建”,然后选择“编码测试用例”。
    测试用例的代码分为三部分 (Arrange-Act-Assert),与 Given-When-Then 模板类似。
    • 排列 – 设置测试数据。
    • 执行 – 执行测试用例步骤。
    • 断言 – 验证测试用例结果。
  2. 从测试应用程序中检索用户界面元素,以便在编码测试用例中使用它们。对于此示例,从网页表单中检索用户界面元素。转到“对象存储库”选项卡,然后创建一个名为 TestForm 的应用程序。
  3. 在“TestForm”应用程序中,创建一个名为“TestFormScreen”的界面,并指定打开网页表单的 Chrome 选项卡。


  4. 在“TestFormScreen”中,为每个表单字段创建一个元素,并在表单中创建按钮。用户界面元素按字母顺序升序排列。


  5. 开始使用用户界面自动化测试服务设计编码测试用例。
  6. “排列”部分中,使用 UIAutomation 服务以及开放 API 和键入 API 打开网页表单并输入测试数据。对于此示例,请使用以下代码示例:
    var screen = uiAutomation.Open(ObjectRepository.Descriptors.TestForm.TestFormScreen);
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Name, "John Doe");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Email, "john.doe@uipath.com");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Password, "1234");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.ConfirmPassword, "1234");var screen = uiAutomation.Open(ObjectRepository.Descriptors.TestForm.TestFormScreen);
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Name, "John Doe");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Email, "john.doe@uipath.com");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.Password, "1234");
                screen.TypeInto(ObjectRepository.Descriptors.TestForm.TestFormScreen.ConfirmPassword, "1234");
    
    提示:在 Studio IDE 中使用 IntelliSense。按 Ctrl+Space 键即可使用 IntelliSense 执行以下操作:
    • 自动完成代码
    • 读取 API 文档 – 读取 API 的参数。在编码自动化生态系统中,API 参数等同于活动属性。




  7. 在“操作”部分中,键入提交表单的操作。对于此示例,请使用以下代码示例:
    screen.Click("Submit");screen.Click("Submit");


  8. “断言”部分中,使用“测试”服务以及验证表达式 API 来验证“验证”中的文本是否为第 6 步中输入的用户名。对于此示例,请使用以下代码示例:
    testing.VerifyExpression(screen.GetText("Verification") == "John Doe");testing.VerifyExpression(screen.GetText("Verification") == "John Doe");


示例项目

要按照步骤自行尝试本教程,请下载以下示例项目:第一个编码测试用例

  • 示例项目

此页面是否有帮助?

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