【问题标题】:Block cursor movement during automation run在自动化运行期间阻止光标移动
【发布时间】:2019-09-05 03:07:54
【问题描述】:

我正在为我的 WPF 应用程序使用 Teststack 白色框架(C#、.net)编写一些自动化测试。我希望在测试运行时冻结任何光标移动。有什么办法吗?

我已经试过了

public partial class NativeMethods
{
    [DllImport("user32.dll", SetLastError = true)]
    public static extern bool BlockInput(bool fBlockIt);
}

但它无法正常工作,因为我的应用程序没有以管理员权限运行

我试过了 NativeMethods.BlockInput(true);

我收到拒绝访问异常

【问题讨论】:

  • 只需断开鼠标。
  • 因为代码将进入生产环境......它将如何在那里工作?
  • 您是在问客户如何进行自动化测试?肯定的:他们会报告问题,您会要求他们断开鼠标的连接。认真地说:我们的 UI 测试在完全没有键盘/鼠标的专用 PC 上运行,我们远程连接到它(很少)。不确定您要解决什么问题。使用PC进行自动化测试并同时在那里上网?宁可不要。

标签: c# wpf automation white-framework teststack


【解决方案1】:

我认为你可以使用 ClipCursor

[DllImport("user32.dll")]
    static extern void ClipCursor(ref System.Drawing.Rectangle rect);

    [DllImport("user32.dll")]
    static extern void ClipCursor(IntPtr rect);

    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = this;
        this.Loaded += MainWindow_Loaded;
        this.MouseMove += Window_MouseMove;
    }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        this.WindowState = WindowState.Maximized;
        HideMouse();
    }
    private void Window_MouseMove(object sender, MouseEventArgs e)
    {
        HideMouse();
    }

    private void HideMouse()
    {
        System.Drawing.Rectangle r = new System.Drawing.Rectangle(0, 0, 0, 0);
        ClipCursor(ref r);
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-31
    • 2023-03-05
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多