studio
2023.10
false
UiPath logo, featuring letters U and I in white
Studio User Guide
Last updated Nov 18, 2024

Creating your first coded test case

This tutorial provides step-by-step instructions for creating a coded test case that types information into a web form and verifies it using 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.
Prerequisites
  1. Create a coded test case. From the File group, select New, and then Coded Test Case.
    The code for the test case is split into three parts (Arrange-Act-Assert), similar to the Given-When-Then template.
    • Arrange – Setup test data.
    • Act – Perform test case steps.
    • Assert – Verify the test case result.
  2. Retrieve the UI elements from your testing application, so you can use them in your Coded Test Case. For this example, retrieve the UI elements from the web form. Go to the Object Repository tab and create an application named TestForm.
  3. Inside the TestForm application, create a screen named TestFormScreen, and indicate the Chrome tab where the web form is open.


  4. Inside the TestFormScreen create an element for every form field, and buttons inside the form. The UI elements are ordered alphabetically, in ascending order.


  5. Start designing your Coded Test Case, using the UIAutomation and Testing services.
  6. In the Arrange section use the UIAutomation service along with the Open and TypeInto APIs to open the web form and input test data. For this example, use the following code sample:
    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");
    
    Tip: Use IntelliSense inside the Studio IDE. Press Ctrl+Space and use IntelliSense for:
    • Autocompleting code
    • Reading API documentation – reading the parameters of an API. In the Coded automations ecosystem, API parameters are the equivalent of activity properties.




  7. In the Act section type the action of submitting the form. For this example, use the following code sample:
    screen.Click("Submit");screen.Click("Submit");


  8. In the Assert section use the Testing service, along with the VerifyExpression API, to verify if the text inside Verification is the username input from step 6. For this example, use the following code sample:
    testing.VerifyExpression(screen.GetText("Verification") == "John Doe");testing.VerifyExpression(screen.GetText("Verification") == "John Doe");


Sample project

To follow the steps and try out the tutorial yourself, download the following sample project: First coded test case.

  • Sample project

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.