using Microsoft.Playwright;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
using System.Threading.Tasks;
using WebullApi;
namespace tests
{
public class Test1 : ContextTest
{
private TradingPage _tradingPage;
[SetUp]
public async Task Setup()
{
string email = "[email protected]";
string password = "Asmallamountofmilk13";
var page = await Context.NewPageAsync();
var loginPage = await new HomePage(page)
.ClickLoginAsync();
var centerPage = await loginPage.LoginViaEmailAsync(email, password);
_tradingPage = await centerPage.ClickTrade();
}
[Test]
public async Task Test()
{
await _tradingPage.Trade();
}
}
//private async Task LoginAsync()û
//{
// playwright = await Playwright.CreateAsync();
// browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
// { Headless = false, SlowMo = 50, });
// Context = await browser.NewContextAsync();
// await Context.StorageStateAsync(new BrowserContextStorageStateOptions
// {
// Path = "state.json"
// });
// page = await Context.NewPageAsync();
// await page.GotoAsync(HttpsWwwDemoblazeComCartHtml);
// await page.ClickAsync("a:has-text('Log In')");
// await Helpers.Login("[email protected]@gmail.com", "12345678", page);
//}
}
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
#nullable enable
namespace Microsoft.Playwright
{
public class BrowserContextStorageStateOptions
{
public BrowserContextStorageStateOptions() { }
public BrowserContextStorageStateOptions(BrowserContextStorageStateOptions clone)
{
if (clone == null)
{
return;
}
Path = clone.Path;
}
/// <summary>
/// <para>
/// The file path to save the storage state to. If <paramref name="path"/> is a relative
/// path, then it is resolved relative to current working directory. If no path is provided,
/// storage state is still returned, but won't be saved to the disk.
/// </para>
/// </summary>
[JsonPropertyName("path")]
public string? Path { get; set; }
}
}
#nullable disable
using Microsoft.Playwright;
using System.Threading.Tasks;
namespace manaTest.Helpers
{
public static class IPageExtensions
{
private static volatile TaskCompletionSource<IPage> loginPageTask;
public static async Task<IPage> DoLogin(this Task<IPage> targetPage)
{
if (null == loginPageTask)
{
loginPageTask ??= new TaskCompletionSource<IPage>();
var loginPage = await handleLoginStep();
loginPageTask.TrySetResult(loginPage);
return loginPage;
}
await loginPageTask.Task;
return await targetPage;
async Task<IPage> handleLoginStep()
{
var loginPage = await targetPage;
await loginPage.GotoAsync("https://localhost:44364");
await loginPage.WaitForTimeoutAsync(15000);
//const string LoginButtonSelector = "text=Login";
//await loginPage.ClickAsync(LoginButtonSelector);
//await loginPage.WaitForTimeoutAsync(10000);
//var options = new PageWaitForNavigationOptions { UrlString = "https://localhost:44364" };
//await loginPage.WaitForNavigationAsync(options);
//await loginPage.WaitForLoadStateAsync(LoadState.NetworkIdle);
var contextStateOptions = new BrowserContextStorageStateOptions
{
Path = PageFactory.StorageStatePath,
};
await loginPage.Context.StorageStateAsync(contextStateOptions);
return loginPage;
}
}
}
}