Skip to content

Commit a54f5b2

Browse files
committed
Adding additional .NET click tests to alignwith java test suite
1 parent 4bc1068 commit a54f5b2

File tree

2 files changed

+179
-27
lines changed

2 files changed

+179
-27
lines changed

dotnet/test/common/ClickTest.cs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,8 @@ public void ClicksASurroundingStrongTag()
246246
}
247247

248248
[Test]
249-
[IgnoreBrowser(Browser.Chrome, "Element is not clickable")]
250249
[IgnoreBrowser(Browser.IE, "Map click fails")]
251250
[IgnoreBrowser(Browser.Opera, "Map click fails")]
252-
[IgnoreBrowser(Browser.Android, "Not tested")]
253-
[IgnoreBrowser(Browser.IPhone, "Not tested")]
254251
public void CanClickAnImageMapArea()
255252
{
256253
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/google_map.html");
@@ -280,12 +277,8 @@ public void ShouldBeAbleToClickOnAnElementGreaterThanTwoViewports()
280277
}
281278

282279
[Test]
283-
[IgnoreBrowser(Browser.Firefox, "Fails on Firefox")]
284280
[IgnoreBrowser(Browser.Chrome, "Fails on Chrome")]
285281
[IgnoreBrowser(Browser.Opera, "Not Tested")]
286-
[IgnoreBrowser(Browser.Android, "Not Tested")]
287-
[IgnoreBrowser(Browser.HtmlUnit, "Not Tested")]
288-
[IgnoreBrowser(Browser.IPhone, "Not Tested")]
289282
public void ShouldBeAbleToClickOnAnElementInFrameGreaterThanTwoViewports()
290283
{
291284
string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_too_big_in_frame.html");
@@ -301,6 +294,19 @@ public void ShouldBeAbleToClickOnAnElementInFrameGreaterThanTwoViewports()
301294
WaitFor(() => { return driver.Title == "clicks"; }, "Browser title was not 'clicks'");
302295
}
303296

297+
[Test]
298+
public void ShouldBeAbleToClickOnRightToLeftLanguageLink()
299+
{
300+
String url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_rtl.html");
301+
driver.Url = url;
302+
303+
IWebElement element = driver.FindElement(By.Id("ar_link"));
304+
element.Click();
305+
306+
WaitFor(() => driver.Title == "clicks", "Expected title to be 'clicks'");
307+
Assert.AreEqual("clicks", driver.Title);
308+
}
309+
304310
[Test]
305311
public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooter()
306312
{
@@ -322,5 +328,53 @@ public void ShouldBeAbleToClickOnLinkInAbsolutelyPositionedFooterInQuirksMode()
322328
WaitFor(() => { return driver.Title == "XHTML Test Page"; }, "Browser title was not 'XHTML Test Page'");
323329
Assert.AreEqual("XHTML Test Page", driver.Title);
324330
}
331+
332+
[Test]
333+
public void ShouldBeAbleToClickOnLinksWithNoHrefAttribute()
334+
{
335+
driver.Url = javascriptPage;
336+
337+
IWebElement element = driver.FindElement(By.LinkText("No href"));
338+
element.Click();
339+
340+
WaitFor(() => driver.Title == "Changed", "Expected title to be 'Changed'");
341+
Assert.AreEqual("Changed", driver.Title);
342+
}
343+
344+
[Test]
345+
public void ShouldBeAbleToClickOnALinkThatWrapsToTheNextLine()
346+
{
347+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/link_that_wraps.html");
348+
349+
driver.FindElement(By.Id("link")).Click();
350+
351+
WaitFor(() => driver.Title == "Submitted Successfully!", "Expected title to be 'Submitted Successfully!'");
352+
Assert.AreEqual("Submitted Successfully!", driver.Title);
353+
}
354+
355+
[Test]
356+
public void ShouldBeAbleToClickOnASpanThatWrapsToTheNextLine()
357+
{
358+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/span_that_wraps.html");
359+
360+
driver.FindElement(By.Id("span")).Click();
361+
362+
WaitFor(() => driver.Title == "Submitted Successfully!", "Expected title to be 'Submitted Successfully!'");
363+
Assert.AreEqual("Submitted Successfully!", driver.Title);
364+
}
365+
366+
[Test]
367+
[IgnoreBrowser(Browser.IE)]
368+
[IgnoreBrowser(Browser.Chrome)]
369+
[IgnoreBrowser(Browser.Safari)]
370+
public void ShouldBeAbleToClickOnAPartiallyOverlappedLinkThatWrapsToTheNextLine()
371+
{
372+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/wrapped_overlapping_elements.html");
373+
374+
driver.FindElement(By.Id("link")).Click();
375+
376+
WaitFor(() => driver.Title == "Submitted Successfully!", "Expected title to be 'Submitted Successfully!'");
377+
Assert.AreEqual("Submitted Successfully!", driver.Title);
378+
}
325379
}
326380
}

dotnet/test/common/CorrectEventFiringTest.cs

Lines changed: 118 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
using System.Text;
44
using NUnit.Framework;
55
using System.Collections.ObjectModel;
6+
using OpenQA.Selenium.Environment;
67

78
namespace OpenQA.Selenium
89
{
910
[TestFixture]
1011
public class CorrectEventFiringTest : DriverTestFixture
1112
{
1213
[Test]
13-
[IgnoreBrowser(Browser.Android)]
14-
[IgnoreBrowser(Browser.Chrome, "Webkit bug 22261")]
1514
public void ShouldFireFocusEventWhenClicking()
1615
{
1716
driver.Url = javascriptPage;
@@ -23,7 +22,6 @@ public void ShouldFireFocusEventWhenClicking()
2322

2423
[Test]
2524
[Category("Javascript")]
26-
[IgnoreBrowser(Browser.Android)]
2725
public void ShouldFireClickEventWhenClicking()
2826
{
2927
driver.Url = javascriptPage;
@@ -35,7 +33,6 @@ public void ShouldFireClickEventWhenClicking()
3533

3634
[Test]
3735
[Category("Javascript")]
38-
[IgnoreBrowser(Browser.Android)]
3936
public void ShouldFireMouseDownEventWhenClicking()
4037
{
4138
driver.Url = javascriptPage;
@@ -47,7 +44,6 @@ public void ShouldFireMouseDownEventWhenClicking()
4744

4845
[Test]
4946
[Category("Javascript")]
50-
[IgnoreBrowser(Browser.Android)]
5147
public void ShouldFireMouseUpEventWhenClicking()
5248
{
5349
driver.Url = javascriptPage;
@@ -82,7 +78,6 @@ public void ShouldFireMouseMoveEventWhenClicking()
8278

8379
[Test]
8480
[Category("Javascript")]
85-
[IgnoreBrowser(Browser.HtmlUnit)]
8681
public void ShouldNotThrowIfEventHandlerThrows()
8782
{
8883
driver.Url = javascriptPage;
@@ -91,8 +86,6 @@ public void ShouldNotThrowIfEventHandlerThrows()
9186

9287
[Test]
9388
[Category("Javascript")]
94-
[IgnoreBrowser(Browser.Android)]
95-
[IgnoreBrowser(Browser.Chrome, "Webkit bug 22261")]
9689
public void ShouldFireEventsInTheRightOrder()
9790
{
9891
driver.Url = javascriptPage;
@@ -115,7 +108,6 @@ public void ShouldFireEventsInTheRightOrder()
115108

116109
[Test]
117110
[Category("Javascript")]
118-
[IgnoreBrowser(Browser.Android)]
119111
public void ShouldIssueMouseDownEvents()
120112
{
121113
driver.Url = javascriptPage;
@@ -149,7 +141,6 @@ public void ShouldIssueMouseUpEvents()
149141

150142
[Test]
151143
[Category("Javascript")]
152-
[IgnoreBrowser(Browser.IPhone)]
153144
public void MouseEventsShouldBubbleUpToContainingElements()
154145
{
155146
driver.Url = javascriptPage;
@@ -161,7 +152,6 @@ public void MouseEventsShouldBubbleUpToContainingElements()
161152

162153
[Test]
163154
[Category("Javascript")]
164-
[IgnoreBrowser(Browser.IPhone)]
165155
public void ShouldEmitOnChangeEventsWhenSelectingElements()
166156
{
167157
driver.Url = javascriptPage;
@@ -179,6 +169,23 @@ public void ShouldEmitOnChangeEventsWhenSelectingElements()
179169
Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "bar");
180170
}
181171

172+
[Test]
173+
[Category("Javascript")]
174+
public void ShouldEmitOnClickEventsWhenSelectingElements()
175+
{
176+
driver.Url = javascriptPage;
177+
// Intentionally not looking up the select tag. See selenium r7937 for details.
178+
ReadOnlyCollection<IWebElement> allOptions = driver.FindElements(By.XPath("//select[@id='selector2']//option"));
179+
180+
IWebElement foo = allOptions[0];
181+
IWebElement bar = allOptions[1];
182+
183+
foo.Click();
184+
Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "foo");
185+
bar.Click();
186+
Assert.AreEqual(driver.FindElement(By.Id("result")).Text, "bar");
187+
}
188+
182189
[Test]
183190
[Category("Javascript")]
184191
[IgnoreBrowser(Browser.IE, "IE does not fire change event when clicking on checkbox")]
@@ -205,7 +212,6 @@ public void ShouldEmitClickEventWhenClickingOnATextInputElement()
205212

206213
[Test]
207214
[Category("Javascript")]
208-
[IgnoreBrowser(Browser.Android)]
209215
public void ShouldFireTwoClickEventsWhenClickingOnALabel()
210216
{
211217
driver.Url = javascriptPage;
@@ -219,7 +225,6 @@ public void ShouldFireTwoClickEventsWhenClickingOnALabel()
219225

220226
[Test]
221227
[Category("Javascript")]
222-
[IgnoreBrowser(Browser.Android)]
223228
public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire()
224229
{
225230
driver.Url = javascriptPage;
@@ -233,8 +238,6 @@ public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire()
233238

234239
[Test]
235240
[Category("Javascript")]
236-
[IgnoreBrowser(Browser.IPhone, "SendKeys implementation is incorrect.")]
237-
[IgnoreBrowser(Browser.Android)]
238241
public void SendingKeysToAnotherElementShouldCauseTheBlurEventToFire()
239242
{
240243
driver.Url = javascriptPage;
@@ -247,8 +250,6 @@ public void SendingKeysToAnotherElementShouldCauseTheBlurEventToFire()
247250

248251
[Test]
249252
[Category("Javascript")]
250-
[IgnoreBrowser(Browser.IPhone, "SendKeys implementation is incorrect.")]
251-
[IgnoreBrowser(Browser.Android)]
252253
public void SendingKeysToAnElementShouldCauseTheFocusEventToFire()
253254
{
254255
driver.Url = javascriptPage;
@@ -259,7 +260,6 @@ public void SendingKeysToAnElementShouldCauseTheFocusEventToFire()
259260

260261
[Test]
261262
[Category("Javascript")]
262-
[IgnoreBrowser(Browser.IPhone, "Input elements are blurred when the keyboard is closed.")]
263263
public void SendingKeysToAFocusedElementShouldNotBlurThatElement()
264264
{
265265
driver.Url = javascriptPage;
@@ -328,8 +328,6 @@ public void SubmittingFormFromFormInputTextElementShouldFireOnSubmitForThatFormA
328328

329329
[Test]
330330
[Category("Javascript")]
331-
[IgnoreBrowser(Browser.IPhone, "Does not yet support file uploads")]
332-
[IgnoreBrowser(Browser.Android, "Does not yet support file uploads")]
333331
[IgnoreBrowser(Browser.Safari, "Does not yet support file uploads")]
334332
[IgnoreBrowser(Browser.WindowsPhone, "Does not yet support file uploads")]
335333
public void UploadingFileShouldFireOnChangeEvent()
@@ -371,6 +369,106 @@ public void ShouldReportTheXAndYCoordinatesWhenClicking()
371369
Assert.AreNotEqual("0", clientY);
372370
}
373371

372+
[Test]
373+
public void ClickEventsShouldBubble()
374+
{
375+
driver.Url = clicksPage;
376+
driver.FindElement(By.Id("bubblesFrom")).Click();
377+
bool eventBubbled = (bool)((IJavaScriptExecutor)driver).ExecuteScript("return !!window.bubbledClick;");
378+
Assert.IsTrue(eventBubbled, "Event didn't bubble up");
379+
}
380+
381+
[Test]
382+
[IgnoreBrowser(Browser.IE, "IE doesn't support detecting overlapped elements")]
383+
[IgnoreBrowser(Browser.Safari)]
384+
public void ClickOverlappingElements()
385+
{
386+
if (TestUtilities.IsOldIE(driver))
387+
{
388+
Assert.Ignore("Not supported on IE < 9");
389+
}
390+
391+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/overlapping_elements.html");
392+
var ex = Assert.Throws<WebDriverException>(() => driver.FindElement(By.Id("under")).Click());
393+
Assert.That(ex.Message.Contains("Other element would receive the click"));
394+
}
395+
396+
[Test]
397+
[IgnoreBrowser(Browser.IE, "IE doesn't support detecting overlapped elements")]
398+
[IgnoreBrowser(Browser.Chrome)]
399+
[IgnoreBrowser(Browser.Safari)]
400+
public void ClickPartiallyOverlappingElements()
401+
{
402+
if (TestUtilities.IsOldIE(driver))
403+
{
404+
Assert.Ignore("Not supported on IE < 9");
405+
}
406+
407+
StringBuilder expectedLogBuilder = new StringBuilder();
408+
expectedLogBuilder.AppendLine("Log:");
409+
expectedLogBuilder.AppendLine("mousedown in under (handled by under)");
410+
expectedLogBuilder.AppendLine("mousedown in under (handled by body)");
411+
expectedLogBuilder.AppendLine("mouseup in under (handled by under)");
412+
expectedLogBuilder.AppendLine("mouseup in under (handled by body)");
413+
expectedLogBuilder.AppendLine("click in under (handled by under)");
414+
expectedLogBuilder.Append("click in under (handled by body)");
415+
416+
for (int i = 1; i < 6; i++)
417+
{
418+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/partially_overlapping_elements.html");
419+
IWebElement over = driver.FindElement(By.Id("over" + i));
420+
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].style.display = 'none'", over);
421+
driver.FindElement(By.Id("under")).Click();
422+
Assert.AreEqual(expectedLogBuilder.ToString(), driver.FindElement(By.Id("log")).Text);
423+
}
424+
}
425+
426+
[Test]
427+
[IgnoreBrowser(Browser.Firefox)]
428+
[IgnoreBrowser(Browser.Chrome)]
429+
[IgnoreBrowser(Browser.Safari)]
430+
public void NativelyClickOverlappingElements()
431+
{
432+
if (TestUtilities.IsOldIE(driver))
433+
{
434+
Assert.Ignore("Not supported on IE < 9");
435+
}
436+
437+
StringBuilder expectedLogBuilder = new StringBuilder();
438+
expectedLogBuilder.AppendLine("Log:");
439+
expectedLogBuilder.AppendLine("mousedown in over (handled by over)");
440+
expectedLogBuilder.AppendLine("mousedown in over (handled by body)");
441+
expectedLogBuilder.AppendLine("mouseup in over (handled by over)");
442+
expectedLogBuilder.AppendLine("mouseup in over (handled by body)");
443+
expectedLogBuilder.AppendLine("click in over (handled by over)");
444+
expectedLogBuilder.Append("click in over (handled by body)");
445+
446+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/overlapping_elements.html");
447+
driver.FindElement(By.Id("under")).Click();
448+
Assert.AreEqual(expectedLogBuilder.ToString(), driver.FindElement(By.Id("log")).Text);
449+
}
450+
451+
[Test]
452+
[IgnoreBrowser(Browser.Safari)]
453+
public void ClickAnElementThatDisappear()
454+
{
455+
if (TestUtilities.IsOldIE(driver))
456+
{
457+
Assert.Ignore("Not supported on IE < 9");
458+
}
459+
460+
StringBuilder expectedLogBuilder = new StringBuilder();
461+
expectedLogBuilder.AppendLine("Log:");
462+
expectedLogBuilder.AppendLine("mousedown in over (handled by over)");
463+
expectedLogBuilder.AppendLine("mousedown in over (handled by body)");
464+
expectedLogBuilder.AppendLine("mouseup in under (handled by under)");
465+
expectedLogBuilder.Append("mouseup in under (handled by body)");
466+
467+
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("click_tests/disappearing_element.html");
468+
driver.FindElement(By.Id("over")).Click();
469+
Assert.That(driver.FindElement(By.Id("log")).Text.StartsWith(expectedLogBuilder.ToString()));
470+
}
471+
374472
private void AssertEventNotFired(string eventName)
375473
{
376474
IWebElement result = driver.FindElement(By.Id("result"));

0 commit comments

Comments
 (0)