Automating repetitive workflows in Microsoft Dynamics 365 can significantly improve efficiency and reduce human errors. One frequent scenario is creating a new customer and verifying that specific fields, such as the Active Fidelity Card, are automatically populated after saving. In this article, we’ll explore how to automate this entire process using Playwright with the MCP Server.
Objective
The goal of this automated test is to:
-
Navigate to the Dynamics 365 environment
-
Sign in using secure environment-based credentials
-
Create a new customer by filling all required fields across multiple tabs (except Active Fidelity Card)
-
Save the record and confirm the data is properly stored
-
Verify that the Active Fidelity Card field is populated after saving
If the field remains empty, the test should fail.
Step-by-Step Implementation
Navigate to Dynamics 365
Access your Dynamics 365 instance using a URL similar to:
https://your-dynamics-instance.crm.dynamics.com/main.aspx?appid=<your-app-id>
Sign In Securely
Store your credentials in environment variables to avoid exposing sensitive data:
export CRMUSER="your-username"
export CRMPASS="your-password"
Create a New Customer
Fill in all required customer fields, such as:
-
First Name
-
Last Name
-
Email
-
Phone
-
Address
You can skip the Active Fidelity Card field, as it will be validated after saving.
Save the Record
Once all required data is completed, save the record and wait for the page to refresh.
Verify the Active Fidelity Card
After saving, check that the Active Fidelity Card field includes a value.
If it is empty, the automation should mark the test as failed.
Expected Result
The Active Fidelity Card field must contain a value after creating a new customer.
If it remains empty, the test is considered failed.
Sample Playwright Script
Here is a simplified JavaScript example using Playwright:
import { test, expect } from '@playwright/test';
test('Verify Active Fidelity Card after creating customer', async ({ page }) => {
await page.goto('https://your-dynamics-instance.crm.dynamics.com/main.aspx?appid=<your-app-id>');
// Login using environment variables
await page.fill('input[type="email"]', process.env.CRMUSER);
await page.click('input[type="submit"]');
await page.fill('input[type="password"]', process.env.CRMPASS);
await page.click('input[type="submit"]');
await page.waitForLoadState('networkidle');
// Create new customer
await page.click('button:has-text("New Customer")');
await page.fill('#firstname', 'TestName');
await page.fill('#lastname', 'TestSurname');
await page.fill('#email', 'test@example.com');
await page.fill('#phone', '123456789');
await page.fill('#address', 'Via Test 123');
// Save
await page.click('button:has-text("Save")');
await page.waitForTimeout(3000);
// Verify Active Fidelity Card
const fidelityCardValue = await page.textContent('#activeFidelityCard');
expect(fidelityCardValue && fidelityCardValue.trim().length > 0).toBeTruthy();
});
Best Practices
-
Use environment variables or secure vaults for credentials
-
Add error handling and screenshot capture for easier debugging
-
Adjust your DOM selectors to match your specific Dynamics 365 layout
-
Consider additional steps if MFA (multi-factor authentication) is enabled