Skip to content

Commit e48851a

Browse files
committed
Adding tests to .NET test suite for parity with Java tests
1 parent dcadbf6 commit e48851a

File tree

2 files changed

+98
-19
lines changed

2 files changed

+98
-19
lines changed

Diff for: dotnet/test/common/Interactions/DragAndDropTest.cs

+83-19
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Drawing;
66
using System.Text.RegularExpressions;
77
using OpenQA.Selenium.Interactions;
8+
using OpenQA.Selenium.Environment;
89

910
namespace OpenQA.Selenium.Interactions
1011
{
@@ -17,7 +18,7 @@ public class DragAndDropTest : DriverTestFixture
1718
[IgnoreBrowser(Browser.Android, "Mobile browser does not support drag-and-drop")]
1819
[IgnoreBrowser(Browser.IPhone, "Mobile browser does not support drag-and-drop")]
1920
[IgnoreBrowser(Browser.Safari, "Advanced User Interactions not implmented on Safari")]
20-
public void DragAndDrop()
21+
public void DragAndDropRelative()
2122
{
2223
driver.Url = dragAndDropPage;
2324
IWebElement img = driver.FindElement(By.Id("test1"));
@@ -47,6 +48,69 @@ public void DragAndDropToElement()
4748
Assert.AreEqual(img1.Location, img2.Location);
4849
}
4950

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+
50114
[Test]
51115
[Category("Javascript")]
52116
[IgnoreBrowser(Browser.HtmlUnit)]
@@ -63,24 +127,6 @@ public void ElementInDiv()
63127
Assert.AreEqual(expectedLocation, endLocation);
64128
}
65129

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-
84130
[Test]
85131
[Category("Javascript")]
86132
[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()
219265
Assert.AreEqual(dragTo.Location, toDrag.Location);
220266
}
221267

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+
222286
private Point drag(IWebElement elem, Point initialLocation, int moveRightBy, int moveDownBy)
223287
{
224288
Point expectedLocation = new Point(initialLocation.X, initialLocation.Y);

Diff for: dotnet/test/common/TestUtilities.cs

+15
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,20 @@ public static bool IsOldIE(IWebDriver driver)
8787
return false;
8888
}
8989
}
90+
91+
public static bool IsNativeEventsEnabled(IWebDriver driver)
92+
{
93+
IHasCapabilities hasCaps = driver as IHasCapabilities;
94+
if (hasCaps != null)
95+
{
96+
object cap = hasCaps.Capabilities.GetCapability(OpenQA.Selenium.Remote.CapabilityType.HasNativeEvents);
97+
if (cap != null && cap is bool)
98+
{
99+
return (bool)cap;
100+
}
101+
}
102+
103+
return false;
104+
}
90105
}
91106
}

0 commit comments

Comments
 (0)