Merge pull request #248 from hchen2020/master

Fix click element in WebDriver.
This commit is contained in:
Haiping 2024-01-05 11:19:24 -06:00 committed by GitHub
commit d19e39e9d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 35 additions and 10 deletions

View file

@ -4,6 +4,7 @@ public interface IUserIdentity
{
string Id { get; }
string Email { get; }
string UserName { get; }
string FirstName { get; }
string LastName { get; }
}

View file

@ -5,6 +5,7 @@ namespace BotSharp.Abstraction.Users.Models;
public class User
{
public string Id { get; set; } = string.Empty;
public string UserName { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;

View file

@ -23,6 +23,9 @@ public static class Utilities
return (splits[0], splits[1]);
}
/// <summary>
/// Flush cache
/// </summary>
public static void ClearCache()
{
// Clear whole cache.

View file

@ -17,6 +17,9 @@ public class UserIdentity : IUserIdentity
public string Id
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier)?.Value!;
public string UserName
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value!;
public string Email
=> _claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value!;

View file

@ -1,5 +1,4 @@
using BotSharp.Abstraction.Repositories;
using BotSharp.Abstraction.Repositories.Records;
using BotSharp.Abstraction.Users.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
@ -29,12 +28,15 @@ public class UserService : IUserService
}
record = user;
record.UserName = user.UserName.ToLower();
record.Email = user.Email.ToLower();
record.Salt = Guid.NewGuid().ToString("N");
record.Password = Utilities.HashText(user.Password, record.Salt);
record.ExternalId = _user.Id;
db.CreateUser(record);
Utilities.ClearCache();
return record;
}

View file

@ -1,10 +1,10 @@
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
namespace BotSharp.OpenAPI.ViewModels.Users;
public class UserCreationModel
{
public string UserName { get; set; } = string.Empty;
public string FirstName { get; set; } = string.Empty;
public string LastName { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
@ -15,6 +15,7 @@ public class UserCreationModel
{
return new User
{
UserName = UserName,
FirstName = FirstName,
LastName = LastName,
Email = Email,

View file

@ -1,6 +1,4 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Users.Enums;
using BotSharp.Abstraction.Users.Models;
using System.Text.Json.Serialization;
namespace BotSharp.OpenAPI.ViewModels.Users;
@ -8,6 +6,8 @@ namespace BotSharp.OpenAPI.ViewModels.Users;
public class UserViewModel
{
public string Id { get; set; }
[JsonPropertyName("user_name")]
public string UserName { get; set; }
[JsonPropertyName("first_name")]
public string FirstName { get; set; }
[JsonPropertyName("last_name")]
@ -32,6 +32,7 @@ public class UserViewModel
return new UserViewModel
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,

View file

@ -24,7 +24,7 @@ public class SignalRHub : Hub
public override async Task OnConnectedAsync()
{
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.UserIdentifier}) connected in {Context.ConnectionId} [{DateTime.Now}]");
_logger.LogInformation($"SignalR Hub: {_user.FirstName} {_user.LastName} ({Context.User.Identity.Name}) connected in {Context.ConnectionId}");
var hooks = _services.GetServices<IConversationHook>();
var convService = _services.GetRequiredService<IConversationService>();
@ -32,6 +32,7 @@ public class SignalRHub : Hub
if (!string.IsNullOrEmpty(conversationId))
{
_logger.LogInformation($"Connection {Context.ConnectionId} is with conversation {conversationId}");
var conv = await convService.GetConversation(conversationId);
if (conv != null)
{

View file

@ -2,6 +2,7 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class UserDocument : MongoBase
{
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }

View file

@ -117,6 +117,7 @@ public class MongoRepository : IBotSharpRepository
var users = _users.Select(x => new UserDocument
{
Id = !string.IsNullOrEmpty(x.Id) ? x.Id : Guid.NewGuid().ToString(),
UserName = x.UserName,
FirstName = x.FirstName,
LastName = x.LastName,
Salt = x.Salt,
@ -132,6 +133,7 @@ public class MongoRepository : IBotSharpRepository
{
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, user.Id);
var update = Builders<UserDocument>.Update
.Set(x => x.UserName, user.UserName)
.Set(x => x.FirstName, user.FirstName)
.Set(x => x.LastName, user.LastName)
.Set(x => x.Email, user.Email)
@ -868,6 +870,7 @@ public class MongoRepository : IBotSharpRepository
return user != null ? new User
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
@ -884,6 +887,7 @@ public class MongoRepository : IBotSharpRepository
return user != null ? new User
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
@ -901,6 +905,7 @@ public class MongoRepository : IBotSharpRepository
var userCollection = new UserDocument
{
Id = Guid.NewGuid().ToString(),
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Salt = user.Salt,

View file

@ -2,6 +2,7 @@ using BotSharp.Abstraction.Users;
using BotSharp.Abstraction.Users.Models;
using BotSharp.Core.Repository;
using Microsoft.EntityFrameworkCore;
using Senparc.Weixin.MP.AdvancedAPIs.MerChant;
using System;
using System.Collections.Generic;
using System.Text;
@ -21,6 +22,7 @@ namespace BotSharp.Plugin.WeChat.Users
{
var user = await userService.CreateUser(new User()
{
UserName = openId + "@" + appId + ".wechat",
Email = openId + "@" + appId + ".wechat",
Password = openId
});

View file

@ -14,7 +14,7 @@ public partial class PlaywrightWebDriver
foreach (var a in anchors)
{
var text = await a.TextContentAsync();
str.Add($"<a>{text}</a>");
str.Add($"<a>{(string.IsNullOrEmpty(text) ? "EMPTY" : text)}</a>");
}
var buttons = await body.QuerySelectorAllAsync("button");

View file

@ -10,7 +10,7 @@
"description": "website url."
}
},
"required": []
"required": ["url"]
}
},
{
@ -42,7 +42,7 @@
"description": "user input."
}
},
"required": ["element_name"]
"required": ["element_name", "input_text"]
}
}
]

View file

@ -1,4 +1,5 @@
{
"userName": "guest",
"firstName": "Guest",
"lastName": "Anonymous",
"email": "guest@gmail.com",

View file

@ -1,4 +1,5 @@
{
{
"userName": "haiping",
"firstName": "Haiping",
"lastName": "Chen",
"email": "admin@gmail.com",

View file

@ -1,4 +1,5 @@
{
"userName": "nancy",
"firstName": "Nancy",
"lastName": "Luna",
"email": "user1@gmail.com",

View file

@ -1,4 +1,5 @@
{
"userName": "elon",
"firstName": "Elon",
"lastName": "Musk",
"email": "csr1@gmail.com",