Untitled
unknown
csharp
2 years ago
2.5 kB
12
Indexable
using Microsoft.Playwright;
using NUnit.Framework;
namespace PlaywrightSessionPOC
{
public class Hooks
{
public IBrowser? Browser { get; set; }
public IBrowserContext? BrowserContext { get; set; }
public IBrowserContext? BrowserContext2 { get; set; }
public IPage Page { get; set; }
[OneTimeSetUp]
public async Task BeforeAll()
{
var playwright = await Playwright.CreateAsync();
this.Browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
{
Headless = false
});
this.BrowserContext = await Browser.NewContextAsync();
this.Page = await BrowserContext.NewPageAsync();
await Page.GotoAsync("https://bmsdststoragetst.z6.web.core.windows.net");
await Page.WaitForLoadStateAsync(LoadState.Load);
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
await Page.FillAsync("#UserNameOrEmail", "asdfsfsdf@levi9.com");
await Page.FillAsync("#Password", "sdfsdfsdf");
await Page.ClickAsync(".login-button");
await Page.WaitForLoadStateAsync(LoadState.Load);
await Page.WaitForLoadStateAsync(LoadState.NetworkIdle);
await BrowserContext.StorageStateAsync(new()
{
Path = @"C:\PlaywrightSessionPOC\state.json"
});
await Page.CloseAsync();
}
[SetUp]
public async Task BeforeTest()
{
this.BrowserContext2 = await Browser.NewContextAsync(new()
{
StorageStatePath = @"C:\PlaywrightSessionPOC\state.json"
});
this.Page = await BrowserContext2.NewPageAsync();
}
[TearDown]
public async Task AfterTest()
{
await this.Page.CloseAsync();
}
[OneTimeTearDown]
public static void AfterAll()
{
}
}
}
namespace PlaywrightSessionPOC
{
[TestFixture]
public class Tests : Hooks
{
[Test]
public async Task GotoOrderOverview ()
{
await Page.GotoAsync("https://bmsdsts.z6.web.core.windows.net/sales/quotes?index=0&size=10&sortingDirection=desc&sortingKey=CreatedDate");
Thread.Sleep(5000);
}
}
}Editor is loading...
Leave a Comment