Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(inspector): render expect.not correctly (#19125)
Dmitry Gozman4f72a895e91c
diff --git a/packages/playwright-test/src/matchers/toBeTruthy.ts b/packages/playwright-test/src/matchers/toBeTruthy.tsindex 58644408dc..cb8802e879 100644--- a/packages/playwright-test/src/matchers/toBeTruthy.ts+++ b/packages/playwright-test/src/matchers/toBeTruthy.ts@@ -36,7 +36,7 @@ export async function toBeTruthy(const timeout = currentExpectTimeout(options);- const { matches, log, timedOut } = await query(this.isNot, timeout, captureStackTrace('expect.' + matcherName));+ const { matches, log, timedOut } = await query(this.isNot, timeout, captureStackTrace(`expect.${this.isNot ? 'not.' : ''}${matcherName}`));const message = () => {return matcherHint(this, matcherName, undefined, '', matcherOptions, timedOut ? timeout : undefined) + callLogText(log);diff --git a/packages/playwright-test/src/matchers/toMatchSnapshot.ts b/packages/playwright-test/src/matchers/toMatchSnapshot.tsindex bd6e0eeba3..e07764ae66 100644--- a/packages/playwright-test/src/matchers/toMatchSnapshot.ts+++ b/packages/playwright-test/src/matchers/toMatchSnapshot.ts@@ -327,7 +327,7 @@ export async function toHaveScreenshot(maxDiffPixelRatio: undefined,};- const customStackTrace = captureStackTrace(`expect.toHaveScreenshot`);+ const customStackTrace = captureStackTrace(`expect.${this.isNot ? 'not.' : ''}toHaveScreenshot`);const hasSnapshot = fs.existsSync(helper.snapshotPath);if (this.isNot) {if (!hasSnapshot)diff --git a/packages/playwright-test/src/matchers/toMatchText.ts b/packages/playwright-test/src/matchers/toMatchText.tsindex 47ceca878a..7987b92358 100644--- a/packages/playwright-test/src/matchers/toMatchText.ts+++ b/packages/playwright-test/src/matchers/toMatchText.ts@@ -59,7 +59,7 @@ export async function toMatchText(const timeout = currentExpectTimeout(options);- const { matches: pass, received, log, timedOut } = await query(this.isNot, timeout, captureStackTrace('expect.' + matcherName));+ const { matches: pass, received, log, timedOut } = await query(this.isNot, timeout, captureStackTrace(`expect.${this.isNot ? 'not.' : ''}${matcherName}`));const stringSubstring = options.matchSubstring ? 'substring' : 'string';const receivedString = received || '';const message = passdiff --git a/packages/recorder/src/callLog.tsx b/packages/recorder/src/callLog.tsxindex aa73853e74..a40be416dc 100644--- a/packages/recorder/src/callLog.tsx+++ b/packages/recorder/src/callLog.tsx@@ -44,7 +44,7 @@ export const CallLogView: React.FC<CallLogProps> = ({const locatorCall = `page.${locator}`;let titlePrefix = callLog.title;let titleSuffix = '';- if (callLog.title.startsWith('expect.to')) {+ if (callLog.title.startsWith('expect.to') || callLog.title.startsWith('expect.not.to')) {titlePrefix = 'expect(';titleSuffix = `).${callLog.title.substring('expect.'.length)}()`;} else if (callLog.title.startsWith('locator.')) {diff --git a/tests/library/inspector/pause.spec.ts b/tests/library/inspector/pause.spec.tsindex 63694cb15f..1580d326e6 100644--- a/tests/library/inspector/pause.spec.ts+++ b/tests/library/inspector/pause.spec.ts@@ -230,6 +230,7 @@ it.describe('pause', () => {const scriptPromise = (async () => {await page.pause();await expect(page.locator('button')).toHaveText('Submit');+ await expect(page.locator('button')).not.toHaveText('Submit2');await page.pause(); // 2})();const recorderPage = await recorderPageGetter();@@ -238,6 +239,7 @@ it.describe('pause', () => {expect(await sanitizeLog(recorderPage)).toEqual(['page.pause- XXms','expect(page.locator(\'button\')).toHaveText()- XXms',+ 'expect(page.locator(\'button\')).not.toHaveText()- XXms','page.pause',]);await recorderPage.click('[title="Resume (F8)"]');diff --git a/tests/page/expect-boolean.spec.ts b/tests/page/expect-boolean.spec.tsindex 3cf89c10b5..f8d0974cef 100644--- a/tests/page/expect-boolean.spec.ts+++ b/tests/page/expect-boolean.spec.ts@@ -58,7 +58,7 @@ test.describe('toBeChecked', () => {await page.setContent('<input type=checkbox checked></input>');const locator = page.locator('input');const error = await expect(locator).not.toBeChecked({ timeout: 1000 }).catch(e => e);- expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`);+ expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`);expect(error.message).toContain(`locator resolved to <input checked type="checkbox"/>`);});@@ -73,7 +73,7 @@ test.describe('toBeChecked', () => {await page.setContent('<div>no inputs here</div>');const locator2 = page.locator('input2');const error = await expect(locator2).not.toBeChecked({ timeout: 1000 }).catch(e => e);- expect(error.message).toContain(`expect.toBeChecked with timeout 1000ms`);+ expect(error.message).toContain(`expect.not.toBeChecked with timeout 1000ms`);expect(error.message).toContain('waiting for locator(\'input2\')');});@@ -368,7 +368,7 @@ test.describe('toBeHidden', () => {await page.setContent('<div></div>');const locator = page.locator('button');const error = await expect(locator).not.toBeHidden({ timeout: 1000 }).catch(e => e);- expect(error.message).toContain(`expect.toBeHidden with timeout 1000ms`);+ expect(error.message).toContain(`expect.not.toBeHidden with timeout 1000ms`);});test('with impossible timeout .not', async ({ page }) => {diff --git a/tests/page/expect-misc.spec.ts b/tests/page/expect-misc.spec.tsindex 87f900295f..37d3916d45 100644--- a/tests/page/expect-misc.spec.ts+++ b/tests/page/expect-misc.spec.ts@@ -255,11 +255,11 @@ test.describe('toHaveAttribute', () => {await expect(locator).toHaveAttribute('checked', /.*/);{const error = await expect(locator).not.toHaveAttribute('checked', '', { timeout: 1000 }).catch(e => e);- expect(error.message).toContain('expect.toHaveAttribute with timeout 1000ms');+ expect(error.message).toContain('expect.not.toHaveAttribute with timeout 1000ms');}{const error = await expect(locator).not.toHaveAttribute('checked', /.*/, { timeout: 1000 }).catch(e => e);- expect(error.message).toContain('expect.toHaveAttribute with timeout 1000ms');+ expect(error.message).toContain('expect.not.toHaveAttribute with timeout 1000ms');}});});