diff --git a/dotnet/src/webdriver/Interactions/ActionBuilder.cs b/dotnet/src/webdriver/Interactions/ActionBuilder.cs
index 077678605d346..cf7383fad9f3e 100644
--- a/dotnet/src/webdriver/Interactions/ActionBuilder.cs
+++ b/dotnet/src/webdriver/Interactions/ActionBuilder.cs
@@ -21,6 +21,8 @@
using System.Collections.Generic;
using System.Text;
+#nullable enable
+
namespace OpenQA.Selenium.Interactions
{
///
@@ -29,7 +31,7 @@ namespace OpenQA.Selenium.Interactions
///
public class ActionBuilder
{
- private Dictionary sequences = new Dictionary();
+ private readonly Dictionary sequences = new Dictionary();
///
/// Adds an action to the built set of actions. Adding an action will
@@ -39,7 +41,7 @@ public class ActionBuilder
/// A self reference.
public ActionBuilder AddAction(Interaction actionToAdd)
{
- this.AddActions(actionToAdd);
+ this.ProcessTick(actionToAdd);
return this;
}
@@ -71,7 +73,7 @@ public IList ToActionSequenceList()
///
public void ClearSequences()
{
- this.sequences = new Dictionary();
+ this.sequences.Clear();
}
///
@@ -89,13 +91,26 @@ public override string ToString()
return builder.ToString();
}
+ private void ProcessTick(Interaction interaction)
+ {
+ ActionSequence sequence = this.GetOrAddSequence(interaction.SourceDevice);
+ sequence.AddAction(interaction);
+
+ foreach (KeyValuePair pair in this.sequences)
+ {
+ if (pair.Key != interaction.SourceDevice)
+ {
+ pair.Value.AddAction(new PauseInteraction(pair.Key, TimeSpan.Zero));
+ }
+ }
+ }
+
private void ProcessTick(params Interaction[] interactionsToAdd)
{
List usedDevices = new List();
foreach (Interaction interaction in interactionsToAdd)
{
- InputDevice actionDevice = interaction.SourceDevice;
- if (usedDevices.Contains(actionDevice))
+ if (usedDevices.Contains(interaction.SourceDevice))
{
throw new ArgumentException("You can only add one action per device for a single tick.");
}
@@ -104,8 +119,9 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
List unusedDevices = new List(this.sequences.Keys);
foreach (Interaction interaction in interactionsToAdd)
{
- ActionSequence sequence = this.FindSequence(interaction.SourceDevice);
+ ActionSequence sequence = this.GetOrAddSequence(interaction.SourceDevice);
sequence.AddAction(interaction);
+
unusedDevices.Remove(interaction.SourceDevice);
}
@@ -116,11 +132,11 @@ private void ProcessTick(params Interaction[] interactionsToAdd)
}
}
- private ActionSequence FindSequence(InputDevice device)
+ private ActionSequence GetOrAddSequence(InputDevice device)
{
- if (this.sequences.ContainsKey(device))
+ if (this.sequences.TryGetValue(device, out ActionSequence? existingSequence))
{
- return this.sequences[device];
+ return existingSequence;
}
int longestSequenceLength = 0;