Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions packages/playwright-core/src/server/agent/actionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@
* limitations under the License.
*/

import { serializeExpectedTextValues } from '../utils/expectUtils';
import { formatMatcherMessage, serializeExpectedTextValues, simpleMatcherUtils } from '../utils/expectUtils';
import { monotonicTime } from '../../utils/isomorphic/time';
import { createGuid } from '../utils/crypto';
import { parseAriaSnapshotUnsafe } from '../../utils/isomorphic/ariaSnapshot';
import { asLocatorDescription } from '../../utils/isomorphic/locatorGenerators';
import { yaml } from '../../utilsBundle';
import { serializeError } from '../errors';

import type * as actions from './actions';
import type { Page } from '../page';
import type { Progress } from '../progress';
import type { NameValue } from '@protocol/channels';
import type { ExpectResult, Frame } from '../frames';
import type { Frame } from '../frames';
import type { CallMetadata } from '../instrumentation';
import type * as channels from '@protocol/channels';
import type { FrameExpectParams } from '@injected/injectedScript';

export async function runAction(progress: Progress, mode: 'generate' | 'run', page: Page, action: actions.Action, secrets: NameValue[]) {
const parentMetadata = progress.metadata;
Expand Down Expand Up @@ -99,36 +101,49 @@ async function innerRunAction(progress: Progress, mode: 'generate' | 'run', page
await frame.uncheck(progress, action.selector, { ...commonOptions });
break;
case 'expectVisible': {
const result = await frame.expect(progress, action.selector, { expression: 'to.be.visible', isNot: !!action.isNot });
if (!result.matches === !action.isNot)
throw new Error(result.errorMessage);
await runExpect(frame, progress, action.selector, { expression: 'to.be.visible', isNot: !!action.isNot }, 'visible', 'toBeVisible', '');
break;
}
case 'expectValue': {
let result: ExpectResult;
if (action.type === 'textbox' || action.type === 'combobox' || action.type === 'slider') {
const expectedText = serializeExpectedTextValues([action.value]);
result = await frame.expect(progress, action.selector, { expression: 'to.have.value', expectedText, isNot: !!action.isNot });
await runExpect(frame, progress, action.selector, { expression: 'to.have.value', expectedText, isNot: !!action.isNot }, action.value, 'toHaveValue', 'expected');
} else if (action.type === 'checkbox' || action.type === 'radio') {
const expectedValue = { checked: action.value === 'true' };
result = await frame.expect(progress, action.selector, { selector: action.selector, expression: 'to.be.checked', expectedValue, isNot: !!action.isNot });
await runExpect(frame, progress, action.selector, { selector: action.selector, expression: 'to.be.checked', expectedValue, isNot: !!action.isNot }, action.value ? 'checked' : 'unchecked', 'toBeChecked', '');
} else {
throw new Error(`Unsupported element type: ${action.type}`);
}
if (!result.matches === !action.isNot)
throw new Error(result.errorMessage);
break;
}
case 'expectAria': {
const expectedValue = parseAriaSnapshotUnsafe(yaml, action.template);
const result = await frame.expect(progress, 'body', { expression: 'to.match.aria', expectedValue, isNot: !!action.isNot });
if (!result.matches === !action.isNot)
throw new Error(result.errorMessage);
await runExpect(frame, progress, 'body', { expression: 'to.match.aria', expectedValue, isNot: !!action.isNot }, '\n' + action.template, 'toMatchAriaSnapshot', 'expected');
break;
}
}
}

async function runExpect(frame: Frame, progress: Progress, selector: string | undefined, options: FrameExpectParams, expected: string, matcherName: string, expectation: string) {
const result = await frame.expect(progress, selector, options);
if (!result.matches === !options.isNot) {
const received = matcherName === 'toMatchAriaSnapshot' ? '\n' + result.received.raw : result.received;
throw new Error(formatMatcherMessage(simpleMatcherUtils, {
isNot: options.isNot,
matcherName,
expectation,
locator: selector ? asLocatorDescription('javascript', selector) : undefined,
timedOut: result.timedOut,
timeout: progress.timeout,
printedExpected: options.isNot ? `Expected: not ${expected}` : `Expected: ${expected}`,
printedReceived: result.errorMessage ? '' : `Received: ${received}`,
errorMessage: result.errorMessage,
// Note: we are not passing call log, because it will be automatically appended on the client side,
// as a part of the agent.{perform,expect} call.
}));
}
}

export function traceParamsForAction(progress: Progress, action: actions.Action): { title?: string, type: string, method: string, params: any } {
const timeout = progress.timeout;
switch (action.method) {
Expand Down
2 changes: 2 additions & 0 deletions packages/playwright-core/src/server/chromium/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ export class Chromium extends BrowserType {
override getExecutableName(options: types.LaunchOptions): string {
if (options.channel && registry.isChromiumAlias(options.channel))
return 'chromium';
if (options.channel === 'chromium-tip-of-tree')
return options.headless ? 'chromium-tip-of-tree-headless-shell' : 'chromium-tip-of-tree';
if (options.channel)
return options.channel;
return options.headless ? 'chromium-headless-shell' : 'chromium';
Expand Down
83 changes: 44 additions & 39 deletions packages/playwright-core/src/server/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,64 +205,64 @@ const DOWNLOAD_PATHS: Record<string, DownloadPaths> = {
'chromium-tip-of-tree': {
'<unknown>': undefined,
'ubuntu18.04-x64': undefined,
'ubuntu20.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'ubuntu22.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'ubuntu24.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'ubuntu20.04-x64': cftUrl('linux64/chrome-linux64.zip'),
'ubuntu22.04-x64': cftUrl('linux64/chrome-linux64.zip'),
'ubuntu24.04-x64': cftUrl('linux64/chrome-linux64.zip'),
'ubuntu18.04-arm64': undefined,
'ubuntu20.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'ubuntu22.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'ubuntu24.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'debian11-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'debian11-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian11-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'debian12-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'debian12-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian12-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'debian13-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux.zip',
'debian13-x64': cftUrl('linux64/chrome-linux64.zip'),
'debian13-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-linux-arm64.zip',
'mac10.13': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac10.14': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac10.15': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac11': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac11-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac-arm64.zip',
'mac12': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac12-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac-arm64.zip',
'mac13': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac13-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac-arm64.zip',
'mac14': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac14-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac-arm64.zip',
'mac15': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac.zip',
'mac15-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-mac-arm64.zip',
'win64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-win64.zip',
'mac10.13': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac10.14': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac10.15': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac11': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac11-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
'mac12': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac12-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
'mac13': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac13-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
'mac14': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac14-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
'mac15': cftUrl('mac-x64/chrome-mac-x64.zip'),
'mac15-arm64': cftUrl('mac-arm64/chrome-mac-arm64.zip'),
'win64': cftUrl('win64/chrome-win64.zip'),
},
'chromium-tip-of-tree-headless-shell': {
'<unknown>': undefined,
'ubuntu18.04-x64': undefined,
'ubuntu20.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'ubuntu22.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'ubuntu24.04-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'ubuntu20.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'ubuntu22.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'ubuntu24.04-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'ubuntu18.04-arm64': undefined,
'ubuntu20.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'ubuntu22.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'ubuntu24.04-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'debian11-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'debian11-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian11-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'debian12-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'debian12-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian12-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'debian13-x64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux.zip',
'debian13-x64': cftUrl('linux64/chrome-headless-shell-linux64.zip'),
'debian13-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-linux-arm64.zip',
'mac10.13': undefined,
'mac10.14': undefined,
'mac10.15': undefined,
'mac11': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac.zip',
'mac11-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac-arm64.zip',
'mac12': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac.zip',
'mac12-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac-arm64.zip',
'mac13': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac.zip',
'mac13-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac-arm64.zip',
'mac14': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac.zip',
'mac14-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac-arm64.zip',
'mac15': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac.zip',
'mac15-arm64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-mac-arm64.zip',
'win64': 'builds/chromium-tip-of-tree/%s/chromium-tip-of-tree-headless-shell-win64.zip',
'mac11': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
'mac11-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
'mac12': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
'mac12-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
'mac13': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
'mac13-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
'mac14': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
'mac14-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
'mac15': cftUrl('mac-x64/chrome-headless-shell-mac-x64.zip'),
'mac15-arm64': cftUrl('mac-arm64/chrome-headless-shell-mac-arm64.zip'),
'win64': cftUrl('win64/chrome-headless-shell-win64.zip'),
},
'firefox': {
'<unknown>': undefined,
Expand Down Expand Up @@ -1413,9 +1413,9 @@ export class Registry {
private _defaultBrowsersToInstall(options: { shell?: 'no' | 'only' }): Executable[] {
let executables = this.defaultExecutables();
if (options.shell === 'no')
executables = executables.filter(e => e.name !== 'chromium-headless-shell');
executables = executables.filter(e => e.name !== 'chromium-headless-shell' && e.name !== 'chromium-tip-of-tree-headless-shell');
if (options.shell === 'only')
executables = executables.filter(e => e.name !== 'chromium');
executables = executables.filter(e => e.name !== 'chromium' && e.name !== 'chromium-tip-of-tree');
return executables;
}

Expand Down Expand Up @@ -1451,6 +1451,11 @@ export class Registry {
handleArgument('chromium');
if (options.shell !== 'no')
handleArgument('chromium-headless-shell');
} else if (alias === 'chromium-tip-of-tree') {
if (options.shell !== 'only')
handleArgument('chromium-tip-of-tree');
if (options.shell !== 'no')
handleArgument('chromium-tip-of-tree-headless-shell');
} else {
handleArgument(alias);
}
Expand Down
32 changes: 32 additions & 0 deletions packages/playwright-core/src/server/utils/expectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { isRegExp, isString } from '../../utils/isomorphic/rtti';
import { colors } from '../../utilsBundle';

import type { ExpectedTextValue } from '@protocol/channels';

Expand Down Expand Up @@ -144,3 +145,34 @@ Call log:
${utils.DIM_COLOR(log.join('\n'))}
`;
};


function printValue(value: unknown): string {
try {
return JSON.stringify(value);
} catch {
return String(value);
}
}

function printReceived(value: unknown): string {
return colors.red(printValue(value));
}

function printExpected(value: unknown): string {
return colors.green(printValue(value));
}

export const simpleMatcherUtils: InternalMatcherUtils = {
DIM_COLOR: colors.dim,
RECEIVED_COLOR: colors.red,
EXPECTED_COLOR: colors.green,
INVERTED_COLOR: colors.inverse,
printReceived,
printExpected,
printDiffOrStringify: (expected: unknown, received: unknown, expectedLabel: string, receivedLabel: string) => {
const maxLength = Math.max(expectedLabel.length, receivedLabel.length) + 2;
return `${expectedLabel}: `.padEnd(maxLength) + printExpected(expected) + `\n` +
`${receivedLabel}: `.padEnd(maxLength) + printReceived(received);
},
};
4 changes: 3 additions & 1 deletion tests/config/browserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ const test = baseTest.extend<BrowserTestTestFixtures, BrowserTestWorkerFixtures>
electronMajorVersion: [0, { scope: 'worker' }],

isHeadlessShell: [async ({ browserName, channel, headless }, use) => {
await use(browserName === 'chromium' && (channel === 'chromium-headless-shell' || channel === 'chromium-tip-of-tree-headless-shell' || (!channel && headless)));
const isShell = channel === 'chromium-headless-shell' || (!channel && headless);
const isToTShell = channel === 'chromium-tip-of-tree-headless-shell' || (channel === 'chromium-tip-of-tree' && headless);
await use(browserName === 'chromium' && (isShell || isToTShell));
}, { scope: 'worker' }],

contextFactory: async ({ _contextFactory }: any, run) => {
Expand Down
Loading
Loading