Atata 框架:DragAndDrop 不起作用

Atata Framework: DragAndDrop doesn't work

我正在尝试使用 Selenium 示例在此站点上实现简单的拖放操作:https://demoqa.com/droppable。 它看起来如何:

看来,我使用 Atata 实现的拖放功能不起作用。我没有收到任何错误,但实际上什么也没发生。

我的实现:

页面对象:

{
    using _ = DemoQAInteractionsPage;

    [Url("interaction")]
    [WaitForDocumentReadyState]
    public class DemoQAInteractionsPage : Page<_>
    {
        [FindById("item-3")]
        [ScrollsUsingScript]
        public Control<_> DroppableMenu { get; private set; }

        [FindById]
        [DragsAndDropsUsingActions]
        [WaitUntilEnabled]
        public Control<_> Draggable { get; private set; }

        [FindById]
        [DragsAndDropsUsingActions]
        [WaitUntilEnabled]
        public Control<_> Droppable { get; private set; }

        [FindByContent("Dropped!")]
        [WaitUntilEnabled]
        public Control<_> DroppedMessage { get; private set; }
    }
}

测试:

        [Test]
        public void DemoQADragAndDropTest()
        {
            Go.To<DemoQAMainPage>()
                .GoToInteractions();

            Go.To<DemoQAInteractionsPage>(navigate: false)
                .DroppableMenu.ScrollTo()
                .DroppableMenu.Click()
                .Draggable.DragAndDropTo(x => x.Droppable);
        }

我知道普通的 Selenium 实现,但更喜欢 Atata API。你能不能给些建议?

更新: 出于某种原因,这种方法有效:

        public _ PerformDragAndDrop()
        {
            IWebElement target = Droppable.GetScope();
            IWebElement source = Draggable.GetScope();
            Actions actions = new Actions(Driver);
            actions.ClickAndHold(source);
            actions.MoveToElement(target);
            actions.Perform();
            actions.Release(target);
            actions.Perform();
            return this;
        }

我看过这个问题,可能与 chromedriver 有关。无论如何,这可以作为一种解决方法,使用 Atata API 仍然是更可取的。也许,chromedriver 中有一些与此问题相关的众所周知的错误?

尽管测试对我有效,但您可以创建自己的拖放行为 class:

public class DragsAndDropsUsingActionsStepByStepAttribute : DragAndDropBehaviorAttribute
{
    public override void Execute<TOwner>(IControl<TOwner> component, IControl<TOwner> target)
    {
        IWebElement sourceElement = component.Scope;
        IWebElement targetElement = component.Scope;

        Actions actions = new Actions(component.Context.Driver);
        actions.ClickAndHold(sourceElement);
        actions.MoveToElement(targetElement);
        actions.Perform();
        actions.Release(targetElement);
        actions.Perform();
    }
}

并将其应用到 Draggable 属性:

[FindById]
[DragsAndDropsUsingActionsStepByStep]
public Control<_> Draggable { get; private set; }