Skip to content

Commit f62aefb

Browse files
committed
Updating .NET tests to correctly test Safari
1 parent 438d1d8 commit f62aefb

13 files changed

+58
-42
lines changed

dotnet/test/common/AlertsTest.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ public void ShouldNotHandleAlertInAnotherWindow()
451451
[IgnoreBrowser(Browser.Chrome, "Chrome does not trigger alerts on unload.")]
452452
[IgnoreBrowser(Browser.Edge, "Edge does not trigger alerts on unload.")]
453453
[IgnoreBrowser(Browser.EdgeLegacy, "Edge does not trigger alerts on unload.")]
454+
[IgnoreBrowser(Browser.Safari, "Safari does not trigger alerts on unload.")]
454455
public void ShouldHandleAlertOnPageUnload()
455456
{
456457
string pageWithOnBeforeUnload = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
@@ -475,7 +476,6 @@ public void ShouldHandleAlertOnPageUnload()
475476
[Test]
476477
[IgnoreBrowser(Browser.Chrome, "Chrome does not implicitly handle onBeforeUnload alert")]
477478
[IgnoreBrowser(Browser.Edge, "Edge does not implicitly handle onBeforeUnload alert")]
478-
[IgnoreBrowser(Browser.Safari, "Safari driver does not implicitly (or otherwise) handle onBeforeUnload alerts")]
479479
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver does not implicitly (or otherwise) handle onBeforeUnload alerts")]
480480
public void ShouldImplicitlyHandleAlertOnPageBeforeUnload()
481481
{
@@ -497,6 +497,7 @@ public void ShouldImplicitlyHandleAlertOnPageBeforeUnload()
497497
[IgnoreBrowser(Browser.Edge, "Test as written does not trigger alert")]
498498
[IgnoreBrowser(Browser.Firefox, "After version 27, Firefox does not trigger alerts on unload.")]
499499
[IgnoreBrowser(Browser.EdgeLegacy, "Edge does not trigger alerts on unload.")]
500+
[IgnoreBrowser(Browser.Safari, "Safari does not trigger alerts on unload.")]
500501
public void ShouldHandleAlertOnWindowClose()
501502
{
502503
string pageWithOnBeforeUnload = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
@@ -532,7 +533,6 @@ public void ShouldHandleAlertOnWindowClose()
532533
[IgnoreBrowser(Browser.EdgeLegacy, "Driver chooses not to return text from unhandled alert")]
533534
[IgnoreBrowser(Browser.Firefox, "Driver chooses not to return text from unhandled alert")]
534535
[IgnoreBrowser(Browser.Opera)]
535-
[IgnoreBrowser(Browser.Safari, "Safari driver does not do unhandled alerts")]
536536
public void IncludesAlertTextInUnhandledAlertException()
537537
{
538538
driver.Url = CreateAlertPage("cheese");
@@ -562,7 +562,6 @@ public void CanQuitWhenAnAlertIsPresent()
562562
}
563563

564564
[Test]
565-
[IgnoreBrowser(Browser.Safari, "Safari driver cannot handle alert thrown via JavaScript")]
566565
public void ShouldHandleAlertOnFormSubmit()
567566
{
568567
driver.Url = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
@@ -585,7 +584,7 @@ public void ShouldHandleAlertOnFormSubmit()
585584
// Tests below here are not included in the Java test suite
586585
//------------------------------------------------------------------
587586
[Test]
588-
[IgnoreBrowser(Browser.Safari, "onBeforeUnload dialogs hang Safari")]
587+
[IgnoreBrowser(Browser.Safari, "Safari does not display onBeforeUnload dialogs")]
589588
public void ShouldHandleAlertOnPageBeforeUnload()
590589
{
591590
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("pageWithOnBeforeUnloadMessage.html");
@@ -606,7 +605,7 @@ public void ShouldHandleAlertOnPageBeforeUnload()
606605

607606
[Test]
608607
[NeedsFreshDriver(IsCreatedAfterTest = true)]
609-
[IgnoreBrowser(Browser.Safari, "onBeforeUnload dialogs hang Safari")]
608+
[IgnoreBrowser(Browser.Safari, "Safari does not display onBeforeUnload dialogs")]
610609
public void ShouldHandleAlertOnPageBeforeUnloadAlertAtQuit()
611610
{
612611
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("pageWithOnBeforeUnloadMessage.html");

dotnet/test/common/CookieImplementationTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,14 @@ private void GotoValidDomainAndClearCookies(string page)
852852
GoToPage(page);
853853

854854
driver.Manage().Cookies.DeleteAllCookies();
855+
if (driver.Manage().Cookies.AllCookies.Count != 0)
856+
{
857+
// If cookies are still present, restart the driver and try again.
858+
// This may mask some errors, where DeleteAllCookies doesn't fully
859+
// delete all it should, but that's a tradeoff we need to be willing
860+
// to make.
861+
driver = EnvironmentManager.Instance.CreateFreshDriver();
862+
}
855863
}
856864

857865
private bool CheckIsOnValidHostNameForCookieTests()

dotnet/test/common/CorrectEventFiringTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,6 @@ public void NativelyClickOverlappingElements()
522522
}
523523

524524
[Test]
525-
[IgnoreBrowser(Browser.Safari, "Test hangs Safari Tech Preview")]
526525
public void ClickAnElementThatDisappear()
527526
{
528527
if (TestUtilities.IsOldIE(driver))

dotnet/test/common/ExecutingAsyncJavascriptTest.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ public void ShouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse()
275275
}
276276

277277
[Test]
278-
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
279278
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
280279
public void ThrowsIfScriptTriggersAlert()
281280
{
@@ -289,7 +288,6 @@ public void ThrowsIfScriptTriggersAlert()
289288
}
290289

291290
[Test]
292-
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
293291
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
294292
public void ThrowsIfAlertHappensDuringScript()
295293
{
@@ -303,7 +301,6 @@ public void ThrowsIfAlertHappensDuringScript()
303301
}
304302

305303
[Test]
306-
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
307304
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
308305
public void ThrowsIfScriptTriggersAlertWhichTimesOut()
309306
{
@@ -318,7 +315,6 @@ public void ThrowsIfScriptTriggersAlertWhichTimesOut()
318315
}
319316

320317
[Test]
321-
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
322318
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
323319
public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
324320
{
@@ -334,7 +330,6 @@ public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
334330
[Test]
335331
[IgnoreBrowser(Browser.EdgeLegacy, "Driver chooses not to return text from unhandled alert")]
336332
[IgnoreBrowser(Browser.Firefox, "Driver chooses not to return text from unhandled alert")]
337-
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
338333
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
339334
public void IncludesAlertTextInUnhandledAlertException()
340335
{

dotnet/test/common/FormHandlingTests.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ public void ShouldBeAbleToAlterTheContentsOfAFileUploadInputElement()
145145

146146
uploadElement.SendKeys(inputFile.FullName);
147147

148-
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElement.GetAttribute("value"));
149-
Assert.AreEqual(inputFile.Name, outputFile.Name);
148+
string uploadElementValue = uploadElement.GetAttribute("value");
149+
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElementValue.Replace('\\', System.IO.Path.DirectorySeparatorChar));
150+
Assert.That(inputFile.Name, Is.EqualTo(outputFile.Name));
150151
inputFile.Delete();
151152
}
152153

@@ -173,7 +174,8 @@ public void ShouldBeAbleToSendKeysToAFileUploadInputElementInAnXhtmlDocument()
173174

174175
uploadElement.SendKeys(inputFile.FullName);
175176

176-
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElement.GetAttribute("value"));
177+
string uploadElementValue = uploadElement.GetAttribute("value");
178+
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElementValue.Replace('\\', System.IO.Path.DirectorySeparatorChar));
177179
Assert.AreEqual(inputFile.Name, outputFile.Name);
178180
inputFile.Delete();
179181
}
@@ -253,7 +255,6 @@ public void EmptyTextBoxesShouldReturnAnEmptyStringNotNull()
253255

254256
[Test]
255257
[IgnoreBrowser(Browser.Opera, "Untested")]
256-
[IgnoreBrowser(Browser.Safari, "Driver does not handle alerts triggered by user JavaScript code; hangs browser.")]
257258
public void HandleFormWithJavascriptAction()
258259
{
259260
string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("form_handling_js_submit.html");
@@ -311,7 +312,6 @@ public void CanClickOnAnExternalImplicitSubmitButton()
311312
}
312313

313314
[Test]
314-
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
315315
public void CanSubmitFormWithSubmitButtonIdEqualToSubmit()
316316
{
317317
string blank = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
@@ -326,7 +326,6 @@ public void CanSubmitFormWithSubmitButtonIdEqualToSubmit()
326326
}
327327

328328
[Test]
329-
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
330329
public void CanSubmitFormWithSubmitButtonNameEqualToSubmit()
331330
{
332331
string blank = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()

dotnet/test/common/FrameSwitchingTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ public void JavaScriptShouldExecuteInTheContextOfTheCurrentFrame()
483483
}
484484

485485
[Test]
486-
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
487486
public void ShouldNotSwitchMagicallyToTheTopWindow()
488487
{
489488
string baseUrl = EnvironmentManager.Instance.UrlBuilder.WhereIs("frame_switching_tests/");
@@ -503,6 +502,7 @@ public void ShouldNotSwitchMagicallyToTheTopWindow()
503502
}
504503
finally
505504
{
505+
System.Threading.Thread.Sleep(100);
506506
string url = (string)((IJavaScriptExecutor)driver).ExecuteScript("return window.location.href");
507507
// IE6 and Chrome add "?"-symbol to the end of the URL
508508
if (url.EndsWith("?"))

dotnet/test/common/ImplicitWaitTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void ShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits()
8585

8686
[Test]
8787
[IgnoreBrowser(Browser.IE, "Driver does not implement waiting for element visible for interaction")]
88-
[IgnoreBrowser(Browser.Safari)]
88+
[IgnoreBrowser(Browser.Safari, "Driver does not implement waiting for element visible for interaction")]
8989
public void ShouldImplicitlyWaitForAnElementToBeVisibleBeforeInteracting()
9090
{
9191
driver.Url = dynamicPage;

dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using OpenQA.Selenium.Internal;
44
using System;
55
using System.Drawing;
6+
using System.Runtime.InteropServices;
67

78
namespace OpenQA.Selenium.Interactions
89
{
@@ -12,13 +13,23 @@ public class BasicKeyboardInterfaceTest : DriverTestFixture
1213
[SetUp]
1314
public void Setup()
1415
{
15-
new Actions(driver).SendKeys(Keys.Null).Perform();
16+
//new Actions(driver).SendKeys(Keys.Null).Perform();
17+
IActionExecutor actionExecutor = driver as IActionExecutor;
18+
if (actionExecutor != null)
19+
{
20+
actionExecutor.ResetInputState();
21+
}
1622
}
1723

1824
[TearDown]
1925
public void ReleaseModifierKeys()
2026
{
21-
new Actions(driver).SendKeys(Keys.Null).Perform();
27+
//new Actions(driver).SendKeys(Keys.Null).Perform();
28+
IActionExecutor actionExecutor = driver as IActionExecutor;
29+
if (actionExecutor != null)
30+
{
31+
actionExecutor.ResetInputState();
32+
}
2233
}
2334

2435
[Test]
@@ -218,6 +229,12 @@ public void SelectionSelectBySymbol()
218229
[Test]
219230
public void SelectionSelectByWord()
220231
{
232+
string controlModifier = Keys.Control;
233+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
234+
{
235+
controlModifier = Keys.Alt;
236+
}
237+
221238
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("single_text_input.html");
222239

223240
IWebElement input = driver.FindElement(By.Id("textInput"));
@@ -243,9 +260,9 @@ public void SelectionSelectByWord()
243260

244261
new Actions(driver).Click(input)
245262
.KeyDown(Keys.Shift)
246-
.KeyDown(Keys.Control)
263+
.KeyDown(controlModifier)
247264
.SendKeys(Keys.Left)
248-
.KeyUp(Keys.Control)
265+
.KeyUp(controlModifier)
249266
.KeyUp(Keys.Shift)
250267
.SendKeys(Keys.Delete)
251268
.Perform();
@@ -256,6 +273,12 @@ public void SelectionSelectByWord()
256273
[Test]
257274
public void SelectionSelectAll()
258275
{
276+
string controlModifier = Keys.Control;
277+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
278+
{
279+
controlModifier = Keys.Command;
280+
}
281+
259282
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("single_text_input.html");
260283

261284
IWebElement input = driver.FindElement(By.Id("textInput"));
@@ -265,9 +288,9 @@ public void SelectionSelectAll()
265288
WaitFor(() => input.GetAttribute("value") == "abc def", "did not send initial keys");
266289

267290
new Actions(driver).Click(input)
268-
.KeyDown(Keys.Control)
291+
.KeyDown(controlModifier)
269292
.SendKeys("a")
270-
.KeyUp(Keys.Control)
293+
.KeyUp(controlModifier)
271294
.SendKeys(Keys.Delete)
272295
.Perform();
273296

dotnet/test/common/Interactions/DragAndDropTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void DragAndDropElementWithOffsetInIframeAtBottom()
9393
[IgnoreBrowser(Browser.Edge, "Moving outside of view port throws exception in spec-compliant driver")]
9494
[IgnoreBrowser(Browser.Firefox, "Moving outside of view port throws exception in spec-compliant driver")]
9595
[IgnoreBrowser(Browser.IE, "Moving outside of view port throws exception in spec-compliant driver")]
96+
[IgnoreBrowser(Browser.Safari, "Moving outside of view port throws exception in spec-compliant driver")]
9697
public void DragAndDropElementWithOffsetInScrolledDiv()
9798
{
9899
if (TestUtilities.IsFirefox(driver) && TestUtilities.IsNativeEventsEnabled(driver))
@@ -140,6 +141,7 @@ public void DragTooFar()
140141
[IgnoreBrowser(Browser.Edge, "Moving outside of view port throws exception in spec-compliant driver")]
141142
[IgnoreBrowser(Browser.Firefox, "Moving outside of view port throws exception in spec-compliant driver")]
142143
[IgnoreBrowser(Browser.IE, "Moving outside of view port throws exception in spec-compliant driver")]
144+
[IgnoreBrowser(Browser.Safari, "Moving outside of view port throws exception in spec-compliant driver")]
143145
public void ShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort()
144146
{
145147
Size originalSize = driver.Manage().Window.Size;

dotnet/test/common/PageLoadingTest.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,13 @@ public void ShouldReturnWhenGettingAUrlThatDoesNotResolve()
177177
}
178178

179179
[Test]
180-
[IgnoreBrowser(Browser.Safari, "Safari driver does not throw on malformed URL, causing long delay awaiting timeout")]
181180
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
182181
public void ShouldThrowIfUrlIsMalformed()
183182
{
184183
Assert.That(() => driver.Url = "www.test.com", Throws.InstanceOf<WebDriverException>());
185184
}
186185

187186
[Test]
188-
[IgnoreBrowser(Browser.Safari, "Safari driver does not throw on malformed URL")]
189187
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
190188
public void ShouldThrowIfUrlIsMalformedInPortPart()
191189
{
@@ -323,7 +321,6 @@ public void ShouldNotHangIfDocumentOpenCallIsNeverFollowedByDocumentCloseCall()
323321
}
324322

325323
[Test]
326-
[IgnoreBrowser(Browser.Safari)]
327324
[NeedsFreshDriver(IsCreatedAfterTest = true)]
328325
public void PageLoadTimeoutCanBeChanged()
329326
{
@@ -332,7 +329,6 @@ public void PageLoadTimeoutCanBeChanged()
332329
}
333330

334331
[Test]
335-
[IgnoreBrowser(Browser.Safari)]
336332
[NeedsFreshDriver(IsCreatedAfterTest = true)]
337333
public void CanHandleSequentialPageLoadTimeouts()
338334
{
@@ -420,7 +416,6 @@ public void ShouldTimeoutIfAPageTakesTooLongToRefresh()
420416
[IgnoreBrowser(Browser.Chrome, "Chrome driver does, in fact, stop loading page after a timeout.")]
421417
[IgnoreBrowser(Browser.Edge, "Edge driver does, in fact, stop loading page after a timeout.")]
422418
[IgnoreBrowser(Browser.Opera, "Not implemented for browser")]
423-
[IgnoreBrowser(Browser.Safari, "Safari behaves correctly with page load timeout, but getting text does not propertly trim, leading to a test run time of over 30 seconds")]
424419
[NeedsFreshDriver(IsCreatedAfterTest = true)]
425420
public void ShouldNotStopLoadingPageAfterTimeout()
426421
{
@@ -438,7 +433,7 @@ public void ShouldNotStopLoadingPageAfterTimeout()
438433
try
439434
{
440435
string text = driver.FindElement(By.TagName("body")).Text;
441-
return text == "Slept for 11s";
436+
return text.Contains("Slept for 11s");
442437
}
443438
catch (NoSuchElementException)
444439
{

dotnet/test/common/TakesScreenshotTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public void ShouldTakeScreenshotsOfAnElement()
117117
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
118118
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
119119
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
120+
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
120121
public void ShouldCaptureScreenshotOfPageWithLongX()
121122
{
122123
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
@@ -147,6 +148,7 @@ public void ShouldCaptureScreenshotOfPageWithLongX()
147148
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
148149
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
149150
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
151+
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
150152
public void ShouldCaptureScreenshotOfPageWithLongY()
151153
{
152154
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
@@ -176,6 +178,7 @@ public void ShouldCaptureScreenshotOfPageWithLongY()
176178
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
177179
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
178180
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
181+
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
179182
public void ShouldCaptureScreenshotOfPageWithTooLongX()
180183
{
181184
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
@@ -205,6 +208,7 @@ public void ShouldCaptureScreenshotOfPageWithTooLongX()
205208
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
206209
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
207210
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
211+
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
208212
public void ShouldCaptureScreenshotOfPageWithTooLongY()
209213
{
210214
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;

0 commit comments

Comments
 (0)