Search code examples
c#seleniumatata

Atata Framework: DragAndDrop doesn't work


I am trying to implement simple drag an drop operation on this site with Selenium examples: https://demoqa.com/droppable. How it looks like: enter image description here

And seems, my implementation of drag and drop with Atata doesn't work. I got no error, but nothing actually happens.

My implementation:

Page Object:

{
    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:

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

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

I know about plain Selenium implementation, but would prefer Atata API for this. Could you, please, suggest something?

Update: For some reason, this approach is working:

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

I've read about this issue, maybe, it's related to chromedriver. Anyway, this could be used as a workaround, using Atata API still would be preferable. Maybe, there is some well-known bug in chromedriver related to this issue?


Solution

  • Although the test works for me, you can create your drag & drop behavior 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();
        }
    }
    

    And apply it to Draggable property:

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