Skip to content

Commit

Permalink
[dotnet] add guards and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 29, 2022
1 parent b3c3903 commit aa5dfd6
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 145 deletions.
4 changes: 3 additions & 1 deletion dotnet/test/common/AlertsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using System.Collections.Generic;
using NUnit.Framework;
using OpenQA.Selenium.Environment;
using OpenQA.Selenium.Remote;

namespace OpenQA.Selenium
{
[TestFixture]
[IgnoreTarget("net48", "Cannot create inline page with UrlBuilder")]
public class AlertsTest : DriverTestFixture
{
[Test]
Expand Down Expand Up @@ -235,6 +235,7 @@ public void SwitchingToMissingAlertThrows()
}

[Test]
[IgnoreBrowser(Browser.IE, "Edge in IE Mode does not properly handle multiple windows")]
public void SwitchingToMissingAlertInAClosedWindowThrows()
{
string blank = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage());
Expand Down Expand Up @@ -369,6 +370,7 @@ public void ShouldHandleAlertOnPageLoadUsingGet()
}

[Test]
[IgnoreBrowser(Browser.IE, "Edge in IE Mode does not properly handle multiple windows")]
[IgnoreBrowser(Browser.Chrome, "Test with onLoad alert hangs Chrome.")]
[IgnoreBrowser(Browser.Edge, "Test with onLoad alert hangs Edge.")]
[IgnoreBrowser(Browser.Safari, "Safari driver does not allow commands in any window when an alert is active")]
Expand Down
12 changes: 7 additions & 5 deletions dotnet/test/common/ChildrenFindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void FindElementByXPath()
driver.Url = nestedPage;
IWebElement element = driver.FindElement(By.Name("form2"));
IWebElement child = element.FindElement(By.XPath("select"));
Assert.AreEqual(child.GetAttribute("id"), "2");
Assert.AreEqual("2", child.GetAttribute("id"));
}

[Test]
Expand Down Expand Up @@ -50,9 +50,9 @@ public void FindElementsByXPath()
driver.Url = nestedPage;
IWebElement element = driver.FindElement(By.Name("form2"));
ReadOnlyCollection<IWebElement> children = element.FindElements(By.XPath("select/option"));
Assert.AreEqual(children.Count, 8);
Assert.AreEqual(children[0].Text, "One");
Assert.AreEqual(children[1].Text, "Two");
Assert.AreEqual(8, children.Count);
Assert.AreEqual("One", children[0].Text);
Assert.AreEqual("Two", children[1].Text);
}

[Test]
Expand All @@ -70,7 +70,7 @@ public void FindElementByName()
driver.Url = nestedPage;
IWebElement element = driver.FindElement(By.Name("form2"));
IWebElement child = element.FindElement(By.Name("selectomatic"));
Assert.AreEqual(child.GetAttribute("id"), "2");
Assert.AreEqual("2", child.GetAttribute("id"));
}

[Test]
Expand Down Expand Up @@ -328,6 +328,7 @@ public void FindMultipleElements()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Safari does not trim")]
public void LinkWithLeadingSpaces()
{
driver.Url = simpleTestPage;
Expand All @@ -338,6 +339,7 @@ public void LinkWithLeadingSpaces()
}

[Test]
[IgnoreBrowser(Browser.Safari, "Safari does not trim")]
public void LinkWithTrailingSpace()
{
driver.Url = simpleTestPage;
Expand Down
11 changes: 0 additions & 11 deletions dotnet/test/common/ClearTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,6 @@ public void ShouldBeAbleToClearRangeInput()
ShouldBeAbleToClearInput(By.Name("range_input"), "42", "50");
}

[Test]
[IgnoreBrowser(Browser.Chrome, "Driver sees checkbox as not editable")]
[IgnoreBrowser(Browser.Edge, "Driver sees checkbox as not editable")]
[IgnoreBrowser(Browser.Firefox, "Driver sees checkbox as not editable")]
[IgnoreBrowser(Browser.IE, "Driver sees checkbox as not editable")]
[IgnoreBrowser(Browser.Safari, "Driver sees checkbox as not editable")]
public void ShouldBeAbleToClearCheckboxInput()
{
ShouldBeAbleToClearInput(By.Name("checkbox_input"), "Checkbox");
}

[Test]
[IgnoreBrowser(Browser.IE, "Driver does not support clearing color elements")]
public void ShouldBeAbleToClearColorInput()
Expand Down
4 changes: 4 additions & 0 deletions dotnet/test/common/ClickScrollingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void ShouldBeAbleToClickOnAnElementHiddenByYOverflow()
}

[Test]
[IgnoreBrowser(Browser.IE, "Scroll bar gets in they way of clicking center element")]
[IgnoreBrowser(Browser.Firefox, "https://github.com/mozilla/geckodriver/issues/2013")]
public void ShouldBeAbleToClickOnAnElementPartiallyHiddenByOverflow()
{
Expand All @@ -94,6 +95,7 @@ public void ShouldNotScrollOverflowElementsWhichAreVisible()


[Test]
[IgnoreBrowser(Browser.IE, "IE is scrolling Button2 to top of screen instead of bottom of screen as per spec")]
[IgnoreBrowser(Browser.Firefox, "https://github.com/mozilla/geckodriver/issues/2013")]
public void ShouldNotScrollIfAlreadyScrolledAndElementIsInView()
{
Expand Down Expand Up @@ -235,6 +237,8 @@ public void ShouldBeAbleToClickElementInATallFrame()
// Tests below here are not included in the Java test suite
//------------------------------------------------------------------
[Test]
[IgnoreBrowser(Browser.IE, "Clicking label is not changing checkbox")]
[IgnoreTarget("net48", "Cannot create inline page with UrlBuilder")]
public void ShouldBeAbleToClickInlineTextElementWithChildElementAfterScrolling()
{
driver.Url = EnvironmentManager.Instance.UrlBuilder.CreateInlinePage(new InlinePage()
Expand Down
1 change: 1 addition & 0 deletions dotnet/test/common/ClickTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public void ShouldClickOnFirstBoundingClientRectWithNonZeroSize()
}

[Test]
[IgnoreBrowser(Browser.IE, "Edge in IE Mode does not properly handle multiple windows")]
[NeedsFreshDriver(IsCreatedAfterTest = true)]
public void ShouldOnlyFollowHrefOnce()
{
Expand Down
24 changes: 3 additions & 21 deletions dotnet/test/common/CookieImplementationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ public void ShouldBeAbleToAddToADomainWhichIsRelatedToTheCurrentDomain()
}

[Test]
[IgnoreBrowser(Browser.IE, "IE does not want to set cookie")]
public void ShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod()
{
if (!CheckIsOnValidHostNameForCookieTests())
Expand Down Expand Up @@ -412,11 +413,6 @@ public void CookieEqualityAfterSetAndGet()
return;
}

string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals");

driver.Url = url;
driver.Manage().Cookies.DeleteAllCookies();

DateTime time = DateTime.Now.AddDays(1);
Cookie cookie1 = new Cookie("fish", "cod", null, "/common/animals", time);
IOptions options = driver.Manage();
Expand Down Expand Up @@ -446,11 +442,6 @@ public void ShouldRetainCookieExpiry()
return;
}

string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals");

driver.Url = url;
driver.Manage().Cookies.DeleteAllCookies();

// DateTime.Now contains milliseconds; the returned cookie expire date
// will not. So we need to truncate the milliseconds.
DateTime current = DateTime.Now;
Expand Down Expand Up @@ -538,11 +529,6 @@ public void ShouldRetainHttpOnlyFlag()
[Test]
public void SettingACookieThatExpiredInThePast()
{
string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals");

driver.Url = url;
driver.Manage().Cookies.DeleteAllCookies();

DateTime expires = DateTime.Now.AddSeconds(-1000);
Cookie cookie = new Cookie("expired", "yes", "/common/animals", expires);
IOptions options = driver.Manage();
Expand Down Expand Up @@ -580,6 +566,7 @@ public void DeleteNotExistedCookie()
}

[Test]
[IgnoreBrowser(Browser.IE, "IE does not want to set cookie")]
public void DeleteAllCookiesDifferentUrls()
{
if (!CheckIsOnValidHostNameForCookieTests())
Expand Down Expand Up @@ -667,7 +654,7 @@ public void ShouldNotBeAbleToSetDomainToSomethingThatIsUnrelatedToTheCurrentDoma
}

[Test]
public void GetCookieDoesNotRetriveBeyondCurrentDomain()
public void GetCookieDoesNotRetrieveBeyondCurrentDomain()
{
if (!CheckIsOnValidHostNameForCookieTests())
{
Expand Down Expand Up @@ -776,11 +763,6 @@ public void ShouldReturnNullBecauseCookieRetainsExpiry()
return;
}

string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals");
driver.Url = url;

driver.Manage().Cookies.DeleteAllCookies();

Cookie addCookie = new Cookie("fish", "cod", "/common/animals", DateTime.Now.AddHours(-1));
IOptions options = driver.Manage();
options.Cookies.AddCookie(addCookie);
Expand Down
4 changes: 2 additions & 2 deletions dotnet/test/common/CorrectEventFiringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void ShouldIssueClickEvents()
driver.FindElement(By.Id("mouseclick")).Click();

String result = driver.FindElement(By.Id("result")).Text;
Assert.AreEqual(result, "mouse click");
Assert.AreEqual("mouse click", result);
}

[Test]
Expand Down Expand Up @@ -250,7 +250,7 @@ public void ClearingAnElementShouldCauseTheOnChangeHandlerToFire()
element.Clear();

IWebElement result = driver.FindElement(By.Id("result"));
Assert.AreEqual(result.Text, "Cleared");
Assert.AreEqual("Cleared", result.Text.Trim());
}

[Test]
Expand Down
1 change: 1 addition & 0 deletions dotnet/test/common/DevTools/DevToolsLogTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace OpenQA.Selenium.DevTools
public class DevToolsLogTest : DevToolsTestFixture
{
[Test]
[Ignore("Unable to open secure url")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down
16 changes: 14 additions & 2 deletions dotnet/test/common/DevTools/DevToolsNetworkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,20 @@ await domains.Network.EmulateNetworkConditions(new V107.Network.EmulateNetworkCo
};
domains.Network.LoadingFailed += loadingFailedHandler;

driver.Url = simpleTestPage;
try
{
driver.Url = simpleTestPage;
}
catch (WebDriverException e)
{
Assert.That(e.Message.Contains("net::ERR_INTERNET_DISCONNECTED"));
}

loadingFailedSync.Wait(TimeSpan.FromSeconds(5));
}

[Test]
[Ignore("The request ID is not getting added to cache")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down Expand Up @@ -194,6 +203,7 @@ await domains.Network.Enable(new V107.Network.EnableCommandSettings()
}

[Test]
[IgnorePlatform("Windows", "Not working properly")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down Expand Up @@ -261,6 +271,7 @@ await domains.Network.SetCacheDisabled(new V107.Network.SetCacheDisabledCommandS
}

[Test]
[Ignore("Unable to open secure url")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down Expand Up @@ -428,6 +439,7 @@ public async Task VerifyEventSourceMessage()
}

[Test]
[Ignore("Unable to open secure url")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down Expand Up @@ -465,7 +477,7 @@ public async Task VerifyResourceChangedPriority()
};
domains.Network.ResourceChangedPriority += resourceChangedPriorityHandler;

driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIsSecure("simpleTest.html");
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("simpleTest.html");
requestSync.Wait(TimeSpan.FromSeconds(5));
}

Expand Down
7 changes: 2 additions & 5 deletions dotnet/test/common/DevTools/DevToolsPerformanceTest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;

Expand Down Expand Up @@ -53,6 +48,7 @@ await domains.Performance.SetTimeDomain(new V107.Performance.SetTimeDomainComman
}

[Test]
[IgnorePlatform("Windows", "Thread time is not supported on this platform")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down Expand Up @@ -90,6 +86,7 @@ await domains.Performance.SetTimeDomain(new V107.Performance.SetTimeDomainComman
}

[Test]
[IgnorePlatform("Windows", "Thread time is not supported on this platform")]
[IgnoreBrowser(Selenium.Browser.IE, "IE does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Firefox, "Firefox does not support Chrome DevTools Protocol")]
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
Expand Down
4 changes: 2 additions & 2 deletions dotnet/test/common/DevTools/DevToolsTargetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task GetTargetActivateAndAttach()
{
var domains = session.GetVersionSpecificDomains<V107.DevToolsSessionDomains>();
driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("devToolsConsoleTest.html");
var response = await domains.Target.GetTargets(null);
var response = await domains.Target.GetTargets();
V107.Target.TargetInfo[] allTargets = response.TargetInfos;
foreach (V107.Target.TargetInfo targetInfo in allTargets)
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task GetTargetAndSendMessageToTarget()
ValidateMessage(e);
sync.Set();
};
var targetsResponse = await domains.Target.GetTargets(null);
var targetsResponse = await domains.Target.GetTargets();
allTargets = targetsResponse.TargetInfos;
ValidateTargetsInfos(allTargets);
ValidateTarget(allTargets[0]);
Expand Down
26 changes: 2 additions & 24 deletions dotnet/test/common/ElementFindingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ public void FindingASingleElementByEmptyTagNameShouldThrow()
Assert.That(() => driver.FindElement(By.TagName("")), Throws.InstanceOf<NoSuchElementException>());
}

[Test]
[IgnoreBrowser(Browser.Chrome, "Throwing invalid selector error")]
public void FindingMultipleElementsByEmptyTagNameShouldReturnEmptyList()
{
driver.Url = formsPage;
ReadOnlyCollection<IWebElement> elements = driver.FindElements(By.TagName(""));
Assert.AreEqual(0, elements.Count);
}

[Test]
public void FindingASingleElementByTagNameWithSpaceShouldThrow()
{
Expand Down Expand Up @@ -438,18 +429,6 @@ public void ShouldBeAbleToFindElementByXPathWithNamespace()
Assert.That(element.Text, Is.EqualTo("Test Chart"));
}

[Test]
[IgnoreBrowser(Browser.IE, "Driver does not support finding elements on XML documents.")]
[IgnoreBrowser(Browser.Chrome, "Driver does not support finding elements on XML documents.")]
[IgnoreBrowser(Browser.Edge, "Driver does not support finding elements on XML documents.")]
[IgnoreBrowser(Browser.Safari, "Not yet implemented")]
public void ShouldBeAbleToFindElementByXPathInXmlDocument()
{
driver.Url = simpleXmlDocument;
IWebElement element = driver.FindElement(By.XPath("//foo"));
Assert.That(element.Text, Is.EqualTo("baz"));
}

// By.XPath negative

[Test]
Expand Down Expand Up @@ -821,15 +800,14 @@ public void ShouldNotBeAbleToLocateASingleElementOnABlankPage()
}

[Test]
[IgnoreBrowser(Browser.Chrome, "https://bugs.chromium.org/p/chromedriver/issues/detail?id=3742")]
[IgnoreBrowser(Browser.Edge, "https://bugs.chromium.org/p/chromedriver/issues/detail?id=3742")]
[IgnoreBrowser(Browser.Firefox, "Already updated to https://github.com/w3c/webdriver/issues/1594")]
public void AnElementFoundInADifferentFrameIsStale()
{
driver.Url = missedJsReferencePage;
driver.SwitchTo().Frame("inner");
IWebElement element = driver.FindElement(By.Id("oneline"));
driver.SwitchTo().DefaultContent();
Assert.That(() => { string foo = element.Text; }, Throws.InstanceOf<NoSuchElementException>());
Assert.That(() => { string foo = element.Text; }, Throws.InstanceOf<StaleElementReferenceException>());
}

[Test]
Expand Down
Loading

0 comments on commit aa5dfd6

Please sign in to comment.