Ui自动化测试右键菜单

时间:2023-01-20 18:46:37

I am trying to automate testing for wpf application using ui automation. I have problems simulating right mouse click and selecting different option in right click menu. Any suggestions?

我正在尝试使用ui自动化自动测试wpf应用程序。我在模拟鼠标右键并在右键菜单中选择不同选项时遇到问题。有什么建议么?

I also have problems with running other test written using ui automation. Because they just don't wanna start if I don't have UISpy opened and all programs minimized.

运行使用ui自动化编写的其他测试时,我也遇到了问题。因为如果我没有打开UISpy并且所有程序都被最小化,他们就不想开始。

1 个解决方案

#1


3  

With a lot of browsing I found this solution. It might be helpful to anyone else: UI Automation in Silverlight

通过大量浏览,我找到了这个解决方案。它可能对其他任何人都有帮助:Silverlight中的UI自动化

Only added simple right click code

只添加了简单的右键单击代码

public static class Mouse
    {

        private const UInt32 MouseEventLeftDown = 0x0002;
        private const UInt32 MouseEventLeftUp = 0x0004;
        private const UInt32 MouseEventRightDown = 0x0008;
        private const UInt32 MouseEventRightUp = 0x00010;


        [DllImport("user32.dll")]

        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);



        public static void Click()
        {
            mouse_event(MouseEventLeftDown, 0, 0, 0, IntPtr.Zero);
            mouse_event(MouseEventLeftUp, 0, 0, 0, IntPtr.Zero);
            Thread.Sleep(100);
        }

        public static void RightClick()
        {
            mouse_event(MouseEventRightDown, 0, 0, 0, IntPtr.Zero);
            mouse_event(MouseEventRightUp, 0, 0, 0, IntPtr.Zero);
            Thread.Sleep(100);

        }

#1


3  

With a lot of browsing I found this solution. It might be helpful to anyone else: UI Automation in Silverlight

通过大量浏览,我找到了这个解决方案。它可能对其他任何人都有帮助:Silverlight中的UI自动化

Only added simple right click code

只添加了简单的右键单击代码

public static class Mouse
    {

        private const UInt32 MouseEventLeftDown = 0x0002;
        private const UInt32 MouseEventLeftUp = 0x0004;
        private const UInt32 MouseEventRightDown = 0x0008;
        private const UInt32 MouseEventRightUp = 0x00010;


        [DllImport("user32.dll")]

        private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);



        public static void Click()
        {
            mouse_event(MouseEventLeftDown, 0, 0, 0, IntPtr.Zero);
            mouse_event(MouseEventLeftUp, 0, 0, 0, IntPtr.Zero);
            Thread.Sleep(100);
        }

        public static void RightClick()
        {
            mouse_event(MouseEventRightDown, 0, 0, 0, IntPtr.Zero);
            mouse_event(MouseEventRightUp, 0, 0, 0, IntPtr.Zero);
            Thread.Sleep(100);

        }