참고소스 수정본

This commit is contained in:
LASTA_DEV01\lasta
2026-05-12 19:40:31 +09:00
parent 0f34a451fc
commit 2e9204243d
8708 changed files with 3259488 additions and 869 deletions

View File

@@ -0,0 +1,27 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const requireName = process.argv[2];
const pkg = require(requireName);
for (const key of ['chromium', 'firefox', 'webkit', 'test', 'devices']) {
if (pkg[key] !== undefined) {
console.error(`Package ${requireName} should not export ${key}`);
process.exit(1);
}
}
console.log(`${requireName} SUCCESS`);

View File

@@ -0,0 +1,19 @@
const { test, expect } = require('@playwright/test');
test('platform', async ({ page }) => {
console.log('@' + page.context().browser().browserType().name(), await page.evaluate(() => navigator.platform));
});
test('userAgent', async ({ page }) => {
console.log('@' + page.context().browser().browserType().name(), await page.evaluate(() => navigator.userAgent));
});
test('screenshot', async ({ page }) => {
await expect(page).toHaveScreenshot('img.png');
});
test('localhost', async ({ page }) => {
expect(process.env.TEST_PORT).toBeTruthy();
await page.goto('http://localhost:' + process.env.TEST_PORT);
console.log('@' + page.context().browser().browserType().name(), await page.textContent('body'));
});

View File

@@ -0,0 +1,33 @@
const playwright = require('playwright-core');
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
(async () => {
const dir = process.argv[2];
const chrome = await playwright.chromium.launch({ channel: 'chrome' });
const version = chrome.version();
await chrome.close();
console.log(`Found Chrome version ${version}`);
const [major] = version.split('.');
const downloadsInfo = JSON.parse(execSync(`curl https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json --silent`).toString('utf-8'));
let currentPlatform = '';
if (process.platform === 'darwin')
currentPlatform = process.arch === 'arm64' ? 'mac-arm64' : 'mac-x64';
else if (process.platform === 'linux')
currentPlatform = 'linux64';
else
currentPlatform = 'win64';
const chromeDriverURL = downloadsInfo.milestones[major].downloads.chromedriver.find(({ platform, url }) => platform === currentPlatform).url;
console.log(`Found ChromeDriver download URL: ${chromeDriverURL}`);
const zip = path.join(dir, 'chromedriver.zip');
execSync(`curl ${chromeDriverURL} --output ${zip} --silent`);
console.log(`Downloaded ${zip}`);
execSync(`unzip -j ${zip}`, { cwd: dir });
console.log(`Unzipped ${zip}`);
fs.rmSync(zip);
})();

View File

@@ -0,0 +1,15 @@
const { execSync } = require('child_process');
const { mkdirSync } = require('fs');
const path = require('path');
async function downloadFile(url, dir, filename) {
const output = path.join(dir, filename);
execSync(`curl -L --silent --output ${output} ${url}`);
}
(async () => {
const dir = process.argv[2];
mkdirSync(dir);
downloadFile('https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.8.0/selenium-server-4.8.3.jar', dir, 'selenium-server-4.8.3.jar')
downloadFile('https://github.com/SeleniumHQ/selenium/releases/download/selenium-3.141.59/selenium-server-standalone-3.141.59.jar', dir, 'selenium-server-standalone-3.141.59.jar')
})();

View File

@@ -0,0 +1,54 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-check
const pw = require.resolve('playwright');
const coreBundle = require.resolve('playwright-core/lib/coreBundle', { paths: [pw] });
const { oop } = require(coreBundle);
(async () => {
console.log('launching driver')
const { playwright, stop } = await oop.start();
console.log('launched driver')
try {
const browser = await playwright.chromium.launch({ handleSIGINT: false });
const context = await browser.newContext();
const page = await context.newPage();
// let things settle down
await page.waitForTimeout(100);
// send SIGINT to driver
process.kill(playwright.driverProcess.pid, 'SIGINT');
// wait and see if driver exits
await page.waitForTimeout(100);
console.log(`closing gracefully`)
await page.close();
console.log('closed page');
await context.close();
console.log('closed context');
await browser.close();
console.log('closed browser');
await stop();
console.log('stopped driver');
} catch (e) {
console.error(`Should be able to launch from ${process.cwd()}`);
console.error(e);
process.exit(1);
}
console.log(`SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const pw = require.resolve('playwright');
const coreBundle = require.resolve('playwright-core/lib/coreBundle', { paths: [pw] });
const { oop } = require(coreBundle);
(async () => {
const { playwright, stop } = await oop.start();
console.log(`driver PID=${playwright.driverProcess.pid}`);
for (const browserType of ['chromium', 'firefox', 'webkit']) {
try {
const browser = await playwright[browserType].launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
console.log(`${browserType} SUCCESS`);
} catch (e) {
console.error(`Should be able to launch ${browserType} from ${process.cwd()}`);
console.error(e);
process.exit(1);
}
}
await stop();
console.log(`driver SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -0,0 +1,3 @@
const { app } = require('electron');
app.on('window-all-closed', e => e.preventDefault());

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { chromium, firefox, webkit, selectors, devices, errors, request } from 'playwright-chromium';
import playwright from 'playwright-chromium';
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, [chromium]);

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { chromium, firefox, webkit, selectors, devices, errors, request } from 'playwright-firefox';
import playwright from 'playwright-firefox';
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, [firefox]);

View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { chromium, firefox, webkit, selectors, devices, errors, request, test, expect } from '@playwright/test';
import * as playwright from '@playwright/test';
import defaultExport from '@playwright/test';
import testESM from './esm.mjs';
if (defaultExport !== test) {
console.error('default export is not test.');
process.exit(1);
}
if (typeof test !== 'function') {
console.error('test is not a function');
process.exit(1);
}
if (typeof expect !== 'function') {
console.error('expect is not a function');
process.exit(1);
}
expect(1).toBe(1);
testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, [chromium, firefox, webkit]);

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { chromium, firefox, webkit, selectors, devices, errors, request } from 'playwright-webkit';
import playwright from 'playwright-webkit';
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, [webkit]);

View File

@@ -0,0 +1,21 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { chromium, firefox, webkit, selectors, devices, errors, request } from 'playwright';
import playwright from 'playwright';
import testESM from './esm.mjs';
testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, [chromium, firefox, webkit]);

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default async function testESM({ chromium, firefox, webkit, selectors, devices, errors, request, playwright }, browsers) {
if (playwright.chromium !== chromium)
process.exit(1);
if (playwright.firefox !== firefox)
process.exit(1);
if (playwright.webkit !== webkit)
process.exit(1);
if (playwright.errors !== errors)
process.exit(1);
if (playwright.request !== request)
process.exit(1);
try {
for (const browserType of browsers) {
const browser = await browserType.launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
}
console.log(`esm SUCCESS`);
} catch (err) {
console.error(err);
process.exit(1);
}
}

View File

@@ -0,0 +1,6 @@
const { test, expect } = require('@playwright/test');
test('failing test', async ({ page }) => {
await page.setContent(`<div>hello</div><span>world</span>`);
await expect(page.locator('span')).toHaveText('hello', { timeout: 1000 });
});

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const playwright = require('playwright');
(async () => {
const browser = await playwright.chromium.launch({
executablePath: '/opt/google/chrome/chrome'
});
const context = await browser.newContext();
await context.newPage();
await browser.close();
console.log('SUCCESS');
})();

View File

@@ -0,0 +1,19 @@
import { test as test1, expect as expect1, mergeTests, mergeExpects } from '@playwright/test';
import type { Page } from '@playwright/test';
import { test as test2, expect as expect2 } from 'playwright-test-plugin';
const test = mergeTests(test1, test2);
const expect = mergeExpects(expect1, expect2);
test('sample test', async ({ page, plugin }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
type IsString = (typeof plugin) extends string ? true : never;
const isString: IsString = true;
await page.setContent('<div>hello world</div>');
await expect(page).toContainText('hello');
// @ts-expect-error
await expect(page).toContainText(123);
});

View File

@@ -0,0 +1,57 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { test, expect } from '@playwright/test';
import type { Reporter, TestCase } from '@playwright/test/reporter';
test.use({ locale: 'en-US' });
test.describe('block', () => {
test.beforeAll(async ({ browser }) => {
});
test.afterAll(async ({ browser }) => {
});
test.beforeEach(async ({ page }) => {
});
test.afterEach(async ({ page }) => {
});
test('should work', async ({ page, browserName }, testInfo) => {
test.skip(browserName === 'chromium');
await page.click(testInfo.title);
testInfo.annotations.push({ type: 'foo' });
await page.fill(testInfo.outputPath('foo', 'bar'), testInfo.outputDir);
});
});
const test2 = test.extend<{ foo: string, bar: number }>({
foo: '123',
bar: async ({ foo }, use) => {
await use(parseInt(foo, 10));
},
});
test2('should work 2', async ({ foo, bar }) => {
bar += parseInt(foo, 10);
expect(bar).toBe(123 * 2);
});
export class MyReporter implements Reporter {
onTestBegin(test: TestCase) {
test.titlePath().slice();
if (test.results[0].status === test.expectedStatus)
console.log(`Nice test ${test.title} at ${test.location.file}`);
}
}

View File

@@ -0,0 +1,16 @@
import { test as test1, expect as expect1, mergeTests, mergeExpects } from '@playwright/test';
import { test as test2, expect as expect2 } from 'playwright-test-plugin';
const test = mergeTests(test1, test2);
const expect = mergeExpects(expect1, expect2);
test('sample test', async ({ page, plugin }) => {
await page.setContent(`<div>hello</div><span>world</span>`);
expect(await page.textContent('span')).toBe('world');
console.log(`plugin value: ${plugin}`);
expect(plugin).toBe('hello from plugin');
await page.setContent('<div>hello world</div>');
await expect(page).toContainText('hello');
});

View File

@@ -0,0 +1,27 @@
const report = require(process.argv[2]);
if (report.suites[0].specs[0].title !== 'sample test') {
console.log(`Wrong spec title`);
process.exit(1);
}
const projects = report.suites[0].specs[0].tests.map(t => t.projectName).sort();
if (process.argv.slice(3).includes('--validate-chromium-project-only')) {
if (projects.length !== 1 || projects[0] !== 'chromium') {
console.log(`Wrong browsers`);
process.exit(1);
}
} else {
if (projects.length !== 3 || projects[0] !== 'chromium' || projects[1] !== 'firefox' || projects[2] !== 'webkit') {
console.log(`Wrong browsers`);
process.exit(1);
}
}
for (const test of report.suites[0].specs[0].tests) {
if (test.results[0].status !== 'passed') {
console.log(`Test did not pass`);
process.exit(1);
}
}
console.log('Report check SUCCESS');
process.exit(0);

View File

@@ -0,0 +1,6 @@
const { test, expect } = require('@playwright/test');
test('sample test', async ({ page }) => {
await page.setContent(`<div>hello</div><span>world</span>`);
expect(await page.textContent('span')).toBe('world');
});

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const { _electron: electron } = require('@playwright/test');
const path = require('path');
(async () => {
const application = await electron.launch({
args: [path.join(__dirname, 'electron-app.js')],
});
const appPath = await application.evaluate(async ({ app }) => app.getAppPath());
await application.close();
if (appPath !== __dirname)
throw new Error(`Malformed app path: got "${appPath}", expected "${__dirname}"`);
console.log(`@playwright/test electron SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -0,0 +1,56 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const requireName = process.argv[2];
const success = process.argv.slice(3);
const playwright = require(requireName);
const packageJSON = require(requireName + '/package.json');
if (!packageJSON || !packageJSON.version) {
console.error('Should be able to require the package.json and get the version.')
process.exit(1);
}
(async () => {
for (const browserType of success) {
try {
const browser = await playwright[browserType].launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.evaluate(() => navigator.userAgent);
await browser.close();
} catch (e) {
console.error(`Should be able to launch ${browserType} from ${requireName}`);
console.error(e);
process.exit(1);
}
}
const fail = ['chromium', 'webkit', 'firefox'].filter(x => !success.includes(x));
for (const browserType of fail) {
try {
await playwright[browserType].launch();
console.error(`Should not be able to launch ${browserType} from ${requireName}`);
process.exit(1);
} catch (e) {
// All good.
console.log(`Expected error while launching ${browserType}: ${e}`);
}
}
console.log(`require SUCCESS`);
})().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const requireName = process.argv[2];
const success = process.argv.slice(3);
const playwright = require(requireName);
const fs = require('fs');
(async () => {
for (const browserType of success) {
try {
const browser = await playwright[browserType].launch({});
const context = await browser.newContext({
recordVideo: { dir: __dirname, size: {width: 320, height: 240} },
});
await context.newPage();
// Wait for 1 second to actually record something.
await new Promise(x => setTimeout(x, 1000));
await context.close();
await browser.close();
const videoFile = fs.readdirSync(__dirname).find(name => name.endsWith('webm'));
if (!videoFile) {
console.error(`ERROR: Package "${requireName}", browser "${browserType}" should have created screencast!`);
process.exit(1);
}
} catch (err) {
console.error(`ERROR: Should be able to launch ${browserType} from ${requireName}`);
console.error(err);
process.exit(1);
}
}
})();

View File

@@ -0,0 +1,10 @@
const playwright = require('playwright');
process.env.PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = 1;
(async () => {
const browser = await playwright.chromium.launch({
executablePath: playwright.chromium.executablePath()
});
await browser.close();
})();