test: some tests for expected API behavior (#32495)

Adding some tests discussed in
https://github.com/microsoft/playwright/pull/32434
This commit is contained in:
Yury Semikhatsky 2024-09-06 13:13:44 -07:00 committed by GitHub
parent 1402dee9e6
commit d85527e9f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 71 additions and 1 deletions

View File

@ -297,6 +297,16 @@ it('should click', async function({ page, browser, server }) {
expect(await handle1.evaluate(() => (window as any)['_clicked'])).toBe(true);
});
it('contentFrame should work', async ({ page, browser, server }) => {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(page.frames().length).toBe(2);
expect(await countOOPIFs(browser)).toBe(1);
expect(await page.locator('iframe').contentFrame().locator('div').count()).toBe(200);
const oopif = await page.$('iframe');
const content = await oopif.contentFrame();
expect(await content.locator('div').count()).toBe(200);
});
it('should allow cdp sessions on oopifs', async function({ page, browser, server }) {
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(await countOOPIFs(browser)).toBe(1);

View File

@ -75,3 +75,19 @@ it('should work inside closed shadow root', async ({ page, server, browserName }
const element = await frame.frameElement();
expect(await element.getAttribute('name')).toBe('myframe');
});
it('should work inside declarative shadow root', async ({ page, server, browserName }) => {
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
<div>
<template shadowrootmode="open">
<iframe name="myframe" srcdoc="<h1>Hi!</h1>"></iframe>
<slot></slot>
</template>
<span>footer</span>
</div>
`);
const frame = page.frame({ name: 'myframe' });
const element = await frame.frameElement();
expect(await element.getAttribute('name')).toBe('myframe');
});

View File

@ -164,7 +164,7 @@ it('should work with regular expression passed from a different context', async
expect(intercepted).toBe(true);
});
it('should not break remote worker importScripts', async ({ page, server, browserName, browserMajorVersion }) => {
it('should not break remote worker importScripts', async ({ page, server }) => {
await page.route('**', async route => {
await route.continue();
});
@ -189,3 +189,20 @@ it('should disable memory cache when intercepting', async ({ page, server }) =>
await expect(page).toHaveURL(server.PREFIX + '/page.html');
expect(interceted).toBe(2);
});
it('should intercept blob url requests', async function({ page, server, browserName }) {
it.fixme(browserName !== 'webkit');
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {
route.fulfill({
status: 200,
body: 'intercepted',
}).catch(e => null);
});
page.on('console', msg => console.log(msg.text()));
const response = await page.evaluate(async () => {
const blobUrl = URL.createObjectURL(new Blob(['failed to intercept'], { type: 'text/plain' }));
return await fetch(blobUrl).then(response => response.text());
});
expect(response).toBe('intercepted');
});

View File

@ -78,6 +78,33 @@ it('should dblclick the div', async ({ page, server }) => {
expect(event.button).toBe(0);
});
it('down and up should generate click', async ({ page, server }) => {
await page.evaluate(() => {
window['clickPromise'] = new Promise(resolve => {
document.addEventListener('click', event => {
resolve({
type: event.type,
detail: event.detail,
clientX: event.clientX,
clientY: event.clientY,
isTrusted: event.isTrusted,
button: event.button
});
});
});
});
await page.mouse.move(50, 60);
await page.mouse.down();
await page.mouse.up();
const event = await page.evaluate(() => window['clickPromise']);
expect(event.type).toBe('click');
expect(event.detail).toBe(1);
expect(event.clientX).toBe(50);
expect(event.clientY).toBe(60);
expect(event.isTrusted).toBe(true);
expect(event.button).toBe(0);
});
it('should pointerdown the div with a custom button', async ({ page, server, browserName }) => {
await page.setContent(`<div style='width: 100px; height: 100px;'>Click me</div>`);
await page.evaluate(() => {