azure-resource-manager-playwright-dotnet
microsoft/skills
Gérez les espaces de travail Microsoft Playwright Testing via Azure Resource Manager : créez, mettez à jour et supprimez des espaces de travail, vérifiez la disponibilité des noms et gérez les quotas à l’aide du SDK .NET.
...Développer toutAzure.ResourceManager.Playwright (.NET)
SDK du plan de gestion pour le provisionnement et la gestion des espaces de travail Microsoft Playwright Testing via Azure Resource Manager.
⚠️ Gestion vs Exécution des tests
- Ce SDK (Azure.ResourceManager.Playwright) : Créer des espaces de travail, gérer les quotas, vérifier la disponibilité des noms
- SDK d'exécution des tests (Azure.Developer.MicrosoftPlaywrightTesting.NUnit) : Exécuter des tests Playwright à grande échelle sur des navigateurs cloud
Installation
dotnet add package Azure.ResourceManager.Playwright
dotnet add package Azure.Identity
Versions actuelles : Stable v1.0.0, Aperçu v1.0.0-beta.1
Variables d'environnement
AZURE_SUBSCRIPTION_ID=<votre-id-abonnement> # Obligatoire : ID d'abonnement Azure
AZURE_TOKEN_CREDENTIALS=prod # Obligatoire uniquement si DefaultAzureCredential est utilisé en production
AZURE_TENANT_ID=<id-locataire> # Pour l'authentification par principal de service (facultatif)
AZURE_CLIENT_ID=<id-client> # Pour l'authentification par principal de service (facultatif)
AZURE_CLIENT_SECRET=<secret-client> # Pour l'authentification par principal de service (facultatif)
</secret-client></id-client></id-locataire></votre-id-abonnement>Authentification
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Playwright;
// Développement local : DefaultAzureCredential. Production : définir AZURE_TOKEN_CREDENTIALS=prod ou AZURE_TOKEN_CREDENTIALS=<identifiant_crédentiel_spécifique>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Ou utiliser un identifiant de crédit spécifique directement en production :
// Voir https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
// Obtenir l'abonnement
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
new ResourceIdentifier($"/subscriptions/{subscriptionId}"));
</identifiant_crédentiel_spécifique>Hiérarchie des ressources
ArmClient
└── SubscriptionResource
├── PlaywrightQuotaResource (quotas au niveau de l'abonnement)
└── ResourceGroupResource
└── PlaywrightWorkspaceResource
└── PlaywrightWorkspaceQuotaResource (quotas au niveau de l'espace de travail)
Flux de travail principal
1. Créer un espace de travail Playwright
using Azure.ResourceManager.Playwright;
using Azure.ResourceManager.Playwright.Models;
// Obtenir le groupe de ressources
var resourceGroup = await subscription
.GetResourceGroupAsync("mon-groupe-de-ressources");
// Définir l'espace de travail
var workspaceData = new PlaywrightWorkspaceData(AzureLocation.WestUS3)
{
// Facultatif : Configurer l'affinité régionale et l'authentification locale
RegionalAffinity = PlaywrightRegionalAffinity.Enabled,
LocalAuth = PlaywrightLocalAuth.Enabled,
Tags =
{
["Équipe"] = "Exp Dev",
["Environnement"] = "Production"
}
};
// Créer l'espace de travail (opération longue)
var workspaceCollection = resourceGroup.Value.GetPlaywrightWorkspaces();
var operation = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"mon-espace-de-travail-playwright",
workspaceData);
PlaywrightWorkspaceResource workspace = operation.Value;
// Obtenir l'URI du plan de données pour exécuter les tests
Console.WriteLine($"URI du plan de données : {workspace.Data.DataplaneUri}");
Console.WriteLine($"ID de l'espace de travail : {workspace.Data.WorkspaceId}");
2. Obtenir un espace de travail existant
// Obtenir par nom
var workspace = await workspaceCollection.GetAsync("mon-espace-de-travail-playwright");
// Ou vérifier d'abord s'il existe
bool existe = await workspaceCollection.ExistsAsync("mon-espace-de-travail-playwright");
if (existe)
{
var espaceDeTravailExistant = await workspaceCollection.GetAsync("mon-espace-de-travail-playwright");
Console.WriteLine($"Espace de travail trouvé : {espaceDeTravailExistant.Value.Data.Name}");
}
3. Lister les espaces de travail
// Lister dans le groupe de ressources
await foreach (var workspace in workspaceCollection.GetAllAsync())
{
Console.WriteLine($"Espace de travail : {workspace.Data.Name}");
Console.WriteLine($" Emplacement : {workspace.Data.Location}");
Console.WriteLine($" État : {workspace.Data.ProvisioningState}");
Console.WriteLine($" URI du plan de données : {workspace.Data.DataplaneUri}");
}
// Lister à travers l'abonnement
await foreach (var workspace in subscription.GetPlaywrightWorkspacesAsync())
{
Console.WriteLine($"Espace de travail : {workspace.Data.Name}");
}
4. Mettre à jour l'espace de travail
var patch = new PlaywrightWorkspacePatch
{
Tags =
{
["Équipe"] = "Exp Dev",
["Environnement"] = "Staging",
["MisAJourLe"] = DateTime.UtcNow.ToString("o")
}
};
var espaceDeTravailMisAJour = await workspace.Value.UpdateAsync(patch);
5. Vérifier la disponibilité du nom
using Azure.ResourceManager.Playwright.Models;
var demandeVerification = new PlaywrightCheckNameAvailabilityContent
{
Nom = "mon-nouvel-espace-de-travail",
ResourceType = "Microsoft.LoadTestService/playwrightWorkspaces"
};
var resultat = await subscription.CheckPlaywrightNameAvailabilityAsync(demandeVerification);
if (resultat.Value.IsNomDisponible == true)
{
Console.WriteLine("Le nom est disponible !");
}
else
{
Console.WriteLine($"Nom non disponible : {resultat.Value.Message}");
Console.WriteLine($"Raison : {resultat.Value.Reason}");
}
6. Obtenir les informations de quota
// Quotas au niveau de l'abonnement
await foreach (var quota in subscription.GetPlaywrightQuotasAsync(AzureLocation.WestUS3))
{
Console.WriteLine($"Quota : {quota.Data.Name}");
Console.WriteLine($" Limite : {quota.Data.Limit}");
Console.WriteLine($" Utilisé : {quota.Data.Used}");
}
// Quotas au niveau de l'espace de travail
var quotasEspaceDeTravail = workspace.Value.GetAllPlaywrightWorkspaceQuota();
await foreach (var quota in quotasEspaceDeTravail.GetAllAsync())
{
Console.WriteLine($"Quota de l'espace de travail : {quota.Data.Name}");
}
7. Supprimer l'espace de travail
// Supprimer (opération longue)
await workspace.Value.DeleteAsync(WaitUntil.Completed);
Référence des types clés
| Type | Objectif |
|---|---|
| `ArmClient` | Point d'entrée pour toutes les opérations ARM |
| `PlaywrightWorkspaceResource` | Représente un espace de travail Playwright Testing |
| `PlaywrightWorkspaceCollection` | Collection pour les opérations CRUD des espaces de travail |
| `PlaywrightWorkspaceData` | Payload de création/réponse de l'espace de travail |
| `PlaywrightWorkspacePatch` | Payload de mise à jour de l'espace de travail |
| `PlaywrightQuotaResource` | Informations sur les quotas au niveau de l'abonnement |
| `PlaywrightWorkspaceQuotaResource` | Informations sur les quotas au niveau de l'espace de travail |
| `PlaywrightExtensions` | Méthodes d'extension pour les ressources ARM |
| `PlaywrightCheckNameAvailabilityContent` | Demande de vérification de disponibilité du nom |
Propriétés de l'espace de travail
| Propriété | Description |
|---|---|
| `DataplaneUri` | URI pour exécuter les tests (par ex., `https://api.dataplane.{guid}.domain.com`) |
| `WorkspaceId` | Identifiant unique de l'espace de travail (GUID) |
| `RegionalAffinity` | Activer/désactiver l'affinité régionale pour l'exécution des tests |
| `LocalAuth` | Activer/désactiver l'authentification locale (jetons d'accès) |
| `ProvisioningState` | État actuel du provisionnement (Réussi, Échoué, etc.) |
Meilleures pratiques
- Utiliser
WaitUntil.Completedpour les opérations qui doivent se terminer avant de continuer - Utiliser
WaitUntil.Startedlorsque vous souhaitez interroger manuellement ou exécuter des opérations en parallèle - Toujours utiliser
DefaultAzureCredential— ne jamais coder les clés en dur - Gérer
RequestFailedExceptionpour les erreurs de l'API ARM - Utiliser
CreateOrUpdateAsyncpour les opérations idempotentes - Naviguer dans la hiérarchie via les méthodes
Get*(par ex.,resourceGroup.GetPlaywrightWorkspaces()) - Stocker le DataplaneUri après la création de l'espace de travail pour la configuration d'exécution des tests
Gestion des erreurs
using Azure;
try
{
var operation = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed, nomEspaceDeTravail, donneesEspaceDeTravail);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("L'espace de travail existe déjà");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Mauvaise demande : {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"Erreur ARM : {ex.Status} - {ex.ErrorCode} : {ex.Message}");
}
Intégration avec l'exécution des tests
Après avoir créé un espace de travail, utilisez le DataplaneUri pour configurer vos tests Playwright :
// 1. Créer l'espace de travail (ce SDK)
var espaceDeTravail = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed, "mon-espace-de-travail", donneesEspaceDeTravail);
// 2. Obtenir l'URL du service
var urlService = espaceDeTravail.Value.Data.DataplaneUri;
// 3. Définir la variable d'environnement pour l'exécution des tests
Environment.SetEnvironmentVariable("PLAYWRIGHT_SERVICE_URL", urlService.ToString());
// 4. Exécuter les tests en utilisant Azure.Developer.MicrosoftPlaywrightTesting.NUnit
// (package séparé pour l'exécution des tests)
SDK connexes
| SDK | Objectif | Installation |
|---|---|---|
| `Azure.ResourceManager.Playwright` | Plan de gestion (ce SDK) | `dotnet add package Azure.ResourceManager.Playwright` |
| `Azure.Developer.MicrosoftPlaywrightTesting.NUnit` | Exécuter des tests Playwright NUnit à grande échelle | `dotnet add package Azure.Developer.MicrosoftPlaywrightTesting.NUnit --prerelease` |
| `Azure.Developer.Playwright` | Bibliothèque cliente Playwright | `dotnet add package Azure.Developer.Playwright` |
Informations sur l'API
- Fournisseur de ressources :
Microsoft.LoadTestService - Version de l'API par défaut :
2025-09-01 - Type de ressource :
Microsoft.LoadTestService/playwrightWorkspaces
Liens vers la documentation
- Référence de l'API Azure.ResourceManager.Playwright
- Vue d'ensemble de Microsoft Playwright Testing
- Démarrage rapide : Exécuter des tests Playwright à grande échelle
---
name: azure-resource-manager-playwright-dotnet
description: Manage Microsoft Playwright Testing workspaces via Azure Resource Manager: create, update, delete workspaces, check name availability, and manage quotas using the .NET SDK.
license: MIT
---
# Azure.ResourceManager.Playwright (.NET)
Management plane SDK for provisioning and managing Microsoft Playwright Testing workspaces via Azure Resource Manager.
> **⚠️ Management vs Test Execution**
> - **This SDK (Azure.ResourceManager.Playwright)**: Create workspaces, manage quotas, check name availability
> - **Test Execution SDK (Azure.Developer.MicrosoftPlaywrightTesting.NUnit)**: Run Playwright tests at scale on cloud browsers
## Installation
```bash
dotnet add package Azure.ResourceManager.Playwright
dotnet add package Azure.Identity
```
**Current Versions**: Stable v1.0.0, Preview v1.0.0-beta.1
## Environment Variables
```bash
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production
AZURE_TENANT_ID=<tenant-id> # For service principal auth (optional)
AZURE_CLIENT_ID=<client-id> # For service principal auth (optional)
AZURE_CLIENT_SECRET=<client-secret> # For service principal auth (optional)
```
## Authentication
```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.Playwright;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
new ResourceIdentifier($"/subscriptions/{subscriptionId}"));
```
## Resource Hierarchy
```
ArmClient
└── SubscriptionResource
├── PlaywrightQuotaResource (subscription-level quotas)
└── ResourceGroupResource
└── PlaywrightWorkspaceResource
└── PlaywrightWorkspaceQuotaResource (workspace-level quotas)
```
## Core Workflow
### 1. Create Playwright Workspace
```csharp
using Azure.ResourceManager.Playwright;
using Azure.ResourceManager.Playwright.Models;
// Get resource group
var resourceGroup = await subscription
.GetResourceGroupAsync("my-resource-group");
// Define workspace
var workspaceData = new PlaywrightWorkspaceData(AzureLocation.WestUS3)
{
// Optional: Configure regional affinity and local auth
RegionalAffinity = PlaywrightRegionalAffinity.Enabled,
LocalAuth = PlaywrightLocalAuth.Enabled,
Tags =
{
["Team"] = "Dev Exp",
["Environment"] = "Production"
}
};
// Create workspace (long-running operation)
var workspaceCollection = resourceGroup.Value.GetPlaywrightWorkspaces();
var operation = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed,
"my-playwright-workspace",
workspaceData);
PlaywrightWorkspaceResource workspace = operation.Value;
// Get the data plane URI for running tests
Console.WriteLine($"Data Plane URI: {workspace.Data.DataplaneUri}");
Console.WriteLine($"Workspace ID: {workspace.Data.WorkspaceId}");
```
### 2. Get Existing Workspace
```csharp
// Get by name
var workspace = await workspaceCollection.GetAsync("my-playwright-workspace");
// Or check if exists first
bool exists = await workspaceCollection.ExistsAsync("my-playwright-workspace");
if (exists)
{
var existingWorkspace = await workspaceCollection.GetAsync("my-playwright-workspace");
Console.WriteLine($"Workspace found: {existingWorkspace.Value.Data.Name}");
}
```
### 3. List Workspaces
```csharp
// List in resource group
await foreach (var workspace in workspaceCollection.GetAllAsync())
{
Console.WriteLine($"Workspace: {workspace.Data.Name}");
Console.WriteLine($" Location: {workspace.Data.Location}");
Console.WriteLine($" State: {workspace.Data.ProvisioningState}");
Console.WriteLine($" Data Plane URI: {workspace.Data.DataplaneUri}");
}
// List across subscription
await foreach (var workspace in subscription.GetPlaywrightWorkspacesAsync())
{
Console.WriteLine($"Workspace: {workspace.Data.Name}");
}
```
### 4. Update Workspace
```csharp
var patch = new PlaywrightWorkspacePatch
{
Tags =
{
["Team"] = "Dev Exp",
["Environment"] = "Staging",
["UpdatedAt"] = DateTime.UtcNow.ToString("o")
}
};
var updatedWorkspace = await workspace.Value.UpdateAsync(patch);
```
### 5. Check Name Availability
```csharp
using Azure.ResourceManager.Playwright.Models;
var checkRequest = new PlaywrightCheckNameAvailabilityContent
{
Name = "my-new-workspace",
ResourceType = "Microsoft.LoadTestService/playwrightWorkspaces"
};
var result = await subscription.CheckPlaywrightNameAvailabilityAsync(checkRequest);
if (result.Value.IsNameAvailable == true)
{
Console.WriteLine("Name is available!");
}
else
{
Console.WriteLine($"Name unavailable: {result.Value.Message}");
Console.WriteLine($"Reason: {result.Value.Reason}");
}
```
### 6. Get Quota Information
```csharp
// Subscription-level quotas
await foreach (var quota in subscription.GetPlaywrightQuotasAsync(AzureLocation.WestUS3))
{
Console.WriteLine($"Quota: {quota.Data.Name}");
Console.WriteLine($" Limit: {quota.Data.Limit}");
Console.WriteLine($" Used: {quota.Data.Used}");
}
// Workspace-level quotas
var workspaceQuotas = workspace.Value.GetAllPlaywrightWorkspaceQuota();
await foreach (var quota in workspaceQuotas.GetAllAsync())
{
Console.WriteLine($"Workspace Quota: {quota.Data.Name}");
}
```
### 7. Delete Workspace
```csharp
// Delete (long-running operation)
await workspace.Value.DeleteAsync(WaitUntil.Completed);
```
## Key Types Reference
| Type | Purpose |
|------|---------|
| `ArmClient` | Entry point for all ARM operations |
| `PlaywrightWorkspaceResource` | Represents a Playwright Testing workspace |
| `PlaywrightWorkspaceCollection` | Collection for workspace CRUD |
| `PlaywrightWorkspaceData` | Workspace creation/response payload |
| `PlaywrightWorkspacePatch` | Workspace update payload |
| `PlaywrightQuotaResource` | Subscription-level quota information |
| `PlaywrightWorkspaceQuotaResource` | Workspace-level quota information |
| `PlaywrightExtensions` | Extension methods for ARM resources |
| `PlaywrightCheckNameAvailabilityContent` | Name availability check request |
## Workspace Properties
| Property | Description |
|----------|-------------|
| `DataplaneUri` | URI for running tests (e.g., `https://api.dataplane.{guid}.domain.com`) |
| `WorkspaceId` | Unique workspace identifier (GUID) |
| `RegionalAffinity` | Enable/disable regional affinity for test execution |
| `LocalAuth` | Enable/disable local authentication (access tokens) |
| `ProvisioningState` | Current provisioning state (Succeeded, Failed, etc.) |
## Best Practices
1. **Use `WaitUntil.Completed`** for operations that must finish before proceeding
2. **Use `WaitUntil.Started`** when you want to poll manually or run operations in parallel
3. **Always use `DefaultAzureCredential`** — never hardcode keys
4. **Handle `RequestFailedException`** for ARM API errors
5. **Use `CreateOrUpdateAsync`** for idempotent operations
6. **Navigate hierarchy** via `Get*` methods (e.g., `resourceGroup.GetPlaywrightWorkspaces()`)
7. **Store the DataplaneUri** after workspace creation for test execution configuration
## Error Handling
```csharp
using Azure;
try
{
var operation = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed, workspaceName, workspaceData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
Console.WriteLine("Workspace already exists");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
Console.WriteLine($"Bad request: {ex.Message}");
}
catch (RequestFailedException ex)
{
Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}");
}
```
## Integration with Test Execution
After creating a workspace, use the `DataplaneUri` to configure your Playwright tests:
```csharp
// 1. Create workspace (this SDK)
var workspace = await workspaceCollection.CreateOrUpdateAsync(
WaitUntil.Completed, "my-workspace", workspaceData);
// 2. Get the service URL
var serviceUrl = workspace.Value.Data.DataplaneUri;
// 3. Set environment variable for test execution
Environment.SetEnvironmentVariable("PLAYWRIGHT_SERVICE_URL", serviceUrl.ToString());
// 4. Run tests using Azure.Developer.MicrosoftPlaywrightTesting.NUnit
// (separate package for test execution)
```
## Related SDKs
| SDK | Purpose | Install |
|-----|---------|---------|
| `Azure.ResourceManager.Playwright` | Management plane (this SDK) | `dotnet add package Azure.ResourceManager.Playwright` |
| `Azure.Developer.MicrosoftPlaywrightTesting.NUnit` | Run NUnit Playwright tests at scale | `dotnet add package Azure.Developer.MicrosoftPlaywrightTesting.NUnit --prerelease` |
| `Azure.Developer.Playwright` | Playwright client library | `dotnet add package Azure.Developer.Playwright` |
## API Information
- **Resource Provider**: `Microsoft.LoadTestService`
- **Default API Version**: `2025-09-01`
- **Resource Type**: `Microsoft.LoadTestService/playwrightWorkspaces`
## Documentation Links
- [Azure.ResourceManager.Playwright API Reference](https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.playwright)
- [Microsoft Playwright Testing Overview](https://learn.microsoft.com/en-us/azure/playwright-testing/overview-what-is-microsoft-playwright-testing)
- [Quickstart: Run Playwright Tests at Scale](https://learn.microsoft.com/en-us/azure/playwright-testing/quickstart-run-end-to-end-tests)
Tous les fichiers
0 fichiersInstaller azure-resource-manager-playwright-dotnet
Téléchargez et extrayez les fichiers de compétences dans votre répertoire .claude/skills/.
Télécharger le ZIPClonez le dépôt et copiez les fichiers de compétence dans votre projet.
git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-dotnet/skills/azure-resource-manager-playwright-dotnet # Copy SKILL.md to your .claude/skills/ directory
Copier





Maison
