WinAppDriver: Drag’n’Drop Beispiel

Vorher natürlich WinAppDriver installieren und starten.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Remote;
using OpenQA.Selenium.Appium.Windows;
using System.Threading;

namespace UnitTestProject2
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void NotepadTest()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe");
            WindowsDriver<WindowsElement> session = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), desiredCapabilities);
            
            Thread.Sleep(2000); // damit man die Drag'n'Drop Action besser sieht
            WindowsElement eckeInNotepad = session.FindElementByName("Ziehpunkt");
            session.Mouse.MouseMove(eckeInNotepad.Coordinates, 15, 15);
            Thread.Sleep(2000); // damit man die Drag'n'Drop Action besser sieht
            session.Mouse.MouseDown(eckeInNotepad.Coordinates);
            session.Mouse.MouseMove(eckeInNotepad.Coordinates, -200, 200);
            session.Mouse.MouseUp(null);
        }
    }
}