loading
0%

Hello-Site.ru. Бесплатный конструктор сайтов.

Stand with Ukraine! Support here

How to automate acceptance testing in Business Central with the page scripting tool

Oleksandr Shevchuk, Technical Lead of Xpand:

Introduction

User Acceptance Testing (UAT) is an important phase in the software development lifecycle, which ensures that the system aligns with business requirements before deployment. Normally, UAT should be performed implementing any change that might impact your solution, such as upgrading to a new Business Central version, implementing new change requests, fixing bugs, or installing third-party add-ons. At the same time, manually testing all user flows is often complex and time-consuming, which is where automation of routine or repetitive steps can make a real difference.

In Microsoft Dynamics 365 Business Central, the page scripting tool offers a powerful way to automate testing business processes, allowing users to record and replay their interactions directly in the web client. This automation minimizes manual effort, enhances test accuracy, and optimizes testing workflows.

In this article, we explore the use of the page scripting tool for automating acceptance testing in Business Central, covering its capabilities, usage scenarios, setup prerequisites, and best practices.

Capabilities

The page scripting tool records user actions in the Business Central web client and allows you to replay these recordings to automatically replicate the exact same steps. As the recording is replayed, you receive real-time status feedback on whether an action succeeds or fails. This tool can be used on any type of Business Central environment, including on-premises, online (production and sandbox), and Docker.

The page scripting tool offers several main features:

  • Recording user interactions within the Business Central web client. This allows users to capture every action performed on the interface for replay.

During the recording process, you can do the following:

  • Copy and paste control values
  • Validate control values
  • Use session info
  • Edit steps
  • Make steps conditional
  • Add a wait step
  • Use Microsoft Power Fx expressions
  • Handle optional pages
  • Replaying recorded interactions to validate system behavior. Once recorded, actions can be replayed to ensure that the system responds as expected.

During the replaying process you can do the following:

  • Move a step forward or backward
  • Go back to the start
  • Run to a given step
  • Saving and sharing recordings to standardized testing processes. Users can store and share recorded scripts, enabling consistent testing across different teams.
  • Running scripts in CI/CD pipelines for continuous testing. This allows you to run page scripts in your own pipelines, using the stand-alone bc-replay script player.

Common usage scenarios

The page scripting tool can be applied in various testing and automation scenarios within Business Central. Below are some examples of the most common and beneficial ways to leverage this tool:

  • Validating new features and customizations before deploying them to production.
  • Regression testing to ensure updates do not break existing functionality
  • User role-based testing to verify that permissions and access controls are working correctly for different roles within the organization.
  • Automating repetitive manual testing tasks to save time and resources.
  • Training and onboarding by sharing recorded user interactions.

Prerequisites

Before using the page scripting tool, ensure the following requirements are met:

  • Business Central is updated to a version that supports the Page Scripting Tool (Business Central 2024 Release Wave 1 or later).
  • To record, your user account must have the PAGESCRIPTING - REC permission set.
  • To play back a recording, your user account must have the PAGESCRIPTING - PLAY permission set.
  • A web browser supported by Business Central is used.

How to use the page scripting tool (basic scenario)

The Page Scripting Tool follows a simple workflow: Record, Play, Save, and Share.

Record a page script

  1. Open Business Central and navigate to the page you want to start recording.
  2. In the upper-right corner, select the Settings > Page Scripting



  3. Select the Start new button or the New recording button in the control bar at the top of the Page Scripting pane.



  4. Go through the steps that you want to record.
    For example: open Items list page > apply filters by Item No. > open Item Card page for filtered item > modify Unit Price field value > close Item Card.
  5. Once finished, click Stop Recording.



  6. To play back the recording right away, select the Play button.

Play a recording

  1. Open the page scripting tool.
  2. Select the Open button in the Page Scripting pane or the Open recording button in the control bar.
  3. Locate and open the corresponding YAML file, and then select the Play button.
  4. Verify if the expected results are achieved.

Save a recording to a file

  1. To save the recording to YAML file so you can run it later or share it with someone, select the Save button in the control bar.
  2. Choose a location and save the script.

Share a recording as a link

  1. To share a recording as a link, select Share > Copy Link in the control bar.
  2. Copy the link and send it to team members.
  3. Recipients can access the recording for review or testing purposes.

Define parameters in the existing script

To make your script more flexible, you can define specific variables (parameters) instead of relying on hardcoded values. Here’s the process:

  1. Open and edit the YAML file containing the recorded script.
  2. Add parameters for the values you want to change dynamically.
  3. Replace the hardcoded values in the script with references to these parameter.



  4. Open the edited file, and then select the Play button.



Combining multiple scripts into a single YAML file

It’s always recommended to split a complex process into smaller steps. Smaller, focused scripts are easier to maintain (fewer lines to update or debug) and reusable across different user flows. Such scripts can be tested independently before combining them into a larger process.

To combine multiple scripts into one file:

  1. Record different parts of your user flow as individual page scripts and save each to a separate file.
  2. Create a new YAML file in the same folder where your individual step scripts are stored.

  3. In the new YAML file, add references to the step scripts that should be included in the main user flow.



  4. Open the edited file, and then select the Play button.



Run page scripts in CI\CD pipelines

You can execute page scripts in your own pipelines using the standalone bc-replay script player, which is distributed as npm (Node Package Manager) package.

Prerequisites

Your machine must meet the following requirements:

  • NodeJs version 16.14.0 or later
  • Windows PowerShell 7 or later.

Preparation

Create the following folders on your machine:

  • A folder for the BC replay installation (e.g. c:\bc-replay).
  • A folder for storing the recorded scripts (e.g. c:\bc-replay\recordings).
  • A folder for storing the test results (e.g. c:\bc-replay\results).

Install BC replay

  1. Run Window PowerShell as an administrator.
  2. At the command prompt, run the following command to change to the BC replay installation folder: cd c:\bc-replay



  3. Run the following command to add @microsoft/bc-replay and install playwright:



Run scripts

To run the scripts, you need to know the URL of your Business Central web client

  1. Copy the scripts you want to run into the scripts folder (e.g. c:\bc-replay\recordings)



  2. Execute a specific script (e.g., BasicUserFlow.yml) by running:
    npx replay ".\recordings\BasicUserFlow.yml" -StartAddress [YourWebClientURL] -ResultDir ".\results"
    When the test run completes, results are displayed in the console.



  3. To view the result of the last run as a detailed report, use the following command:
    npx playwright show-report ".\results\playwright-report"



    This automatically opens a browser tab with the results report, where you can see any execution errors, step details, and a video recording of the page script execution



Best Practices

To maximize efficiency when using the page scripting tool, consider the following recommendations:

  • Begin recording from a well-known location (for example, the Role Center). Remember that playback always starts from the current page.
  • Use descriptive script names to easily identify different test cases.
  • When selecting a value in a grid, filter it so that the desired value appears first.
  • Whenever possible, create new entities to use in a test. For example, create a new customer for the new sales order test.
  • Try not to depend on data that might not be available during playback.
  • Use parameters to update values in a single place instead of searching through the entire script.
  • Minimize hardcoded values to simplify script maintenance and reduce errors.
  • Divide recordings into smaller parts for easier maintenance.

Limitations

While the page scripting tool is powerful, it has some limitations:

  • It is not a generic HTML automation tool, for example, it cannot automate control add-ins, embedded Power BI reports, or anything else outside the Business Central web client experience.
  • Multiple line selections aren't recorded as expected. If you select multiple records in a list during a recording, only the last line selection is recorded and played back.
  • May require manual updates if the UI changes significantly, as recorded scripts might not work correctly after major interface modifications.

Conclusion

The page scripting tool in Business Central offers an efficient way to automate acceptance testing, ensuring that business processes continue to function correctly after code changes. You can record key user flows once and then replay those recordings whenever you upgrade to a new Business Central version, implement new change requests, or fix significant bugs, eliminating the need to manually repeat each scenario every time. After running these scripts, you can also generate interactive reports detailing any identified issues and even watch video replays of the execution steps for further analysis and debugging.

Implementing the page scripting tool wisely in your UAT strategy can be a real game-changer that will boost overall efficiency, reduce risk, and improve the entire development lifecycle of your Business Central solution.

References

For more detailed information refer to the official Microsoft resources:

Do you happen to have any knowledge about Xpand?

Xpand is a product and service software development company with over 14 years of market experience and a Microsoft Partner since 2016, assisting organizations worldwide in managing their Microsoft Dynamics ERP and CRM systems. We provide a broad range of services for clients and partners, including implementation and development for Microsoft Dynamics 365 Business Central, as well as upgrades from earlier versions like Navision Financials 2.0. Learn more about our services at https://www.xpandsoftware.com/services.

Curious about the redesign of work with files to make a Business Central extension cloud-ready? Read the full article  https://www.xpandsoftware.com/blogs/business-centr...


83