Skip to content

Commit

Permalink
chore(): update samples to showcase all options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid200026 committed Dec 22, 2024
1 parent 0926863 commit bd1a39e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
const { AzureCliCredential } = require("@azure/identity");
const { getServiceConfig, ServiceOS } = require("@azure/microsoft-playwright-testing");
const { getServiceConfig, ServiceOS, ServiceAuth } = require("@azure/microsoft-playwright-testing");
const { defineConfig } = require('@playwright/test');
const config = require("./playwright.config");

export default defineConfig(
config,
getServiceConfig(config, {
os: ServiceOS.WINDOWS,
runId: new Date().toISOString(),
credential: new AzureCliCredential(),
}),
{
reporter: [
["list"],
[
"@azure/microsoft-playwright-testing/reporter",
{
enableGitHubSummary: false,
},
],
],
},
);
const azureCredential = new AzureCliCredential();

const serviceAuthType = ServiceAuth.ENTRA_ID;
const os = ServiceOS.LINUX;

const playwrightServiceAdditionalOptions = {
serviceAuthType: serviceAuthType, // Authentication types supported by Microsoft Playwright Testing
os: os, // Operating system types supported by Microsoft Playwright Testing
runId: new Date().toISOString(), // Run id for the test run
timeout: 30000, // Maximum time in milliseconds to wait for the connection to be established
slowMo: 0, // Slows down Playwright operations by the specified amount of milliseconds
exposeNetwork: "<loopback>", // Exposes network available on the connecting client to the browser being connected to
useCloudHostedBrowsers: true, // Use cloud hosted browsers
credential: azureCredential, // Custom token credential for Entra ID authentication
runName: "JavaScript V1 - Sample Run", // Run name for the test run
};

const reporterConfiguration = {
enableGitHubSummary: true, // Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal
enableResultPublish: true, // Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal
};


export default defineConfig(config, getServiceConfig(config, playwrightServiceAdditionalOptions), {
reporter: [["list"], ["@azure/microsoft-playwright-testing/reporter", reporterConfiguration]],
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const playwright = require("@playwright/test");
const { getConnectOptions } = require("@azure/microsoft-playwright-testing");
const { getConnectOptions, ServiceOS } = require("@azure/microsoft-playwright-testing");
const { AzureCliCredential } = require("@azure/identity");

const { test, expect } = playwright;

Expand All @@ -20,8 +21,22 @@ test("has title", async ({ browserName }) => {
});

test("get started link", async ({ browserName }) => {
const { wsEndpoint, options } = await getConnectOptions();
const browser = await playwright[browserName].connect(wsEndpoint, options);
const azureCredential = new AzureCliCredential();
const os = ServiceOS.LINUX;

const playwrightServiceAdditionalOptions = {
os: os, // Operating system types supported by Microsoft Playwright Testing
runId: new Date().toISOString(), // Run id for the test run
timeout: 30000, // Maximum time in milliseconds to wait for the connection to be established
slowMo: 0, // Slows down Playwright operations by the specified amount of milliseconds
exposeNetwork: "<loopback>", // Exposes network available on the connecting client to the browser being connected to
useCloudHostedBrowsers: true, // Use cloud hosted browsers
credential: azureCredential, // Custom token credential for Entra ID authentication
runName: "JavaScript V1 - Sample Run", // Run name for the test run
};

const browserConnectOptions = await getConnectOptions(playwrightServiceAdditionalOptions);
const browser = await playwright[browserName].connect(browserConnectOptions.wsEndpoint, browserConnectOptions.options);
const context = await browser.newContext();
const page = await context.newPage();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const { getServiceConfig, ServiceAuth } = require("@azure/microsoft-playwright-testing");
const { getServiceConfig, ServiceAuth, ServiceEnvironmentVariable } = require("@azure/microsoft-playwright-testing");
const { defineConfig } = require('@playwright/test');
const config = require("./playwright.config");

// You can get the below values from the MPT portal. Alternatively you can directly set the environment variables PLAYWRIGHT_SERVICE_URL & PLAYWRIGHT_SERVICE_ACCESS_TOKEN
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_URL] = "Remote Browser URL";
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_ACCESS_TOKEN] = "***Access Token***";

export default defineConfig(config, getServiceConfig(config, {
serviceAuthType: ServiceAuth.ACCESS_TOKEN
}), {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import { getServiceConfig, ServiceOS } from "@azure/microsoft-playwright-testing";
import {
getServiceConfig,
ServiceOS,
PlaywrightServiceAdditionalOptions,
ServiceAuth,
AuthenticationType,
OsType,
MPTReporterConfig,
} from "@azure/microsoft-playwright-testing";
import { defineConfig } from "@playwright/test";
import config from "./playwright.config";
import { AzureCliCredential } from "@azure/identity";

export default defineConfig(
config,
getServiceConfig(config, {
os: ServiceOS.WINDOWS,
runId: new Date().toISOString(),
credential: new AzureCliCredential(),
}),
{
reporter: [
["list"],
[
"@azure/microsoft-playwright-testing/reporter",
{
enableGitHubSummary: false,
},
],
],
},
);
const azureCredential = new AzureCliCredential();

const serviceAuthType: AuthenticationType = ServiceAuth.ENTRA_ID;
const os: OsType = ServiceOS.LINUX;

const playwrightServiceAdditionalOptions: PlaywrightServiceAdditionalOptions = {
serviceAuthType: serviceAuthType, // Authentication types supported by Microsoft Playwright Testing
os: os, // Operating system types supported by Microsoft Playwright Testing
runId: new Date().toISOString(), // Run id for the test run
timeout: 30000, // Maximum time in milliseconds to wait for the connection to be established
slowMo: 0, // Slows down Playwright operations by the specified amount of milliseconds
exposeNetwork: "<loopback>", // Exposes network available on the connecting client to the browser being connected to
useCloudHostedBrowsers: true, // Use cloud hosted browsers
credential: azureCredential, // Custom token credential for Entra ID authentication
runName: "Typescript V1 - Sample Run", // Run name for the test run
};

const reporterConfiguration: MPTReporterConfig = {
enableGitHubSummary: true, // Enable GitHub Actions annotations to diagnose test failures and deep link to MPT Portal
enableResultPublish: true, // Enable result publishing for the test run. This will upload the test result and artifacts to the MPT Portal
};

export default defineConfig(config, getServiceConfig(config, playwrightServiceAdditionalOptions), {
reporter: [["list"], ["@azure/microsoft-playwright-testing/reporter", reporterConfiguration]],
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import playwright, { test, expect, BrowserType } from "@playwright/test";
import { getConnectOptions } from "@azure/microsoft-playwright-testing";
import {
getConnectOptions,
PlaywrightServiceAdditionalOptions,
ServiceOS,
BrowserConnectOptions,
} from "@azure/microsoft-playwright-testing";
import { AzureCliCredential } from "@azure/identity";

test("has title", async ({ browserName }) => {
const { wsEndpoint, options } = await getConnectOptions();
Expand All @@ -18,8 +24,27 @@ test("has title", async ({ browserName }) => {
});

test("get started link", async ({ browserName }) => {
const { wsEndpoint, options } = await getConnectOptions();
const browser = await (playwright[browserName] as BrowserType).connect(wsEndpoint, options);
const azureCredential = new AzureCliCredential();
const os = ServiceOS.LINUX;

const playwrightServiceAdditionalOptions: PlaywrightServiceAdditionalOptions = {
os: os, // Operating system types supported by Microsoft Playwright Testing
runId: new Date().toISOString(), // Run id for the test run
timeout: 30000, // Maximum time in milliseconds to wait for the connection to be established
slowMo: 0, // Slows down Playwright operations by the specified amount of milliseconds
exposeNetwork: "<loopback>", // Exposes network available on the connecting client to the browser being connected to
useCloudHostedBrowsers: true, // Use cloud hosted browsers
credential: azureCredential, // Custom token credential for Entra ID authentication
runName: "Typescript V1 - Sample Run", // Run name for the test run
};

const browserConnectOptions: BrowserConnectOptions = await getConnectOptions(
playwrightServiceAdditionalOptions,
);
const browser = await (playwright[browserName] as BrowserType).connect(
browserConnectOptions.wsEndpoint,
browserConnectOptions.options,
);
const context = await browser.newContext();
const page = await context.newPage();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { getServiceConfig, ServiceAuth } from "@azure/microsoft-playwright-testing";
import {
getServiceConfig,
ServiceAuth,
ServiceEnvironmentVariable,
} from "@azure/microsoft-playwright-testing";
import { defineConfig } from "@playwright/test";
import config from "./playwright.config";

// You can get the below values from the MPT portal. Alternatively you can directly set the environment variables PLAYWRIGHT_SERVICE_URL & PLAYWRIGHT_SERVICE_ACCESS_TOKEN
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_URL] = "Remote Browser URL";
process.env[ServiceEnvironmentVariable.PLAYWRIGHT_SERVICE_ACCESS_TOKEN] = "***Access Token***";

export default defineConfig(
config,
getServiceConfig(config, {
Expand Down

0 comments on commit bd1a39e

Please sign in to comment.