Skip to content

Commit

Permalink
Updating .NET tests to correctly test Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jul 12, 2019
1 parent 438d1d8 commit f62aefb
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 42 deletions.
9 changes: 4 additions & 5 deletions dotnet/test/common/AlertsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ public void ShouldNotHandleAlertInAnotherWindow()
[IgnoreBrowser(Browser.Chrome, "Chrome does not trigger alerts on unload.")]
[IgnoreBrowser(Browser.Edge, "Edge does not trigger alerts on unload.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge does not trigger alerts on unload.")]
[IgnoreBrowser(Browser.Safari, "Safari does not trigger alerts on unload.")]
public void ShouldHandleAlertOnPageUnload()
{
string pageWithOnBeforeUnload = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand All @@ -475,7 +476,6 @@ public void ShouldHandleAlertOnPageUnload()
[Test]
[IgnoreBrowser(Browser.Chrome, "Chrome does not implicitly handle onBeforeUnload alert")]
[IgnoreBrowser(Browser.Edge, "Edge does not implicitly handle onBeforeUnload alert")]
[IgnoreBrowser(Browser.Safari, "Safari driver does not implicitly (or otherwise) handle onBeforeUnload alerts")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver does not implicitly (or otherwise) handle onBeforeUnload alerts")]
public void ShouldImplicitlyHandleAlertOnPageBeforeUnload()
{
Expand All @@ -497,6 +497,7 @@ public void ShouldImplicitlyHandleAlertOnPageBeforeUnload()
[IgnoreBrowser(Browser.Edge, "Test as written does not trigger alert")]
[IgnoreBrowser(Browser.Firefox, "After version 27, Firefox does not trigger alerts on unload.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge does not trigger alerts on unload.")]
[IgnoreBrowser(Browser.Safari, "Safari does not trigger alerts on unload.")]
public void ShouldHandleAlertOnWindowClose()
{
string pageWithOnBeforeUnload = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand Down Expand Up @@ -532,7 +533,6 @@ public void ShouldHandleAlertOnWindowClose()
[IgnoreBrowser(Browser.EdgeLegacy, "Driver chooses not to return text from unhandled alert")]
[IgnoreBrowser(Browser.Firefox, "Driver chooses not to return text from unhandled alert")]
[IgnoreBrowser(Browser.Opera)]
[IgnoreBrowser(Browser.Safari, "Safari driver does not do unhandled alerts")]
public void IncludesAlertTextInUnhandledAlertException()
{
driver.Url = CreateAlertPage("cheese");
Expand Down Expand Up @@ -562,7 +562,6 @@ public void CanQuitWhenAnAlertIsPresent()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Safari driver cannot handle alert thrown via JavaScript")]
public void ShouldHandleAlertOnFormSubmit()
{
driver.Url = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand All @@ -585,7 +584,7 @@ public void ShouldHandleAlertOnFormSubmit()
// Tests below here are not included in the Java test suite
//------------------------------------------------------------------
[Test]
[IgnoreBrowser(Browser.Safari, "onBeforeUnload dialogs hang Safari")]
[IgnoreBrowser(Browser.Safari, "Safari does not display onBeforeUnload dialogs")]
public void ShouldHandleAlertOnPageBeforeUnload()
{
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("pageWithOnBeforeUnloadMessage.html");
Expand All @@ -606,7 +605,7 @@ public void ShouldHandleAlertOnPageBeforeUnload()

[Test]
[NeedsFreshDriver(IsCreatedAfterTest = true)]
[IgnoreBrowser(Browser.Safari, "onBeforeUnload dialogs hang Safari")]
[IgnoreBrowser(Browser.Safari, "Safari does not display onBeforeUnload dialogs")]
public void ShouldHandleAlertOnPageBeforeUnloadAlertAtQuit()
{
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("pageWithOnBeforeUnloadMessage.html");
Expand Down
8 changes: 8 additions & 0 deletions dotnet/test/common/CookieImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,14 @@ private void GotoValidDomainAndClearCookies(string page)
GoToPage(page);

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

private bool CheckIsOnValidHostNameForCookieTests()
Expand Down
1 change: 0 additions & 1 deletion dotnet/test/common/CorrectEventFiringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ public void NativelyClickOverlappingElements()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Test hangs Safari Tech Preview")]
public void ClickAnElementThatDisappear()
{
if (TestUtilities.IsOldIE(driver))
Expand Down
5 changes: 0 additions & 5 deletions dotnet/test/common/ExecutingAsyncJavascriptTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ public void ShouldBeAbleToMakeXMLHttpRequestsAndWaitForTheResponse()
}

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

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

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

[Test]
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
{
Expand All @@ -334,7 +330,6 @@ public void ThrowsIfAlertHappensDuringScriptWhichTimesOut()
[Test]
[IgnoreBrowser(Browser.EdgeLegacy, "Driver chooses not to return text from unhandled alert")]
[IgnoreBrowser(Browser.Firefox, "Driver chooses not to return text from unhandled alert")]
[IgnoreBrowser(Browser.Safari, "Does not alerts thrown during async JavaScript; driver hangs until alert dismissed")]
[IgnoreBrowser(Browser.Opera, "Does not handle async alerts")]
public void IncludesAlertTextInUnhandledAlertException()
{
Expand Down
11 changes: 5 additions & 6 deletions dotnet/test/common/FormHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ public void ShouldBeAbleToAlterTheContentsOfAFileUploadInputElement()

uploadElement.SendKeys(inputFile.FullName);

System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElement.GetAttribute("value"));
Assert.AreEqual(inputFile.Name, outputFile.Name);
string uploadElementValue = uploadElement.GetAttribute("value");
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElementValue.Replace('\\', System.IO.Path.DirectorySeparatorChar));
Assert.That(inputFile.Name, Is.EqualTo(outputFile.Name));
inputFile.Delete();
}

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

uploadElement.SendKeys(inputFile.FullName);

System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElement.GetAttribute("value"));
string uploadElementValue = uploadElement.GetAttribute("value");
System.IO.FileInfo outputFile = new System.IO.FileInfo(uploadElementValue.Replace('\\', System.IO.Path.DirectorySeparatorChar));
Assert.AreEqual(inputFile.Name, outputFile.Name);
inputFile.Delete();
}
Expand Down Expand Up @@ -253,7 +255,6 @@ public void EmptyTextBoxesShouldReturnAnEmptyStringNotNull()

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

[Test]
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
public void CanSubmitFormWithSubmitButtonIdEqualToSubmit()
{
string blank = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand All @@ -326,7 +326,6 @@ public void CanSubmitFormWithSubmitButtonIdEqualToSubmit()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
public void CanSubmitFormWithSubmitButtonNameEqualToSubmit()
{
string blank = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/FrameSwitchingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ public void JavaScriptShouldExecuteInTheContextOfTheCurrentFrame()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
public void ShouldNotSwitchMagicallyToTheTopWindow()
{
string baseUrl = EnvironmentManager.Instance.UrlBuilder.WhereIs("frame_switching_tests/");
Expand All @@ -503,6 +502,7 @@ public void ShouldNotSwitchMagicallyToTheTopWindow()
}
finally
{
System.Threading.Thread.Sleep(100);
string url = (string)((IJavaScriptExecutor)driver).ExecuteScript("return window.location.href");
// IE6 and Chrome add "?"-symbol to the end of the URL
if (url.EndsWith("?"))
Expand Down
2 changes: 1 addition & 1 deletion dotnet/test/common/ImplicitWaitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void ShouldReturnAfterFirstAttemptToFindManyAfterDisablingImplicitWaits()

[Test]
[IgnoreBrowser(Browser.IE, "Driver does not implement waiting for element visible for interaction")]
[IgnoreBrowser(Browser.Safari)]
[IgnoreBrowser(Browser.Safari, "Driver does not implement waiting for element visible for interaction")]
public void ShouldImplicitlyWaitForAnElementToBeVisibleBeforeInteracting()
{
driver.Url = dynamicPage;
Expand Down
35 changes: 29 additions & 6 deletions dotnet/test/common/Interactions/BasicKeyboardInterfaceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using OpenQA.Selenium.Internal;
using System;
using System.Drawing;
using System.Runtime.InteropServices;

namespace OpenQA.Selenium.Interactions
{
Expand All @@ -12,13 +13,23 @@ public class BasicKeyboardInterfaceTest : DriverTestFixture
[SetUp]
public void Setup()
{
new Actions(driver).SendKeys(Keys.Null).Perform();
//new Actions(driver).SendKeys(Keys.Null).Perform();
IActionExecutor actionExecutor = driver as IActionExecutor;
if (actionExecutor != null)
{
actionExecutor.ResetInputState();
}
}

[TearDown]
public void ReleaseModifierKeys()
{
new Actions(driver).SendKeys(Keys.Null).Perform();
//new Actions(driver).SendKeys(Keys.Null).Perform();
IActionExecutor actionExecutor = driver as IActionExecutor;
if (actionExecutor != null)
{
actionExecutor.ResetInputState();
}
}

[Test]
Expand Down Expand Up @@ -218,6 +229,12 @@ public void SelectionSelectBySymbol()
[Test]
public void SelectionSelectByWord()
{
string controlModifier = Keys.Control;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
controlModifier = Keys.Alt;
}

driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("single_text_input.html");

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

new Actions(driver).Click(input)
.KeyDown(Keys.Shift)
.KeyDown(Keys.Control)
.KeyDown(controlModifier)
.SendKeys(Keys.Left)
.KeyUp(Keys.Control)
.KeyUp(controlModifier)
.KeyUp(Keys.Shift)
.SendKeys(Keys.Delete)
.Perform();
Expand All @@ -256,6 +273,12 @@ public void SelectionSelectByWord()
[Test]
public void SelectionSelectAll()
{
string controlModifier = Keys.Control;
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
controlModifier = Keys.Command;
}

driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("single_text_input.html");

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

new Actions(driver).Click(input)
.KeyDown(Keys.Control)
.KeyDown(controlModifier)
.SendKeys("a")
.KeyUp(Keys.Control)
.KeyUp(controlModifier)
.SendKeys(Keys.Delete)
.Perform();

Expand Down
2 changes: 2 additions & 0 deletions dotnet/test/common/Interactions/DragAndDropTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void DragAndDropElementWithOffsetInIframeAtBottom()
[IgnoreBrowser(Browser.Edge, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.Firefox, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.IE, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.Safari, "Moving outside of view port throws exception in spec-compliant driver")]
public void DragAndDropElementWithOffsetInScrolledDiv()
{
if (TestUtilities.IsFirefox(driver) && TestUtilities.IsNativeEventsEnabled(driver))
Expand Down Expand Up @@ -140,6 +141,7 @@ public void DragTooFar()
[IgnoreBrowser(Browser.Edge, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.Firefox, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.IE, "Moving outside of view port throws exception in spec-compliant driver")]
[IgnoreBrowser(Browser.Safari, "Moving outside of view port throws exception in spec-compliant driver")]
public void ShouldAllowUsersToDragAndDropToElementsOffTheCurrentViewPort()
{
Size originalSize = driver.Manage().Window.Size;
Expand Down
7 changes: 1 addition & 6 deletions dotnet/test/common/PageLoadingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,13 @@ public void ShouldReturnWhenGettingAUrlThatDoesNotResolve()
}

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

[Test]
[IgnoreBrowser(Browser.Safari, "Safari driver does not throw on malformed URL")]
[NeedsFreshDriver(IsCreatedBeforeTest = true)]
public void ShouldThrowIfUrlIsMalformedInPortPart()
{
Expand Down Expand Up @@ -323,7 +321,6 @@ public void ShouldNotHangIfDocumentOpenCallIsNeverFollowedByDocumentCloseCall()
}

[Test]
[IgnoreBrowser(Browser.Safari)]
[NeedsFreshDriver(IsCreatedAfterTest = true)]
public void PageLoadTimeoutCanBeChanged()
{
Expand All @@ -332,7 +329,6 @@ public void PageLoadTimeoutCanBeChanged()
}

[Test]
[IgnoreBrowser(Browser.Safari)]
[NeedsFreshDriver(IsCreatedAfterTest = true)]
public void CanHandleSequentialPageLoadTimeouts()
{
Expand Down Expand Up @@ -420,7 +416,6 @@ public void ShouldTimeoutIfAPageTakesTooLongToRefresh()
[IgnoreBrowser(Browser.Chrome, "Chrome driver does, in fact, stop loading page after a timeout.")]
[IgnoreBrowser(Browser.Edge, "Edge driver does, in fact, stop loading page after a timeout.")]
[IgnoreBrowser(Browser.Opera, "Not implemented for browser")]
[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")]
[NeedsFreshDriver(IsCreatedAfterTest = true)]
public void ShouldNotStopLoadingPageAfterTimeout()
{
Expand All @@ -438,7 +433,7 @@ public void ShouldNotStopLoadingPageAfterTimeout()
try
{
string text = driver.FindElement(By.TagName("body")).Text;
return text == "Slept for 11s";
return text.Contains("Slept for 11s");
}
catch (NoSuchElementException)
{
Expand Down
4 changes: 4 additions & 0 deletions dotnet/test/common/TakesScreenshotTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public void ShouldTakeScreenshotsOfAnElement()
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
public void ShouldCaptureScreenshotOfPageWithLongX()
{
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
Expand Down Expand Up @@ -147,6 +148,7 @@ public void ShouldCaptureScreenshotOfPageWithLongX()
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
public void ShouldCaptureScreenshotOfPageWithLongY()
{
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
Expand Down Expand Up @@ -176,6 +178,7 @@ public void ShouldCaptureScreenshotOfPageWithLongY()
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
public void ShouldCaptureScreenshotOfPageWithTooLongX()
{
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
Expand Down Expand Up @@ -205,6 +208,7 @@ public void ShouldCaptureScreenshotOfPageWithTooLongX()
[IgnoreBrowser(Browser.Firefox, "Firfox driver only captures visible viewport.")]
[IgnoreBrowser(Browser.IE, "IE driver only captures visible viewport.")]
[IgnoreBrowser(Browser.EdgeLegacy, "Edge driver only captures visible viewport.")]
[IgnoreBrowser(Browser.Safari, "Safari driver only captures visible viewport.")]
public void ShouldCaptureScreenshotOfPageWithTooLongY()
{
ITakesScreenshot screenshotCapableDriver = driver as ITakesScreenshot;
Expand Down

0 comments on commit f62aefb

Please sign in to comment.