chore: make csharp library codegen more csharp like (#28663)
This commit is contained in:
parent
9c845365f7
commit
44c3ad5ceb
|
|
@ -53,7 +53,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
|
|||
generateAction(actionInContext: ActionInContext): string {
|
||||
const action = this._generateActionInner(actionInContext);
|
||||
if (action)
|
||||
return action + '\n';
|
||||
return action;
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
|
|||
let pageAlias = actionInContext.frame.pageAlias;
|
||||
if (this._mode !== 'library')
|
||||
pageAlias = pageAlias.replace('page', 'Page');
|
||||
const formatter = new CSharpFormatter(8);
|
||||
const formatter = new CSharpFormatter(this._mode === 'library' ? 0 : 8);
|
||||
|
||||
if (action.name === 'openPage') {
|
||||
formatter.add(`var ${pageAlias} = await context.NewPageAsync();`);
|
||||
|
|
@ -184,10 +184,6 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static async Task Main()
|
||||
{
|
||||
using var playwright = await Playwright.CreateAsync();
|
||||
await using var browser = await playwright.${toPascal(options.browserName)}.LaunchAsync(${formatObject(options.launchOptions, ' ', 'BrowserTypeLaunchOptions')});
|
||||
var context = await browser.NewContextAsync(${formatContextOptions(options.contextOptions, options.deviceName)});`);
|
||||
|
|
@ -220,9 +216,11 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
|
|||
}
|
||||
|
||||
generateFooter(saveStorage: string | undefined): string {
|
||||
const storageStateLine = saveStorage ? `\n await context.StorageStateAsync(new BrowserContextStorageStateOptions\n {\n Path = ${quote(saveStorage)}\n });\n` : '';
|
||||
return `${storageStateLine} }
|
||||
}\n`;
|
||||
const offset = this._mode === 'library' ? '' : ' ';
|
||||
let storageStateLine = saveStorage ? `\n${offset}await context.StorageStateAsync(new BrowserContextStorageStateOptions\n${offset}{\n${offset} Path = ${quote(saveStorage)}\n${offset}});\n` : '';
|
||||
if (this._mode !== 'library')
|
||||
storageStateLine += ` }\n}\n`;
|
||||
return storageStateLine;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,10 +33,6 @@ test('should print the correct imports and context options', async ({ browserNam
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static async Task Main()
|
||||
{
|
||||
using var playwright = await Playwright.CreateAsync();
|
||||
await using var browser = await playwright.${capitalize(browserName)}.LaunchAsync(new BrowserTypeLaunchOptions
|
||||
{
|
||||
|
|
@ -231,7 +227,6 @@ public class Tests : PageTest
|
|||
public async Task MyTest()
|
||||
{
|
||||
await Page.GotoAsync("${emptyHTML}");
|
||||
|
||||
}
|
||||
}`;
|
||||
expect(cli.text()).toContain(expected);
|
||||
|
|
@ -259,7 +254,6 @@ public class Tests : PageTest
|
|||
public async Task MyTest()
|
||||
{
|
||||
await Page.GotoAsync("${emptyHTML}");
|
||||
|
||||
}
|
||||
}`;
|
||||
expect(cli.text()).toContain(expected);
|
||||
|
|
|
|||
Loading…
Reference in a new issue