Skip to content

Fix click element in WebDriver. #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public interface IUserIdentity
{
string Id { get; }
string Email { get; }
string UserName { get; }
string FirstName { get; }
string LastName { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Infrastructure/BotSharp.Core/Infrastructures/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static (string, string) SplitAsTuple(this string str, string sep)
return (splits[0], splits[1]);
}

/// <summary>
/// Flush cache
/// </summary>
public static void ClearCache()
{
// Clear whole cache.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public UserIdentity(IHttpContextAccessor contextAccessor)
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!;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,12 +28,15 @@ public async Task<User> CreateUser(User user)
}

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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +15,7 @@ public User ToUser()
{
return new User
{
UserName = UserName,
FirstName = FirstName,
LastName = LastName,
Email = Email,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;

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")]
Expand All @@ -32,6 +32,7 @@ public static UserViewModel FromUser(User user)
return new UserViewModel
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Expand Down
3 changes: 2 additions & 1 deletion src/Plugins/BotSharp.Plugin.ChatHub/SignalRHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ public SignalRHub(IServiceProvider services,

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>();
_context.HttpContext.Request.Query.TryGetValue("conversationId", out var conversationId);

if (!string.IsNullOrEmpty(conversationId))
{
_logger.LogInformation($"Connection {Context.ConnectionId} is with conversation {conversationId}");
var conv = await convService.GetConversation(conversationId);
if (conv != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public int Transaction<TTableInterface>(Action action)
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,
Expand All @@ -132,6 +133,7 @@ public int Transaction<TTableInterface>(Action action)
{
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)
Expand Down Expand Up @@ -868,6 +870,7 @@ public List<Conversation> GetLastConversations()
return user != null ? new User
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Expand All @@ -884,6 +887,7 @@ public List<Conversation> GetLastConversations()
return user != null ? new User
{
Id = user.Id,
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Expand All @@ -901,6 +905,7 @@ public void CreateUser(User user)
var userCollection = new UserDocument
{
Id = Guid.NewGuid().ToString(),
UserName = user.UserName,
FirstName = user.FirstName,
LastName = user.LastName,
Salt = user.Salt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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;
Expand All @@ -21,6 +22,7 @@ public async Task<User> GetOrCreateWeChatAccountUserAsync(string appId, string o
{
var user = await userService.CreateUser(new User()
{
UserName = openId + "@" + appId + ".wechat",
Email = openId + "@" + appId + ".wechat",
Password = openId
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public async Task ClickElement(Agent agent, BrowsingContextIn context, string me
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"description": "website url."
}
},
"required": []
"required": ["url"]
}
},
{
Expand Down Expand Up @@ -42,7 +42,7 @@
"description": "user input."
}
},
"required": ["element_name"]
"required": ["element_name", "input_text"]
}
}
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"userName": "guest",
"firstName": "Guest",
"lastName": "Anonymous",
"email": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
{
"userName": "haiping",
"firstName": "Haiping",
"lastName": "Chen",
"email": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"userName": "nancy",
"firstName": "Nancy",
"lastName": "Luna",
"email": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"userName": "elon",
"firstName": "Elon",
"lastName": "Musk",
"email": "[email protected]",
Expand Down