fix(codegen): generate acceptDownloads option for download signals (#6697)
This commit is contained in:
parent
d1d49b3412
commit
f529f0a25d
|
|
@ -240,6 +240,8 @@ async function launchContext(options: Options, headless: boolean, executablePath
|
||||||
if (contextOptions.isMobile && browserType.name() === 'firefox')
|
if (contextOptions.isMobile && browserType.name() === 'firefox')
|
||||||
contextOptions.isMobile = undefined;
|
contextOptions.isMobile = undefined;
|
||||||
|
|
||||||
|
contextOptions.acceptDownloads = true;
|
||||||
|
|
||||||
// Proxy
|
// Proxy
|
||||||
|
|
||||||
if (options.proxyServer) {
|
if (options.proxyServer) {
|
||||||
|
|
@ -335,7 +337,9 @@ async function launchContext(options: Options, headless: boolean, executablePath
|
||||||
|
|
||||||
// Omit options that we add automatically for presentation purpose.
|
// Omit options that we add automatically for presentation purpose.
|
||||||
delete launchOptions.headless;
|
delete launchOptions.headless;
|
||||||
|
delete launchOptions.executablePath;
|
||||||
delete contextOptions.deviceScaleFactor;
|
delete contextOptions.deviceScaleFactor;
|
||||||
|
delete contextOptions.acceptDownloads;
|
||||||
return { browser, browserName: browserType.name(), context, contextOptions, launchOptions };
|
return { browser, browserName: browserType.name(), context, contextOptions, launchOptions };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,9 @@ export class CodeGenerator extends EventEmitter {
|
||||||
constructor(browserName: string, generateHeaders: boolean, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, deviceName: string | undefined, saveStorage: string | undefined) {
|
constructor(browserName: string, generateHeaders: boolean, launchOptions: LaunchOptions, contextOptions: BrowserContextOptions, deviceName: string | undefined, saveStorage: string | undefined) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
// Make a copy of options to modify them later.
|
||||||
launchOptions = { headless: false, ...launchOptions };
|
launchOptions = { headless: false, ...launchOptions };
|
||||||
delete launchOptions.executablePath;
|
contextOptions = { ...contextOptions };
|
||||||
this._enabled = generateHeaders;
|
this._enabled = generateHeaders;
|
||||||
this._options = { browserName, generateHeaders, launchOptions, contextOptions, deviceName, saveStorage };
|
this._options = { browserName, generateHeaders, launchOptions, contextOptions, deviceName, saveStorage };
|
||||||
this.restart();
|
this.restart();
|
||||||
|
|
@ -127,6 +128,11 @@ export class CodeGenerator extends EventEmitter {
|
||||||
signal(pageAlias: string, frame: Frame, signal: Signal) {
|
signal(pageAlias: string, frame: Frame, signal: Signal) {
|
||||||
if (!this._enabled)
|
if (!this._enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// We'll need to pass acceptDownloads for any generated downloads code to work.
|
||||||
|
if (signal.name === 'download')
|
||||||
|
this._options.contextOptions.acceptDownloads = true;
|
||||||
|
|
||||||
// Signal either arrives while action is being performed or shortly after.
|
// Signal either arrives while action is being performed or shortly after.
|
||||||
if (this._currentAction) {
|
if (this._currentAction) {
|
||||||
this._currentAction.action.signals.push(signal);
|
this._currentAction.action.signals.push(signal);
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,10 @@ test.describe('cli codegen', () => {
|
||||||
]);
|
]);
|
||||||
const sources = await recorder.waitForOutput('<javascript>', 'waitForEvent');
|
const sources = await recorder.waitForOutput('<javascript>', 'waitForEvent');
|
||||||
|
|
||||||
|
expect(sources.get('<javascript>').text).toContain(`
|
||||||
|
const context = await browser.newContext({
|
||||||
|
acceptDownloads: true
|
||||||
|
});`);
|
||||||
expect(sources.get('<javascript>').text).toContain(`
|
expect(sources.get('<javascript>').text).toContain(`
|
||||||
// Click text=Download
|
// Click text=Download
|
||||||
const [download] = await Promise.all([
|
const [download] = await Promise.all([
|
||||||
|
|
@ -257,24 +261,36 @@ test.describe('cli codegen', () => {
|
||||||
page.click('text=Download')
|
page.click('text=Download')
|
||||||
]);`);
|
]);`);
|
||||||
|
|
||||||
|
// TODO: fix generated options in java.
|
||||||
|
expect(sources.get('<java>').text).toContain(`
|
||||||
|
BrowserContext context = browser.newContext(new Browser.NewContextOptions());`);
|
||||||
expect(sources.get('<java>').text).toContain(`
|
expect(sources.get('<java>').text).toContain(`
|
||||||
// Click text=Download
|
// Click text=Download
|
||||||
Download download = page.waitForDownload(() -> {
|
Download download = page.waitForDownload(() -> {
|
||||||
page.click("text=Download");
|
page.click("text=Download");
|
||||||
});`);
|
});`);
|
||||||
|
|
||||||
|
expect(sources.get('<python>').text).toContain(`
|
||||||
|
context = browser.new_context(accept_downloads=True)`);
|
||||||
expect(sources.get('<python>').text).toContain(`
|
expect(sources.get('<python>').text).toContain(`
|
||||||
# Click text=Download
|
# Click text=Download
|
||||||
with page.expect_download() as download_info:
|
with page.expect_download() as download_info:
|
||||||
page.click(\"text=Download\")
|
page.click(\"text=Download\")
|
||||||
download = download_info.value`);
|
download = download_info.value`);
|
||||||
|
|
||||||
|
expect(sources.get('<async python>').text).toContain(`
|
||||||
|
context = await browser.new_context(accept_downloads=True)`);
|
||||||
expect(sources.get('<async python>').text).toContain(`
|
expect(sources.get('<async python>').text).toContain(`
|
||||||
# Click text=Download
|
# Click text=Download
|
||||||
async with page.expect_download() as download_info:
|
async with page.expect_download() as download_info:
|
||||||
await page.click(\"text=Download\")
|
await page.click(\"text=Download\")
|
||||||
download = await download_info.value`);
|
download = await download_info.value`);
|
||||||
|
|
||||||
|
expect(sources.get('<csharp>').text).toContain(`
|
||||||
|
var context = await browser.NewContextAsync(new BrowserNewContextOptions
|
||||||
|
{
|
||||||
|
AcceptDownloads = true,
|
||||||
|
});`);
|
||||||
expect(sources.get('<csharp>').text).toContain(`
|
expect(sources.get('<csharp>').text).toContain(`
|
||||||
// Click text=Download
|
// Click text=Download
|
||||||
var download1 = await page.RunAndWaitForEventAsync(PageEvent.Download, async () =>
|
var download1 = await page.RunAndWaitForEventAsync(PageEvent.Download, async () =>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue