2016-12-02 70 views
0

我有我已经转移到UIMap.cs(这样我就可以编辑代码)编码的UI测试和我的代码是...编码的UI测试Mouse.StartDragging工作一次,然后停止工作

public void Drag_Item(Point from, Point to) 
    { 
     #region Variable Declarations 
     WpfPane uIItemPane = this.UIOMyWindow.UIDesignSurfaceCustom.UIItemTabList.UIControlTabPage.UIControlText.UIItemPane; 
     #endregion 

     Mouse.StartDragging(uIItemPane, from); 
     Mouse.StopDragging(uIItemPane, to); 
    } 

我在我的测试调用此方法...

[TestMethod()] 
    public void Drag_3_Items() 
    { 
     Positions positions = new Positions(); 
     Point start = positions.adaptorsAlert; 
     this.UIMap.Drag_Item(start, positions.pos1); 
     this.UIMap.Drag_Item(start, positions.pos2); 
     this.UIMap.Drag_Item(start, positions.pos3); 
     this.UIMap.Close_AdaptorsWindowOnDesignGrid(); 
    } 

我的问题是,在第一次调用Drag_Item工作,但第二个呼叫和第三个电话没有。第一次拖动工作后,光标回到我的窗口图标,这是正确的,然后它无限期地等待。如果我摆动鼠标,它突然发挥作用。当我的测试自己运行时,我显然不会在那里晃动鼠标,所以我该如何解决这个问题?我尝试了很多东西,包括添加各种Thread.Sleep线,Mouse.Hover和Mouse.Move。除了用手移动我的鼠标外,没有任何东西可以工作。其他人在各种论坛上发布了同样的问题,没有很好的答案。

对于信息我的位置类是...

using System; 
using System.Collections.Generic; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace MyCodedUITesting 
{ 
//[Serializable] 
public class Positions 
{ 
    public Point pos1 = new Point(40, -500); 
    public Point Pos1 
    { 
     get { return pos1 ; } 
     set { this.pos1 = value; } 
    } 

    public Point pos2 = new Point(440, -500); 
    public Point Pos2 
    { 
     get { return pos2 ; } 
     set { this.pos2 = value; } 
    } 

    public Point pos3 = new Point(840, -500); 
    public Point Pos3 
    { 
     get { return pos3 ; } 
     set { this.pos3 = value; } 
    } 
} 
} 

回答

0

只有我能想到的事情是,你再每次调用方法时,实例化uIItemPane。你可能想在你的测试方法中实例化它,然后把它传递给Drag_Item。

+0

对不起Ryanman,那没什么区别。它在第一次尝试时仍然有效,但在随后的拖放尝试中失败。 – Ewan

+0

还有两个建议 - 尝试调用Mouse.Move(uIItemPane,from);在你开始拖动之前。 第二个建议是,您所依赖的项目窗格可能不正确。看看控制层次结构,它看起来像是在一个文本框内的窗格内查看。我当然不知道你的情况,但我的直觉说你的父母控制应该是不同的。 – Ryanman

+0

感谢Ryanman,我试过Mouse.Move,但是它恐怕不管用。我也尝试过Mouse.Hover。关于第二个建议,是的,它是一个文本框内的窗格,但这是开发团队创建的,所以我无法更改它。它确实第一次工作,所以它在某个时刻必须是正确的。有趣的是,我注意到它有时第一次停止工作,然后开始再次尝试第一次尝试。就好像鼠标的状态发生了一些可疑的事情。 – Ewan