Skip to content

Commit

Permalink
Drag and drop to specific target point
Browse files Browse the repository at this point in the history
  • Loading branch information
nvborisenko committed Aug 30, 2024
1 parent 75917f6 commit 488277c
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Yapoml.Playwright/Components/BaseComponent.Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public virtual TComponent DragAndDrop<TToComponent, TToConditions, TToCondition>
{
using (var scope = _logger.BeginLogScope($"Dragging {Metadata.Name} to {toComponent.Metadata.Name}"))
{
scope.Execute(async () =>
scope.Execute(() =>
{
RelocateOnStaleReference(async () => await WrappedElement.DragToAsync(toComponent.WrappedElement));
});
Expand All @@ -521,6 +521,38 @@ public virtual TComponent DragAndDrop<TToComponent, TToConditions, TToCondition>
return DragAndDrop(toComponent);
}

/// <summary>
/// Performs a drag and drop operation to another component.
/// </summary>
public virtual TComponent DragAndDrop<TToComponent, TToConditions, TToCondition>(BaseComponent<TToComponent, TToConditions, TToCondition> toComponent, int x, int y)
where TToComponent : BaseComponent<TToComponent, TToConditions, TToCondition>
where TToConditions : BaseComponentConditions<TToConditions>
where TToCondition : BaseComponentConditions<TToComponent>
{
using (var scope = _logger.BeginLogScope($"Dragging {Metadata.Name} to {toComponent.Metadata.Name}"))
{
scope.Execute(() =>
{
RelocateOnStaleReference(async () => await WrappedElement.DragToAsync(toComponent.WrappedElement, new() { TargetPosition = new() { X = x, Y = y } }));
});
}

return component;
}

/// <summary>
/// Performs a drag and drop operation to another component.
/// </summary>
public virtual TComponent DragAndDrop<TToComponent, TToConditions, TToCondition>(BaseComponent<TToComponent, TToConditions, TToCondition> toComponent, int x, int y, Action<TConditions> when)
where TToComponent : BaseComponent<TToComponent, TToConditions, TToCondition>
where TToConditions : BaseComponentConditions<TToConditions>
where TToCondition : BaseComponentConditions<TToComponent>
{
when(conditions);

return DragAndDrop(toComponent, x, y);
}

/// <summary>
/// Gets a screenshot of the current state of the component in PNG format.
/// </summary>
Expand Down

0 comments on commit 488277c

Please sign in to comment.