From f584c3190fc723c4c4d0e95b19d71b72b04e09a5 Mon Sep 17 00:00:00 2001 From: Haiping Chen Date: Thu, 23 May 2024 07:05:36 -0500 Subject: [PATCH] Fix UserService. --- .../Browsing/Models/BrowserActionResult.cs | 5 +++++ .../Browsing/Models/ElementLocatingArgs.cs | 5 +++++ .../Users/Services/UserService.cs | 2 +- .../PlaywrightWebDriver.LocateElement.cs | 20 ++++++++++++++++--- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/BrowserActionResult.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/BrowserActionResult.cs index a634cccd..b3576b90 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/BrowserActionResult.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/BrowserActionResult.cs @@ -8,4 +8,9 @@ public class BrowserActionResult public string Selector { get; set; } public string Body { get; set; } public bool IsHighlighted { get; set; } + + public override string ToString() + { + return $"{IsSuccess} - {Selector}"; + } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs index 6d6411d8..3b96c760 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Browsing/Models/ElementLocatingArgs.cs @@ -5,6 +5,9 @@ public class ElementLocatingArgs [JsonPropertyName("match_rule")] public string MatchRule { get; set; } = string.Empty; + [JsonPropertyName("tag")] + public string? Tag { get; set; } = null!; + [JsonPropertyName("text")] public string? Text { get; set; } @@ -20,6 +23,8 @@ public class ElementLocatingArgs [JsonPropertyName("selector")] public string? Selector { get; set; } + public bool Parent { get; set; } + public bool FailIfMultiple { get; set; } /// diff --git a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs index de4c12c8..4324b6f7 100644 --- a/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs +++ b/src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs @@ -77,7 +77,7 @@ public class UserService : IUserService record = db.GetUserByUserName(id); } - User? user = null; + User? user = record; var hooks = _services.GetServices(); if (record == null || record.Source != "internal") { diff --git a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs index 13b0464c..df6e0a7d 100644 --- a/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs +++ b/src/Plugins/BotSharp.Plugin.WebDriver/Drivers/PlaywrightDriver/PlaywrightWebDriver.LocateElement.cs @@ -24,6 +24,12 @@ public partial class PlaywrightWebDriver count = await locator.CountAsync(); } + if (location.Tag != null) + { + locator = page.Locator(location.Tag); + count = await locator.CountAsync(); + } + // try attribute if (!string.IsNullOrEmpty(location.AttributeName)) { @@ -66,12 +72,20 @@ public partial class PlaywrightWebDriver } else if (count == 1) { + if (location.Parent) + { + locator = locator.Locator(".."); + } + result.Selector = locator.ToString().Split('@').Last(); // Make sure the element is visible - await locator.EvaluateAsync("element => element.style.height = ''"); - await locator.EvaluateAsync("element => element.style.width = ''"); - await locator.EvaluateAsync("element => element.style.opacity = ''"); + /*if (!await locator.IsVisibleAsync()) + { + await locator.EvaluateAsync("element => element.style.height = '15px'"); + await locator.EvaluateAsync("element => element.style.width = '15px'"); + await locator.EvaluateAsync("element => element.style.opacity = '1.0'"); + }*/ var text = await locator.InnerTextAsync(); result.Body = text;