test: fix CR proxy tests on Windows (#7675)

This commit is contained in:
Max Schmitt 2021-07-19 17:50:14 +02:00 committed by GitHub
parent d03a54da64
commit d5bb8a327b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View File

@ -21,11 +21,17 @@ it.use({ proxy: { server: 'per-context' } });
it('should throw for missing global proxy on Chromium Windows', async ({ browserName, platform, browserType, browserOptions, server }) => { it('should throw for missing global proxy on Chromium Windows', async ({ browserName, platform, browserType, browserOptions, server }) => {
it.skip(browserName !== 'chromium' || platform !== 'win32'); it.skip(browserName !== 'chromium' || platform !== 'win32');
delete browserOptions.proxy; let browser;
const browser = await browserType.launch(browserOptions); try {
browser = await browserType.launch({
...browserOptions,
proxy: undefined,
});
const error = await browser.newContext({ proxy: { server: `localhost:${server.PORT}` } }).catch(e => e); const error = await browser.newContext({ proxy: { server: `localhost:${server.PORT}` } }).catch(e => e);
expect(error.toString()).toContain('Browser needs to be launched with the global proxy'); expect(error.toString()).toContain('Browser needs to be launched with the global proxy');
} finally {
await browser.close(); await browser.close();
}
}); });
it('should work when passing the proxy only on the context level', async ({browserName, platform, browserType, browserOptions, contextOptions, server}) => { it('should work when passing the proxy only on the context level', async ({browserName, platform, browserType, browserOptions, contextOptions, server}) => {
@ -36,8 +42,12 @@ it('should work when passing the proxy only on the context level', async ({brows
server.setRoute('/target.html', async (req, res) => { server.setRoute('/target.html', async (req, res) => {
res.end('<html><title>Served by the proxy</title></html>'); res.end('<html><title>Served by the proxy</title></html>');
}); });
delete browserOptions.proxy; let browser;
const browser = await browserType.launch(browserOptions); try {
browser = await browserType.launch({
...browserOptions,
proxy: undefined,
});
const context = await browser.newContext({ const context = await browser.newContext({
...contextOptions, ...contextOptions,
proxy: { server: `localhost:${server.PORT}` } proxy: { server: `localhost:${server.PORT}` }
@ -46,7 +56,9 @@ it('should work when passing the proxy only on the context level', async ({brows
const page = await context.newPage(); const page = await context.newPage();
await page.goto('http://non-existent.com/target.html'); await page.goto('http://non-existent.com/target.html');
expect(await page.title()).toBe('Served by the proxy'); expect(await page.title()).toBe('Served by the proxy');
} finally {
await browser.close(); await browser.close();
}
}); });
it('should throw for bad server value', async ({ contextFactory }) => { it('should throw for bad server value', async ({ contextFactory }) => {

View File

@ -381,6 +381,7 @@ it('should have connection details', async ({ contextFactory, server, browserNam
it('should have security details', async ({ contextFactory, httpsServer, browserName, platform }, testInfo) => { it('should have security details', async ({ contextFactory, httpsServer, browserName, platform }, testInfo) => {
it.fail(browserName === 'webkit' && platform === 'linux', 'https://github.com/microsoft/playwright/issues/6759'); it.fail(browserName === 'webkit' && platform === 'linux', 'https://github.com/microsoft/playwright/issues/6759');
it.fail(browserName === 'webkit' && platform === 'win32');
const { page, getLog } = await pageWithHar(contextFactory, testInfo); const { page, getLog } = await pageWithHar(contextFactory, testInfo);
await page.goto(httpsServer.EMPTY_PAGE); await page.goto(httpsServer.EMPTY_PAGE);
@ -388,9 +389,7 @@ it('should have security details', async ({ contextFactory, httpsServer, browser
const { serverIPAddress, _serverPort: port, _securityDetails: securityDetails } = log.entries[0]; const { serverIPAddress, _serverPort: port, _securityDetails: securityDetails } = log.entries[0];
expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/); expect(serverIPAddress).toMatch(/^127\.0\.0\.1|\[::1\]/);
expect(port).toBe(httpsServer.PORT); expect(port).toBe(httpsServer.PORT);
if (browserName === 'webkit' && platform === 'win32') if (browserName === 'webkit' && platform === 'darwin')
expect(securityDetails).toEqual({subjectName: 'puppeteer-tests', validFrom: 1550084863, validTo: -1});
else if (browserName === 'webkit')
expect(securityDetails).toEqual({protocol: 'TLS 1.3', subjectName: 'puppeteer-tests', validFrom: 1550084863, validTo: 33086084863}); expect(securityDetails).toEqual({protocol: 'TLS 1.3', subjectName: 'puppeteer-tests', validFrom: 1550084863, validTo: 33086084863});
else else
expect(securityDetails).toEqual({issuer: 'puppeteer-tests', protocol: 'TLS 1.3', subjectName: 'puppeteer-tests', validFrom: 1550084863, validTo: 33086084863}); expect(securityDetails).toEqual({issuer: 'puppeteer-tests', protocol: 'TLS 1.3', subjectName: 'puppeteer-tests', validFrom: 1550084863, validTo: 33086084863});