2016-12-02 90 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