在Atata框架中执行Drag-and-Drop操作的最佳方法是使用Atata提供的DragAndDrop
using Atata;
using NUnit.Framework;
namespace SampleApp.UITests
{
public class DragAndDropTests : UITestFixture
{
[Test]
public void DragAndDrop()
{
Go.To<DragAndDropPage>();
var sourceElement = Go.To<DraggableElementPage>().DraggableElement;
var targetElement = Go.To<DroppableElementPage>().DroppableElement;
// Perform the Drag-and-Drop operation
sourceElement.DragAndDrop(targetElement);
// Verify that the operation was successful
sourceElement.Should.Not.Exist();
targetElement.Should.Equal("Dropped!");
}
}
[Url("https://jqueryui.com/droppable/")]
[VerifyTitle]
public class DragAndDropPage : Page
{
}
public class DraggableElementPage : Page
{
[FindById("draggable")]
public DraggableObject<DroppableElementPage> DraggableElement { get; private set; }
}
public class DroppableElementPage : Page
{
[FindById("droppable", OuterXPath = "")]
public Content<DroppableElementPage> DroppableElement { get; private set; }
public UIComponent<DroppableElementPage> DroppedObject =>
Find<UIComponent<DroppableElementPage>>(By.XPath(".//p[text()='Dropped!']"));
}
public class DraggableObject<TDroppable> : Content<TDroppable>, IDraggable<TDroppable>
where TDroppable : PageObject<TDroppable>
{
private Config<IDraggable<TDroppable>> drag;
public DraggableObject(PageObject<TDroppable> owner)
: base(owner)
{
drag = new Config<IDraggable<TDroppable>>(this);
}
public TDroppable DragAndDrop(TDroppable droppable)
{
ExecuteActions(actions => actions.DragAndDropToElement(droppable.Scope));
return droppable;
}
public Config<IDraggable<TDroppable>> Drag => drag;
}
}