Added screenshots to login method. Logs should reflect error messages encountered during login.

This commit is contained in:
William Lewis 2024-04-11 11:01:07 -05:00
parent 86d3cb9937
commit 4e50aa4e74
4 changed files with 19 additions and 0 deletions

View File

@ -23,6 +23,7 @@ bin/
Bin/ Bin/
obj/ obj/
Obj/ Obj/
screenshots/
# Sample Data # Sample Data
/SampleData /SampleData

View File

@ -46,6 +46,7 @@ public class CacheService : ICacheService
if (!internalKeys.TryGetValue(apiKey, out var clientId)) if (!internalKeys.TryGetValue(apiKey, out var clientId))
{ {
_logger.LogInformation("Could not find API key. Returning -1."); _logger.LogInformation("Could not find API key. Returning -1.");
PrintInternalKeys(internalKeys);
return -1; return -1;
} }

View File

@ -25,6 +25,8 @@ using Microsoft.Extensions.Logging;
using NuGet.Protocol.Core.Types; using NuGet.Protocol.Core.Types;
using AAIntegration.SimmonsBank.API.Models.Accounts; using AAIntegration.SimmonsBank.API.Models.Accounts;
using AAIntegration.SimmonsBank.API.Models.Transactions; using AAIntegration.SimmonsBank.API.Models.Transactions;
using System.Runtime.Serialization;
using Microsoft.Extensions.Logging.Console;
public interface IPuppeteerService public interface IPuppeteerService
{ {
@ -175,6 +177,13 @@ public class PuppeteerService : IPuppeteerService
{ {
//_logger.LogWarning($"Login Task timed out for user '{user.Id}' after {timeout} seconds"); //_logger.LogWarning($"Login Task timed out for user '{user.Id}' after {timeout} seconds");
_logger.LogError(0, ex, prefix + $"Login Task timed out after {timeout} seconds"); _logger.LogError(0, ex, prefix + $"Login Task timed out after {timeout} seconds");
await page.ScreenshotAsync(GenerateScreenshotPath());
string selector = @"document.querySelector('body > banno-web > bannoweb-login').shadowRoot.querySelector('div > jha-card > jha-error-message').innerHTML";
string errorMessage = await page.EvaluateExpressionAsync<string>(selector)
.WaitAsync(timeout, cancellationToken);
_logger.LogError(errorMessage);
return false; return false;
} }
finally finally
@ -185,6 +194,11 @@ public class PuppeteerService : IPuppeteerService
return false; return false;
} }
private string GenerateScreenshotPath()
{
return "screenshots/" + DateTime.UtcNow.ToString("yyyy-MM-dd_HHmmss.ffffzzz") + ".png";
}
public async Task<bool> IsLoggedIn(User user, CancellationToken cancellationToken) public async Task<bool> IsLoggedIn(User user, CancellationToken cancellationToken)
{ {
string prefix = $"Task::IsLoggedIn - {user.Id} - "; string prefix = $"Task::IsLoggedIn - {user.Id} - ";

View File

@ -63,6 +63,9 @@ public class PuppeteerWorker : BackgroundService
lastExecutedOn = DateTime.UtcNow; lastExecutedOn = DateTime.UtcNow;
_logger.LogInformation("PuppeteerWorker executed at: {time}", DateTimeOffset.Now); _logger.LogInformation("PuppeteerWorker executed at: {time}", DateTimeOffset.Now);
// TEMPORARY DON'T COMMIT!!!!
await Task.Delay(TimeSpan.FromMinutes(120), stoppingToken);
} }
} }
} }