5
5
using System . Drawing ;
6
6
using System . Text . RegularExpressions ;
7
7
using OpenQA . Selenium . Interactions ;
8
+ using OpenQA . Selenium . Environment ;
8
9
9
10
namespace OpenQA . Selenium . Interactions
10
11
{
@@ -17,7 +18,7 @@ public class DragAndDropTest : DriverTestFixture
17
18
[ IgnoreBrowser ( Browser . Android , "Mobile browser does not support drag-and-drop" ) ]
18
19
[ IgnoreBrowser ( Browser . IPhone , "Mobile browser does not support drag-and-drop" ) ]
19
20
[ IgnoreBrowser ( Browser . Safari , "Advanced User Interactions not implmented on Safari" ) ]
20
- public void DragAndDrop ( )
21
+ public void DragAndDropRelative ( )
21
22
{
22
23
driver . Url = dragAndDropPage ;
23
24
IWebElement img = driver . FindElement ( By . Id ( "test1" ) ) ;
@@ -47,6 +48,69 @@ public void DragAndDropToElement()
47
48
Assert . AreEqual ( img1 . Location , img2 . Location ) ;
48
49
}
49
50
51
+ [ Test ]
52
+ [ Category ( "Javascript" ) ]
53
+ public void DragAndDropToElementInIframe ( )
54
+ {
55
+ driver . Url = iframePage ;
56
+ IWebElement iframe = driver . FindElement ( By . TagName ( "iframe" ) ) ;
57
+ ( ( IJavaScriptExecutor ) driver ) . ExecuteScript ( "arguments[0].src = arguments[1]" , iframe ,
58
+ dragAndDropPage ) ;
59
+ driver . SwitchTo ( ) . Frame ( 0 ) ;
60
+ IWebElement img1 = WaitFor < IWebElement > ( ( ) =>
61
+ {
62
+ try
63
+ {
64
+ IWebElement element1 = driver . FindElement ( By . Id ( "test1" ) ) ;
65
+ return element1 ;
66
+ }
67
+ catch ( NoSuchElementException )
68
+ {
69
+ return null ;
70
+ }
71
+ } ) ;
72
+
73
+ IWebElement img2 = driver . FindElement ( By . Id ( "test2" ) ) ;
74
+ new Actions ( driver ) . DragAndDrop ( img2 , img1 ) . Perform ( ) ;
75
+ Assert . AreEqual ( img1 . Location , img2 . Location ) ;
76
+ }
77
+
78
+ [ Test ]
79
+ [ Category ( "Javascript" ) ]
80
+ public void DragAndDropElementWithOffsetInIframeAtBottom ( )
81
+ {
82
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "iframeAtBottom.html" ) ;
83
+
84
+ IWebElement iframe = driver . FindElement ( By . TagName ( "iframe" ) ) ;
85
+ driver . SwitchTo ( ) . Frame ( iframe ) ;
86
+
87
+ IWebElement img1 = driver . FindElement ( By . Id ( "test1" ) ) ;
88
+ Point initial = img1 . Location ;
89
+
90
+ new Actions ( driver ) . DragAndDropToOffset ( img1 , 20 , 20 ) . Perform ( ) ;
91
+ initial . Offset ( 20 , 20 ) ;
92
+ Assert . AreEqual ( initial , img1 . Location ) ;
93
+ }
94
+
95
+ [ Test ]
96
+ [ Category ( "Javascript" ) ]
97
+ public void DragAndDropElementWithOffsetInScrolledDiv ( )
98
+ {
99
+ if ( TestUtilities . IsFirefox ( driver ) && TestUtilities . IsNativeEventsEnabled ( driver ) )
100
+ {
101
+ return ;
102
+ }
103
+
104
+ driver . Url = EnvironmentManager . Instance . UrlBuilder . WhereIs ( "dragAndDropInsideScrolledDiv.html" ) ;
105
+
106
+ IWebElement el = driver . FindElement ( By . Id ( "test1" ) ) ;
107
+ Point initial = el . Location ;
108
+
109
+ new Actions ( driver ) . DragAndDropToOffset ( el , 3700 , 3700 ) . Perform ( ) ;
110
+ initial . Offset ( 3700 , 3700 ) ;
111
+ Assert . AreEqual ( initial , el . Location ) ;
112
+ }
113
+
50
114
[ Test ]
51
115
[ Category ( "Javascript" ) ]
52
116
[ IgnoreBrowser ( Browser . HtmlUnit ) ]
@@ -63,24 +127,6 @@ public void ElementInDiv()
63
127
Assert . AreEqual ( expectedLocation , endLocation ) ;
64
128
}
65
129
66
- [ Test ]
67
- public void MemoryTest ( )
68
- {
69
- driver . Url = dragAndDropPage ;
70
- IWebElement img1 = driver . FindElement ( By . Id ( "test1" ) ) ;
71
- IWebElement img2 = driver . FindElement ( By . Id ( "test2" ) ) ;
72
- System . Threading . Thread . Sleep ( 1000 ) ;
73
- for ( int i = 0 ; i < 500 ; i ++ )
74
- {
75
- string foo = img1 . GetAttribute ( "id" ) ;
76
- //img1 = driver.FindElement(By.Id("test1"));
77
- //Actions a = new Actions(driver);
78
- //a.MoveToElement(img1).Perform();
79
- }
80
-
81
- driver . Url = simpleTestPage ;
82
- }
83
-
84
130
[ Test ]
85
131
[ Category ( "Javascript" ) ]
86
132
[ IgnoreBrowser ( Browser . IE , "Dragging too far in IE causes the element not to move, instead of moving to 0,0." ) ]
@@ -219,6 +265,24 @@ public void CanDragAnElementNotVisibleInTheCurrentViewportDueToAParentOverflow()
219
265
Assert . AreEqual ( dragTo . Location , toDrag . Location ) ;
220
266
}
221
267
268
+ //[Test]
269
+ public void MemoryTest ( )
270
+ {
271
+ driver . Url = dragAndDropPage ;
272
+ IWebElement img1 = driver . FindElement ( By . Id ( "test1" ) ) ;
273
+ IWebElement img2 = driver . FindElement ( By . Id ( "test2" ) ) ;
274
+ System . Threading . Thread . Sleep ( 1000 ) ;
275
+ for ( int i = 0 ; i < 500 ; i ++ )
276
+ {
277
+ string foo = img1 . GetAttribute ( "id" ) ;
278
+ //img1 = driver.FindElement(By.Id("test1"));
279
+ //Actions a = new Actions(driver);
280
+ //a.MoveToElement(img1).Perform();
281
+ }
282
+
283
+ driver . Url = simpleTestPage ;
284
+ }
285
+
222
286
private Point drag ( IWebElement elem , Point initialLocation , int moveRightBy , int moveDownBy )
223
287
{
224
288
Point expectedLocation = new Point ( initialLocation . X , initialLocation . Y ) ;
0 commit comments