Usare le opzioni disponibili nel pacchetto del servizio con l'anteprima di Microsoft Playwright Testing
Questo articolo illustra come usare le opzioni disponibili nel file playwright.service.config.ts
generato automaticamente.
Se questo file non è presente nel codice, seguire Avvio rapido: Eseguire test end-to-end su larga scala con Microsoft Playwright Testing Preview
Questo articolo illustra come usare le opzioni disponibili nel .runsettings
file.
Se questo file non è presente nel codice, seguire Avvio rapido: Eseguire test end-to-end su larga scala con Microsoft Playwright Testing Preview
Importante
Microsoft Playwright Testing è attualmente in anteprima. Vedere le condizioni per l'utilizzo supplementari per le anteprime di Microsoft Azure per termini legali aggiuntivi che si applicano a funzionalità di Azure in versione beta, in anteprima o in altro modo non ancora disponibili a livello generale.
Prerequisiti
- Seguire la guida introduttiva e configurare un progetto da eseguire con il servizio Microsoft Playwright Testing. Vedere Avvio rapido: Eseguire test end-to-end su larga scala con Microsoft Playwright Testing Preview
Ecco la versione del file playwright.service.config.ts
con tutte le opzioni disponibili:
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
import { defineConfig } from "@playwright/test";
import { AzureCliCredential } from "@azure/identity";
import config from "./playwright.config";
export default defineConfig(
config,
getServiceConfig(config, {
serviceAuthType:'ACCESS_TOKEN' // Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace.
os: ServiceOS.WINDOWS, // Select the operating system where you want to run tests.
runId: new Date().toISOString(), // Set a unique ID for every test run to distinguish them in the service portal.
credential: new AzureCliCredential(), // Select the authentication method you want to use with Entra.
useCloudHostedBrowsers: true, // Select if you want to use cloud-hosted browsers to run your Playwright tests.
exposeNetwork: '<loopback>', // Use this option to connect to local resources from your Playwright test code without having to configure additional firewall settings.
timeout: 30000 // Set the timeout for your tests.
}),
{
reporter: [
["list"],
[
"@azure/microsoft-playwright-testing/reporter",
{
enableGitHubSummary: true, // Enable/disable GitHub summary in GitHub Actions workflow.
},
],
],
},
);
Impostazioni nel file playwright.service.config.ts
serviceAuthType
:- Descrizione: questa impostazione consente di scegliere il metodo di autenticazione da usare per l'esecuzione del test.
- Opzioni disponibili:
ACCESS_TOKEN
per usare i token di accesso. È necessario abilitare l'autenticazione usando i token di accesso se si vuole usare questa opzione, vedere Gestire l'autenticazione.ENTRA_ID
per usare Microsoft Entra ID per l'autenticazione. È la modalità predefinita.
- Valore predefinito:
ENTRA_ID
- Esempio:
serviceAuthType:'ENTRA_ID'
os
:- Descrizione: questa impostazione consente di scegliere il sistema operativo in cui sono ospitati i browser che eseguono test Playwright.
- Opzioni disponibili:
ServiceOS.WINDOWS
per il sistema operativo Windows.ServiceOS.LINUX
per il sistema operativo Linux.
- Valore predefinito:
ServiceOS.LINUX
- Esempio:
os: ServiceOS.WINDOWS
runId
:- Descrizione: questa impostazione consente di impostare un ID univoco per ogni esecuzione di test per distinguerli nel portale del servizio. L'uso dello stesso runId per più esecuzioni di test genera un errore. Per il partizionamento orizzontale, mantenere lo stesso in tutte le partizioni.
- Esempio:
runId: new Date().toISOString()
credential
:- Descrizione: questa impostazione consente di selezionare il metodo di autenticazione da usare con Microsoft Entra ID.
- Esempio:
credential: new AzureCliCredential()
useCloudHostedBrowsers
- Descrizione: questa impostazione consente di scegliere se usare browser ospitati nel cloud o browser nel computer client per eseguire i test Playwright. Se si disabilita questa opzione, i test vengono eseguiti nei browser del computer client anziché nei browser ospitati nel cloud e non vengono addebitati costi.
- Valore predefinito: true
- Esempio:
useCloudHostedBrowsers: true
exposeNetwork
- Descrizione: questa impostazione consente di connettersi alle risorse locali dal codice di test Playwright senza dover configurare altre impostazioni del firewall. Per altre informazioni, vedere come testare le applicazioni locali
- Esempio:
exposeNetwork: '<loopback>'
timeout
- Descrizione: questa impostazione consente di impostare il timeout per i test che si connettono ai browser ospitati nel cloud.
- Esempio:
timeout: 30000,
reporter
- Descrizione: il file
playwright.service.config.ts
estende il file di configurazione Playwright dell'installazione. Questa opzione esegue l'override dei reporter esistenti e imposta il reporter di Microsoft Playwright Testing. È possibile aggiungere o modificare l'elenco in modo da includere i reporter da usare. Se si aggiunge@azure/microsoft-playwright-testing/reporter
, viene addebitata la creazione di report di Microsoft Playwright Testing. - Valore predefinito: ["@azure/microsoft-playwright-testing/reporter"]
- Esempio:
reporter: [ ["list"], ["@azure/microsoft-playwright-testing/reporter"],
- Descrizione: il file
enableGitHubSummary
:- Descrizione: questa impostazione consente di configurare il reporter del servizio Microsoft Playwright Testing. È possibile scegliere se includere il riepilogo dell'esecuzione dei test nel riepilogo di GitHub quando viene eseguito in GitHub Actions.
- Valore predefinito: true
- Esempio:
reporter: [ ["list"], [ "@azure/microsoft-playwright-testing/reporter", { enableGitHubSummary: true, }, ], ]
Ecco la versione del file .runsettings
con tutte le opzioni disponibili:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<TestRunParameters>
<!-- Use this option when you want to authenticate using access tokens. This mode of auth should be enabled for the workspace. -->
<Parameter name="ServiceAuthType" value="EntraId" />
<!-- Select the operating system where you want to run tests. -->
<Parameter name="Os" value="linux" />
<!-- Set a unique ID for every test run to distinguish them in the service portal.-->
<Parameter name="RunId" value="sample-run-id1" />
<!--Select if you want to use cloud-hosted browsers to run your Playwright tests.-->
<Parameter name="UseCloudHostedBrowsers" value="true" />
<!--Use this option to connect to local resources from your Playwright test code without having to configure additional firewall-->
<Parameter name="ExposeNetwork" value="loopback" />
<!--Select the authentication method you want to use with Entra-->
<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
<!--Enable/disable GitHub summary in GitHub Actions workflow.-->
<Parameter name="EnableGitHubSummary" value="false" />
</TestRunParameters>
<!-- NUnit adapter -->
<NUnit>
<!-- Adjust parallel workers, parallel worker would also be bound by number of unit test files -->
<NumberOfTestWorkers>10</NumberOfTestWorkers>
</NUnit>
<!-- General run configuration -->
<RunConfiguration>
<EnvironmentVariables>
<!-- For debugging selectors, it's recommend to set the following environment variable -->
<DEBUG>pw:api</DEBUG>
</EnvironmentVariables>
</RunConfiguration>
<!-- Playwright -->
<Playwright>
<BrowserName>chromium</BrowserName>
<!--Set the timeout for your tests.-->
<ExpectTimeout>5000</ExpectTimeout>
<LaunchOptions>
<Headless>false</Headless>
<!--Channel>msedge</Channel-->
</LaunchOptions>
</Playwright>
<LoggerRunSettings>
<Loggers>
<!--microsoft playwright testing service logger for reporting -->
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
<!--could enable any logger additionally -->
<Logger friendlyName="trx" enabled="false" />
</Loggers>
</LoggerRunSettings>
</RunSettings>
Opzioni di configurazione nel .runsettings
file
serviceAuthType
:- Descrizione: questa impostazione consente di scegliere il metodo di autenticazione da usare per l'esecuzione del test.
- Opzioni disponibili:
AccessToken
per usare i token di accesso. È necessario abilitare l'autenticazione usando i token di accesso se si vuole usare questa opzione, vedere Gestire l'autenticazione.EntraId
per usare Microsoft Entra ID per l'autenticazione. È la modalità predefinita.
- Valore predefinito:
EntraId
- Esempio:
<Parameter name="ServiceAuthType" value="EntraId" />
os
:- Descrizione: questa impostazione consente di scegliere il sistema operativo in cui sono ospitati i browser che eseguono test Playwright.
- Opzioni disponibili:
- "windows" per il sistema operativo Windows.
- "linux" per il sistema operativo Linux.
- Valore predefinito: "linux"
- Esempio:
<Parameter name="Os" value="linux" />
RunId
:- Descrizione: questa impostazione consente di impostare un ID univoco per ogni esecuzione di test per distinguerli nel portale del servizio. L'uso dello stesso runId per più esecuzioni di test genera un errore. Se non lo si imposta, il pacchetto del servizio genererà un ID univoco ogni volta che si attiva un'esecuzione di test. Per il partizionamento orizzontale, mantenere lo stesso in tutte le partizioni.
- Esempio:
<Parameter name="RunId" value="sample-run-id1" />
AzureTokenCredentialType
:- Descrizione: questa impostazione consente di selezionare il metodo di autenticazione da usare con Microsoft Entra ID.
- Esempio:
<Parameter name="AzureTokenCredentialType" value="DefaultAzureCredential" />
UseCloudHostedBrowsers
- Descrizione: questa impostazione consente di scegliere se usare browser ospitati nel cloud o browser nel computer client per eseguire i test Playwright. Se si disabilita questa opzione, i test vengono eseguiti nei browser del computer client anziché nei browser ospitati nel cloud e non vengono addebitati costi.
- Valore predefinito: true
- Esempio:
<Parameter name="UseCloudHostedBrowsers" value="true" />
ExposeNetwork
- Descrizione: questa impostazione consente di connettersi alle risorse locali dal codice di test Playwright senza dover configurare altre impostazioni del firewall. Per altre informazioni, vedere come testare le applicazioni locali
- Esempio:
<Parameter name="ExposeNetwork" value="loopback" />
reporter
- Descrizione: è possibile pubblicare i risultati e gli artefatti del test nel servizio usando
microsoft-playwright-testing
il logger. È possibile disabilitare la creazione di report rimuovendo il report dall'utente.runsettings
o impostandolo su false. - Valore predefinito: true
- Esempio:
<Logger friendlyName="microsoft-playwright-testing" enabled="true" />
- Descrizione: è possibile pubblicare i risultati e gli artefatti del test nel servizio usando
EnableGitHubSummary
:- Descrizione: questa impostazione consente di configurare il reporter del servizio Microsoft Playwright Testing. È possibile scegliere se includere il riepilogo dell'esecuzione dei test nel riepilogo di GitHub quando viene eseguito in GitHub Actions.
- Valore predefinito: true
- Esempio:
<Parameter name="EnableGitHubSummary" value="false" />