public async Task ClickHidingButton() { var context = await Browser.NewContextAsync(); page = await context.NewPageAsync(); await page.GoToAsync(_PageUrl); await page.ClickAsync("//a[text()='Scrollbars']"); await page.ClickAsync("#hidingButton"); }
private async Task HandleRecoveryPrompts(IPage page) { //Check for recovery prompts bool clickedConfirm = false; for (int i = 0; i < 300; i++) { if (await page.QuerySelectorAsync("#avatar-btn") is not null) { break; } if (!clickedConfirm && await page.QuerySelectorAsync(":text('Confirm your recovery email')") is { } confirmEmailLink) { await confirmEmailLink.ClickAsync(); clickedConfirm = true; } if (await page.QuerySelectorAsync("input[type=\"email\"]") is { } email&& !string.Equals(RecoveryEmail, await email.GetInnerTextAsync())) { await CaptureStateAsync(page); await page.TypeAsync("input[type=\"email\"]", RecoveryEmail); await page.ClickAsync(":text('Next')"); await CaptureStateAsync(page); break; } await Task.Delay(200); } }
public async Task AlteraCidade() { var context = await Browser.NewContextAsync(); page = await context.NewPageAsync(); await page.GoToAsync(_url); await page.HoverAsync(".location"); await page.ClickAsync("[id='form-troca-cidade'] .icon"); await page.ClickAsync("[for='citySlug']"); await page.ClickAsync("[data-value='salvador']"); }
public async Task Login(string testStep) { await page.FillAsync(txtUserName, Excel.GetValueFromTestStep(testStep, "Email")); await page.FillAsync(txtPassword, Excel.GetValueFromTestStep(testStep, "Password")); await page.ClickAsync(btnSubmit); await ShouldDisableTimeoutWhenItsSetTo0(); await page.WaitForSelectorAsync(Home); //.. await page.ClickAsync(kk); // await page.WaitForSelectorAsync(Home); // await page.ClickAsync(pr); // await page.ClickAsync(pr); }
public async Task ClickOn(string locator) { await page.WaitForSelectorAsync(locator); await page.WaitForTimeoutAsync(20000); await page.ClickAsync(locator); }
public Task LoginUsingForm(string email, string name) { _page.TypeAsync(Cy.InputName("EmailLogin"), email).ConfigureAwait(false).GetAwaiter().GetResult(); _page.TypeAsync(Cy.InputName("NameLogin"), name).ConfigureAwait(false).GetAwaiter().GetResult(); _page.ClickAsync(Cy.Name("LoginButton")).ConfigureAwait(false).GetAwaiter().GetResult(); _page.WaitForTimeoutAsync(1000).MakeItSync(); return(Task.CompletedTask); }
public async Task ShouldAcceptDownloads() { var downloadTask = _page.WaitForEvent(PageEvent.Download); await TaskUtils.WhenAll( downloadTask, _page.ClickAsync("a")); var download = downloadTask.Result.Download; Assert.Equal($"{TestConstants.ServerUrl}/download", download.Url); Assert.Equal("file.txt", download.SuggestedFilename); string path = await download.GetPathAsync(); Assert.True(new FileInfo(path).Exists); }
public async Task LoginAs(string userName, string password) { await _page.TypeAsync("#txtUserName", userName); await _page.TypeAsync("#txtPassword", password); await _page.ClickAsync("#btnLogin"); }
public async Task WaitForProgress() { var context = await Browser.NewContextAsync(); page = await context.NewPageAsync(); await page.GoToAsync(_PageUrl); await page.ClickAsync("//a[text()='Progress Bar']"); await page.ClickAsync("#startButton"); await page.GetInnerTextAsync("#progressBar[aria-valuenow='75']"); await page.ClickAsync("#stopButton"); var outcome = await page.GetInnerTextAsync("#result"); }
public async Task ShouldClickAButtonWhenItOverlaysOopif() { await _page.GoToAsync(TestConstants.ServerUrl + "/button-overlay-oopif.html"); Assert.Equal(1, await CountOOPIFsASync(_browser)); await _page.ClickAsync("button"); Assert.True(await _page.EvaluateAsync <bool?>("() => window.BUTTON_CLICKED")); }
private async Task TestBasicNavigation(IPage page) { var socket = BrowserContextInfo.Pages[page].WebSockets.SingleOrDefault() ?? (await page.WaitForEventAsync(PageEvent.WebSocket)).WebSocket; // Receive render batch await socket.WaitForEventAsync(WebSocketEvent.FrameReceived); await socket.WaitForEventAsync(WebSocketEvent.FrameSent); // JS interop call to intercept navigation await socket.WaitForEventAsync(WebSocketEvent.FrameReceived); await socket.WaitForEventAsync(WebSocketEvent.FrameSent); await page.WaitForSelectorAsync("ul"); // <title> element gets project ID injected into it during template execution Assert.Equal(Project.ProjectName.Trim(), (await page.GetTitleAsync()).Trim()); // Initially displays the home page await page.WaitForSelectorAsync("h1 >> text=Hello, world!"); // Can navigate to the counter page await page.ClickAsync("a[href=counter] >> text=Counter"); await page.WaitForSelectorAsync("h1+p >> text=Current count: 0"); // Clicking the counter button works await page.ClickAsync("p+button >> text=Click me"); await page.WaitForSelectorAsync("h1+p >> text=Current count: 1"); // Can navigate to the 'fetch data' page await page.ClickAsync("a[href=fetchdata] >> text=Fetch data"); await page.WaitForSelectorAsync("h1 >> text=Weather forecast"); // Asynchronously loads and displays the table of weather forecasts await page.WaitForSelectorAsync("table>tbody>tr"); Assert.Equal(5, (await page.QuerySelectorAllAsync("p+table>tbody>tr")).Count()); }
public static async Task InjectExisintgToDoCard(IPage page) { var key = "todos-mithril"; dynamic value = new ExpandoObject(); value.title = CardTitle; value.completed = CardCompletedStatus; value.editing = CardEditingStatus; value.key = CardKey; var stringified = Newtonsoft.Json.JsonConvert.SerializeObject(new[] { value }); await page.EvaluateAsync($"window.localStorage.setItem('{key}','{stringified}')"); await page.ReloadAsync(); await page.ClickAsync("a[href*='completed']"); }
public async Task DynamicTable() { var context = await Browser.NewContextAsync(); page = await context.NewPageAsync(); await page.GoToAsync(_PageUrl); await page.ClickAsync("//a[text()='Dynamic Table']"); var columns = await page.GetInnerHtmlAsync("//span[text()='CPU']/.."); int CPUColumnNumber = GetColumnNumber(columns); var ChromeCPUText = await page.GetInnerTextAsync($"//span[text()='Chrome']/../span[{CPUColumnNumber}]"); var ComparisonText = await page.GetInnerTextAsync(".bg-warning"); Assert.Equal(ComparisonText, $"Chrome CPU: {ChromeCPUText}"); }
public async Task Login_NoUsernameOrPasswordEntered_UserNameAndPasswordValidationMessagesDisplay() { // Given await singlePage.GotoAsync(testUrl); // When await singlePage.ClickAsync("#btnLogin"); // Then var userNameValText = await singlePage.WaitForSelectorAsync("#username-error"); var passwordValText = await singlePage.WaitForSelectorAsync("#password-error"); Assert.That(userNameValText.InnerTextAsync, Is.EqualTo("username is required"), "Username validation message did not display as expected."); Assert.That(passwordValText.InnerTextAsync, Is.EqualTo("password is required"), "Password validation message did not display as expected."); }
public async Task WhenIClickChannel(string p0) { var selector = $"//*[@href='#iplayer-icon-{p0.ToLower().Replace(" ", "")}-active']"; await _page.ClickAsync(selector); }
private async Task TestBasicNavigation(IPage page) { var socket = await page.WaitForWebSocketAsync(); var framesReceived = 0; var framesSent = 0; void FrameReceived(object sender, IWebSocketFrame frame) { framesReceived++; } void FrameSent(object sender, IWebSocketFrame frame) { framesSent++; } socket.FrameReceived += FrameReceived; socket.FrameSent += FrameSent; // Receive render batch await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesReceived == 1 }); await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesSent == 1 }); // JS interop call to intercept navigation await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesReceived == 2 }); await page.WaitForWebSocketAsync(new() { Predicate = (s) => framesSent == 2 }); socket.FrameReceived -= FrameReceived; socket.FrameSent -= FrameSent; await page.WaitForSelectorAsync("nav"); // <title> element gets project ID injected into it during template execution Assert.Equal("Index", (await page.TitleAsync()).Trim()); // Initially displays the home page await page.WaitForSelectorAsync("h1 >> text=Hello, world!"); // Can navigate to the counter page await page.ClickAsync("a[href=counter] >> text=Counter"); await page.WaitForSelectorAsync("h1+p >> text=Current count: 0"); // Clicking the counter button works await page.ClickAsync("p+button >> text=Click me"); await page.WaitForSelectorAsync("h1+p >> text=Current count: 1"); // Can navigate to the 'fetch data' page await page.ClickAsync("a[href=fetchdata] >> text=Fetch data"); await page.WaitForSelectorAsync("h1 >> text=Weather forecast"); // Asynchronously loads and displays the table of weather forecasts await page.WaitForSelectorAsync("table>tbody>tr"); Assert.Equal(5, await page.Locator("p+table>tbody>tr").CountAsync()); }
/// <summary> /// Click a target using a random release delay /// </summary> /// <param name="page">"\_(^_^)_/"</param> /// <param name="selector">Query selector</param> /// <param name="random">Random generator</param> public static async Task ClickAsync(IPage page, string selector, Random random = default) { await page.ClickAsync(selector, TaskUtils.GetRandomDelay(random, 50, 300)) .ConfigureAwait(false); }
public Task ClickAddNewPerson() { _page.ClickAsync(Cy.Name("AddNewPerson")).MakeItSync(); return(Task.CompletedTask); }
public async Task ClickPageAsync(IPage page, BotData botData) => await page.ClickAsync(Selector);
public async Task WhenIClickNewsMenu(string p0) { await _page.ClickAsync($"text={p0}"); }
public async Task SwitchToCompleted() { await _page.ClickAsync("a[href*='completed']"); }
private async Task TestBasicNavigation(string appName, IPage page, bool usesAuth = false, bool skipFetchData = false) { await page.WaitForSelectorAsync("ul"); // <title> element gets project ID injected into it during template execution Assert.Equal(appName.Trim(), (await page.GetTitleAsync()).Trim()); // Initially displays the home page await page.WaitForSelectorAsync("h1 >> text=Hello, world!"); // Can navigate to the counter page await Task.WhenAll( page.WaitForNavigationAsync("**/counter"), page.WaitForSelectorAsync("h1 >> text=Counter"), page.WaitForSelectorAsync("p >> text=Current count: 0"), page.ClickAsync("a[href=counter]")); // Clicking the counter button works await Task.WhenAll( page.WaitForSelectorAsync("p >> text=Current count: 1"), page.ClickAsync("p+button >> text=Click me")); if (usesAuth) { await Task.WhenAll( page.WaitForNavigationAsync("**/Identity/Account/Login**", LifecycleEvent.Networkidle), page.ClickAsync("text=Log in")); await Task.WhenAll( page.WaitForSelectorAsync("[name=\"Input.Email\"]"), page.WaitForNavigationAsync("**/Identity/Account/Register**", LifecycleEvent.Networkidle), page.ClickAsync("text=Register as a new user")); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; await page.TypeAsync("[name=\"Input.Email\"]", userName); await page.TypeAsync("[name=\"Input.Password\"]", password); await page.TypeAsync("[name=\"Input.ConfirmPassword\"]", password); // We will be redirected to the RegisterConfirmation await Task.WhenAll( page.WaitForNavigationAsync("**/Identity/Account/RegisterConfirmation**", LifecycleEvent.Networkidle), page.ClickAsync("#registerSubmit")); // We will be redirected to the ConfirmEmail await Task.WhenAll( page.WaitForNavigationAsync("**/Identity/Account/ConfirmEmail**", LifecycleEvent.Networkidle), page.ClickAsync("text=Click here to confirm your account")); // Now we can login await page.ClickAsync("text=Login"); await page.WaitForSelectorAsync("[name=\"Input.Email\"]"); await page.TypeAsync("[name=\"Input.Email\"]", userName); await page.TypeAsync("[name=\"Input.Password\"]", password); await page.ClickAsync("#login-submit"); // Need to navigate to fetch page await page.GoToAsync(new Uri(page.Url).GetLeftPart(UriPartial.Authority)); Assert.Equal(appName.Trim(), (await page.GetTitleAsync()).Trim()); } if (!skipFetchData) { // Can navigate to the 'fetch data' page await Task.WhenAll( page.WaitForNavigationAsync("**/fetchdata"), page.WaitForSelectorAsync("h1 >> text=Weather forecast"), page.ClickAsync("text=Fetch data")); // Asynchronously loads and displays the table of weather forecasts await page.WaitForSelectorAsync("table>tbody>tr"); Assert.Equal(5, (await page.QuerySelectorAllAsync("p+table>tbody>tr")).Count()); } }
private static async Task TestBasicNavigation(string appName, IPage page, bool usesAuth = false, bool skipFetchData = false) { await page.WaitForSelectorAsync("nav"); // Initially displays the home page await page.WaitForSelectorAsync("h1 >> text=Hello, world!"); Assert.Equal("Index", (await page.TitleAsync()).Trim()); // Can navigate to the counter page await Task.WhenAll( page.WaitForNavigationAsync(new() { UrlString = "**/counter" }), page.WaitForSelectorAsync("h1 >> text=Counter"), page.WaitForSelectorAsync("p >> text=Current count: 0"), page.ClickAsync("a[href=counter]")); // Clicking the counter button works await Task.WhenAll( page.WaitForSelectorAsync("p >> text=Current count: 1"), page.ClickAsync("p+button >> text=Click me")); if (usesAuth) { await Task.WhenAll( page.WaitForNavigationAsync(new() { UrlString = "**/Identity/Account/Login**", WaitUntil = WaitUntilState.NetworkIdle }), page.ClickAsync("text=Log in")); await Task.WhenAll( page.WaitForSelectorAsync("[name=\"Input.Email\"]"), page.WaitForNavigationAsync(new() { UrlString = "**/Identity/Account/Register**", WaitUntil = WaitUntilState.NetworkIdle }), page.ClickAsync("text=Register as a new user")); var userName = $"{Guid.NewGuid()}@example.com"; var password = "******"; await page.TypeAsync("[name=\"Input.Email\"]", userName); await page.TypeAsync("[name=\"Input.Password\"]", password); await page.TypeAsync("[name=\"Input.ConfirmPassword\"]", password); // We will be redirected to the RegisterConfirmation await Task.WhenAll( page.WaitForNavigationAsync(new() { UrlString = "**/Identity/Account/RegisterConfirmation**", WaitUntil = WaitUntilState.NetworkIdle }), page.ClickAsync("#registerSubmit")); // We will be redirected to the ConfirmEmail await Task.WhenAll( page.WaitForNavigationAsync(new() { UrlString = "**/Identity/Account/ConfirmEmail**", WaitUntil = WaitUntilState.NetworkIdle }), page.ClickAsync("text=Click here to confirm your account")); // Now we can login await page.ClickAsync("text=Login"); await page.WaitForSelectorAsync("[name=\"Input.Email\"]"); await page.TypeAsync("[name=\"Input.Email\"]", userName); await page.TypeAsync("[name=\"Input.Password\"]", password); await page.ClickAsync("#login-submit"); // Need to navigate to fetch page await page.GotoAsync(new Uri(page.Url).GetLeftPart(UriPartial.Authority)); Assert.Equal(appName.Trim(), (await page.TitleAsync()).Trim()); } if (!skipFetchData) { // Can navigate to the 'fetch data' page await Task.WhenAll( page.WaitForNavigationAsync(new() { UrlString = "**/fetchdata" }), page.WaitForSelectorAsync("h1 >> text=Weather forecast"), page.ClickAsync("text=Fetch data")); // Asynchronously loads and displays the table of weather forecasts await page.WaitForSelectorAsync("table>tbody>tr"); Assert.Equal(5, await page.Locator("p+table>tbody>tr").CountAsync()); } }