From 0a9437d5715650f5e0836ab91b35cec755b0912b Mon Sep 17 00:00:00 2001 From: wjgerritsen-0001 <40887209+wjgerritsen-0001@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:04:12 +0200 Subject: [PATCH 1/3] use global usings to reduce the number of usings in each file upgrade to NUnit 4 and use Assert.That syntax everywhere added constraints to verify (no) timeout: Does.Timeout and Does.NoTimeout - verify exception throwed - verfiy error message - verify duration Refactored outcommented test to use [Ignore] attribute Single place to read resource path from assembly: BaseTest.EmptyHtmlPath --- .editorconfig | 4 + NSelene.sln | 22 +- NSelene/Wait.cs | 2 +- NSeleneTests/AssemblyInfo.cs | 11 +- .../Straightforward/TodoMvc_Should.cs | 10 +- .../WithPageObjects/TodoMvc_Should.cs | 9 +- .../Configuration_SetValueByJs_Specs.cs | 11 +- .../SharedDriver/Configuration_Specs.cs | 72 ++- .../Configuration_TypeByJs_Specs.cs | 11 +- .../Configuration__HookWaitAction_Specs.cs | 23 +- .../SharedDriver/ErrorMessages_Specs.cs | 64 +- .../SharedDriver/Harness/BaseTest.cs | 36 +- .../Constraints/PassAfterConstraint.cs | 35 ++ .../Harness/Constraints/TimeoutConstraint.cs | 39 ++ .../Integration/SharedDriver/Harness/Does.cs | 21 + .../Integration/SharedDriver/Harness/Given.cs | 84 +-- .../Conditions/Attribute.cs | 3 - .../OldConditionsSpecs/Conditions/Count.cs | 3 - .../OldConditionsSpecs/Conditions/CssClass.cs | 3 - .../OldConditionsSpecs/Conditions/Enabled.cs | 2 - .../OldConditionsSpecs/Conditions/InDom.cs | 3 - .../Conditions/JSReturnedTrue.cs | 6 +- .../OldConditionsSpecs/Conditions/Selected.cs | 2 - .../OldConditionsSpecs/Conditions/Text.cs | 3 - .../OldConditionsSpecs/Conditions/Texts.cs | 2 - .../OldConditionsSpecs/Conditions/Visible.cs | 2 - .../SeleneBrowser_Should_Specs.cs | 148 ++--- .../SeleneCollection_Should_Specs.cs | 124 ++-- .../SeleneElement_Should_Specs.cs | 474 ++++++--------- .../SeleneBrowser_Should_Specs.cs | 144 ++--- .../SeleneCollection_ElementByIts_Specs.cs | 13 - .../SeleneCollection_Enumerable_Specs.cs | 43 +- .../SeleneCollection_FilterBy_Specs.cs | 32 +- .../SeleneCollection_FindBy_Specs.cs | 57 +- .../SeleneCollection_Indexer_Specs.cs | 114 ++-- .../SeleneCollection_Matching_Specs.cs | 24 +- .../SeleneCollection_Queries_Specs.cs | 7 +- .../SeleneCollection_Should_Specs.cs | 119 ++-- .../SeleneCollection_WaitUntil_Specs.cs | 32 +- .../SeleneElementJsExtensions_Specs.cs | 52 +- .../SeleneElementQueries_Specs.cs | 15 +- .../SeleneElement_Actions_Specs.cs | 4 - .../SharedDriver/SeleneElement_Clear_Specs.cs | 313 ++++------ .../SharedDriver/SeleneElement_Click_Specs.cs | 113 ++-- .../SeleneElement_Displayed_Specs.cs | 45 +- .../SeleneElement_DoubleClick_Specs.cs | 157 ++--- .../SeleneElement_ExecuteScript_Specs.cs | 14 +- .../SeleneElement_FindAll_Specs.cs | 28 +- .../SharedDriver/SeleneElement_Find_Specs.cs | 202 ++----- .../SharedDriver/SeleneElement_Hover_Specs.cs | 167 ++--- .../SeleneElement_Matching_Specs.cs | 26 +- .../SeleneElement_SendKeys_Specs.cs | 263 ++++---- .../SeleneElement_SetValue_Specs.cs | 345 ++++------- .../SeleneElement_Should_Specs.cs | 570 ++++++------------ .../SeleneElement_Submit_Specs.cs | 205 +++---- .../SeleneElement_ToString_Specs.cs | 21 +- .../SharedDriver/SeleneElement_Type_Specs.cs | 294 ++++----- .../SeleneElement_WaitUntil_Specs.cs | 32 +- .../SharedDriver/SeleneElement_With_Specs.cs | 40 +- .../Selene_ExecuteScript_Specs.cs | 3 - .../SharedDriver/Selene_SS_Specs.cs | 24 +- .../SharedDriver/Selene_S_Specs.cs | 53 +- .../AssertingByCollectionConditions_Specs.cs | 4 - .../AssertingByElementConditions_Specs.cs | 4 - NSeleneTests/NSeleneTests.csproj | 10 +- NSeleneTests/Unit/ConditionSpecs.cs | 13 +- NSeleneTests/Unit/Condition_Not_Specs.cs | 14 +- 67 files changed, 1772 insertions(+), 3073 deletions(-) create mode 100644 .editorconfig create mode 100644 NSeleneTests/Integration/SharedDriver/Harness/Constraints/PassAfterConstraint.cs create mode 100644 NSeleneTests/Integration/SharedDriver/Harness/Constraints/TimeoutConstraint.cs create mode 100644 NSeleneTests/Integration/SharedDriver/Harness/Does.cs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..333fa6c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0039: Use local function +csharp_style_prefer_local_over_anonymous_function = false diff --git a/NSelene.sln b/NSelene.sln index 98b72f6..8b50ef1 100644 --- a/NSelene.sln +++ b/NSelene.sln @@ -1,11 +1,16 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26124.0 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 MinimumVisualStudioVersion = 15.0.26124.0 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSelene", "NSelene\NSelene.csproj", "{643535D8-7276-4888-A2DB-02125198302A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSelene", "NSelene\NSelene.csproj", "{643535D8-7276-4888-A2DB-02125198302A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSeleneTests", "NSeleneTests\NSeleneTests.csproj", "{DC713443-6E7A-4657-9654-F3779AB30A5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSeleneTests", "NSeleneTests\NSeleneTests.csproj", "{DC713443-6E7A-4657-9654-F3779AB30A5C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C78A189D-05BF-4375-B8BE-14AACDA41B1D}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -16,9 +21,6 @@ Global Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {643535D8-7276-4888-A2DB-02125198302A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {643535D8-7276-4888-A2DB-02125198302A}.Debug|Any CPU.Build.0 = Debug|Any CPU @@ -45,4 +47,10 @@ Global {DC713443-6E7A-4657-9654-F3779AB30A5C}.Release|x86.ActiveCfg = Release|Any CPU {DC713443-6E7A-4657-9654-F3779AB30A5C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {571C60E7-30CC-4D99-99D3-DD87B0B34687} + EndGlobalSection EndGlobal diff --git a/NSelene/Wait.cs b/NSelene/Wait.cs index edd2e3f..813a2bd 100644 --- a/NSelene/Wait.cs +++ b/NSelene/Wait.cs @@ -229,7 +229,7 @@ private _Result _For(_Computation computation) // TODO: should we ac throw failure; } - Thread.Sleep(TimeSpan.FromSeconds(this.polling).Milliseconds); + Thread.Sleep((int)TimeSpan.FromSeconds(this.polling).TotalMilliseconds); } } // throw failFastError; diff --git a/NSeleneTests/AssemblyInfo.cs b/NSeleneTests/AssemblyInfo.cs index 2678057..0af9636 100644 --- a/NSeleneTests/AssemblyInfo.cs +++ b/NSeleneTests/AssemblyInfo.cs @@ -1,4 +1,13 @@ -using NUnit.Framework; +global using Does = NSelene.Tests.Integration.SharedDriver.Harness.Does; +global using NSelene.Conditions; +global using NSelene.Tests.Integration.SharedDriver.Harness; +global using NSelene; +global using NUnit.Framework; +global using OpenQA.Selenium.Chrome; +global using OpenQA.Selenium; +global using System.Linq; +global using System; +global using static NSelene.Selene; [assembly: LevelOfParallelism(2)] [assembly: Parallelizable(ParallelScope.Fixtures)] diff --git a/NSeleneTests/Examples/SharedDriver/Straightforward/TodoMvc_Should.cs b/NSeleneTests/Examples/SharedDriver/Straightforward/TodoMvc_Should.cs index eaa2c1c..84ad811 100644 --- a/NSeleneTests/Examples/SharedDriver/Straightforward/TodoMvc_Should.cs +++ b/NSeleneTests/Examples/SharedDriver/Straightforward/TodoMvc_Should.cs @@ -1,8 +1,3 @@ -using NUnit.Framework; -using OpenQA.Selenium; -using OpenQA.Selenium.Chrome; -using static NSelene.Selene; - namespace NSelene.Tests.Examples.SharedDriver.StraightForward { [TestFixture] @@ -11,7 +6,7 @@ public class BrowserTest IWebDriver driver; [OneTimeSetUp] - public void initDriver() + public void InitDriver() { var options = new ChromeOptions(); options.AddArguments("headless"); @@ -21,10 +16,11 @@ public void initDriver() } [OneTimeTearDown] - public void disposeDriver() + public void DisposeDriver() { Configuration.BaseUrl = ""; this.driver.Quit(); + this.driver.Dispose(); } } diff --git a/NSeleneTests/Examples/SharedDriver/WithPageObjects/TodoMvc_Should.cs b/NSeleneTests/Examples/SharedDriver/WithPageObjects/TodoMvc_Should.cs index 05054e4..46282af 100644 --- a/NSeleneTests/Examples/SharedDriver/WithPageObjects/TodoMvc_Should.cs +++ b/NSeleneTests/Examples/SharedDriver/WithPageObjects/TodoMvc_Should.cs @@ -1,14 +1,10 @@ -using NUnit.Framework; -using OpenQA.Selenium.Chrome; -using static NSelene.Selene; - namespace NSelene.Tests.Examples.SharedDriver.WithPageObjects { [TestFixture] public class BrowserTest { [OneTimeSetUp] - public void initDriver() + public void InitDriver() { var options = new ChromeOptions(); options.AddArguments("headless"); @@ -16,9 +12,10 @@ public void initDriver() } [OneTimeTearDown] - public void disposeDriver() + public void DisposeDriver() { Configuration.Driver.Quit(); + Configuration.Driver.Dispose(); } } diff --git a/NSeleneTests/Integration/SharedDriver/Configuration_SetValueByJs_Specs.cs b/NSeleneTests/Integration/SharedDriver/Configuration_SetValueByJs_Specs.cs index c65c1f5..df751b7 100644 --- a/NSeleneTests/Integration/SharedDriver/Configuration_SetValueByJs_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/Configuration_SetValueByJs_Specs.cs @@ -1,12 +1,5 @@ -using NUnit.Framework; -using static NSelene.Selene; -using OpenQA.Selenium; - namespace NSelene.Tests.Integration.SharedDriver.ConfigurationSpec { - using System; - using Harness; - [TestFixture] public class Configuration_SetValueByJs_Specs : BaseTest { @@ -33,7 +26,7 @@ public void SetValue_ViaElementCustomizedToJs_SetsItFasterThanNormalSetValue() S("#field2").Should(Have.Value(new string('*', 200))); var jsTime = afterJsSetValue - beforeJsSetValue; - Assert.Less(jsTime, setValueTime / 2); + Assert.That(jsTime, Is.LessThan(setValueTime / 2)); } [Test] @@ -59,7 +52,7 @@ public void SetValue_ViaConfiguredGloballyToJs_SetsItFasterThanNormalSetValue() S("#field2").Should(Have.Value(new string('*', 200))); var jsTime = afterJsSetValue - beforeJsSetValue; - Assert.Less(jsTime, setValueTime / 2); + Assert.That(jsTime, Is.LessThan(setValueTime / 2)); } } } diff --git a/NSeleneTests/Integration/SharedDriver/Configuration_Specs.cs b/NSeleneTests/Integration/SharedDriver/Configuration_Specs.cs index 573a18a..abaa0b0 100644 --- a/NSeleneTests/Integration/SharedDriver/Configuration_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/Configuration_Specs.cs @@ -1,7 +1,3 @@ -using NUnit.Framework; -using OpenQA.Selenium; -using OpenQA.Selenium.Chrome; - namespace NSelene.Tests.Integration.SharedDriver.SeleneElementSpec { @@ -30,7 +26,9 @@ public void InitConfiguration() public void ResetConfiguration() { this._driver1.Quit(); + this._driver1.Dispose(); this._driver2.Quit(); + this._driver2.Dispose(); Configuration.Driver = null; Configuration.Timeout = 4; @@ -60,11 +58,11 @@ public void New_CreatesNewConfigWithAllSettingsDefaults() var fresh = Configuration._New_(); // THEN - Assert.AreEqual(null, fresh.Driver); - Assert.AreEqual(4.0, fresh.Timeout); - Assert.AreEqual(0.1, fresh.PollDuringWaits); - Assert.AreEqual(false, fresh.SetValueByJs); - Assert.AreEqual("", fresh.BaseUrl); + Assert.That(fresh.Driver, Is.EqualTo(null)); + Assert.That(fresh.Timeout, Is.EqualTo(4.0)); + Assert.That(fresh.PollDuringWaits, Is.EqualTo(0.1)); + Assert.That(fresh.SetValueByJs, Is.EqualTo(false)); + Assert.That(fresh.BaseUrl, Is.EqualTo("")); } [Test] @@ -81,11 +79,11 @@ public void New_DoesNotTouchExistingSharedStaticConfiguration() var fresh = Configuration._New_(); // THEN - Assert.AreEqual(_driver1, Configuration.Driver); - Assert.AreEqual(9.9, Configuration.Timeout); - Assert.AreEqual(0.9, Configuration.PollDuringWaits); - Assert.AreEqual(true, Configuration.SetValueByJs); - Assert.AreEqual("test url", Configuration.BaseUrl); + Assert.That(Configuration.Driver, Is.EqualTo(_driver1)); + Assert.That(Configuration.Timeout, Is.EqualTo(9.9)); + Assert.That(Configuration.PollDuringWaits, Is.EqualTo(0.9)); + Assert.That(Configuration.SetValueByJs, Is.EqualTo(true)); + Assert.That(Configuration.BaseUrl, Is.EqualTo("test url")); } [Test] @@ -98,12 +96,12 @@ public void New_CanCustomizeManySettings() setValueByJs: true, baseUrl: "test url" ); - - Assert.AreEqual(this._driver1, custom.Driver); - Assert.AreEqual(2.0, custom.Timeout); - Assert.AreEqual(0.2, custom.PollDuringWaits); - Assert.AreEqual(true, custom.SetValueByJs); - Assert.AreEqual("test url", custom.BaseUrl); + + Assert.That(custom.Driver, Is.EqualTo(this._driver1)); + Assert.That(custom.Timeout, Is.EqualTo(2.0)); + Assert.That(custom.PollDuringWaits, Is.EqualTo(0.2)); + Assert.That(custom.SetValueByJs, Is.EqualTo(true)); + Assert.That(custom.BaseUrl, Is.EqualTo("test url")); } [Test] @@ -114,8 +112,8 @@ public void New_CanCustomizeSetting() var custom = Configuration._New_(timeout: 2.0, baseUrl: "test2 url"); - Assert.AreEqual(2.0, custom.Timeout); - Assert.AreEqual("test2 url", custom.BaseUrl); + Assert.That(custom.Timeout, Is.EqualTo(2.0)); + Assert.That(custom.BaseUrl, Is.EqualTo("test2 url")); } [Test] @@ -126,8 +124,8 @@ public void With_CustomizesSetting() var custom = Configuration._With_(timeout: 2.0, baseUrl: "test2 url"); - Assert.AreEqual(2.0, custom.Timeout); - Assert.AreEqual("test2 url", custom.BaseUrl); + Assert.That(custom.Timeout, Is.EqualTo(2.0)); + Assert.That(custom.BaseUrl, Is.EqualTo("test2 url")); } [Test] @@ -138,8 +136,8 @@ public void With_ReusesLatestSharedSettingsNotExplicitelyOverriden() var custom = Configuration._With_(timeout: 1.0); - Assert.AreEqual(1.0, custom.Timeout); - Assert.AreEqual(0.2, custom.PollDuringWaits); + Assert.That(custom.Timeout, Is.EqualTo(1.0)); + Assert.That(custom.PollDuringWaits, Is.EqualTo(0.2)); } [Test] @@ -154,9 +152,9 @@ public void WithConfig_TracksChangesOnlyInReusedSharedConfigSettings() Configuration.Timeout = 2.0; Configuration.PollDuringWaits = 0.25; - Assert.AreEqual(1.0, custom.Timeout); - Assert.AreSame(this._driver2, custom.Driver); - Assert.AreEqual(0.25, custom.PollDuringWaits); + Assert.That(custom.Timeout, Is.EqualTo(1.0)); + Assert.That(custom.Driver, Is.SameAs(this._driver2)); + Assert.That(custom.PollDuringWaits, Is.EqualTo(0.25)); } [Test] @@ -168,9 +166,9 @@ public void NewConfig_StaysUnchangedOnFurtherSharedConfigUpdates() Configuration.PollDuringWaits = 0.2; Configuration.BaseUrl = "test2 url"; - Assert.AreEqual(1.0, custom.Timeout); - Assert.AreEqual(0.1, custom.PollDuringWaits); - Assert.AreEqual("test url", custom.BaseUrl); + Assert.That(custom.Timeout, Is.EqualTo(1.0)); + Assert.That(custom.PollDuringWaits, Is.EqualTo(0.1)); + Assert.That(custom.BaseUrl, Is.EqualTo("test url")); } [Test] @@ -181,11 +179,11 @@ public void Several_NewConfigs_Are_Different() var second = Configuration._New_(timeout: 2.0, baseUrl: "test2 url"); - Assert.AreEqual(1.0, first.Timeout); - Assert.AreEqual(2.0, second.Timeout); - - Assert.AreEqual("test url", first.BaseUrl); - Assert.AreEqual("test2 url", second.BaseUrl); + Assert.That(first.Timeout, Is.EqualTo(1.0)); + Assert.That(second.Timeout, Is.EqualTo(2.0)); + + Assert.That(first.BaseUrl, Is.EqualTo("test url")); + Assert.That(second.BaseUrl, Is.EqualTo("test2 url")); } // TODO: ensure that switching Configuration.driver will work on S, etc. diff --git a/NSeleneTests/Integration/SharedDriver/Configuration_TypeByJs_Specs.cs b/NSeleneTests/Integration/SharedDriver/Configuration_TypeByJs_Specs.cs index 5ed5c5b..e784b09 100644 --- a/NSeleneTests/Integration/SharedDriver/Configuration_TypeByJs_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/Configuration_TypeByJs_Specs.cs @@ -1,12 +1,5 @@ -using NUnit.Framework; -using static NSelene.Selene; -using OpenQA.Selenium; - namespace NSelene.Tests.Integration.SharedDriver.ConfigurationSpec { - using System; - using Harness; - [TestFixture] public class Configuration_TypeByJs_Specs : BaseTest { @@ -33,7 +26,7 @@ public void Type_ViaElementCustomizedToJs_SetsItFasterThanNormalType() S("#field2").Should(Have.Value("prefix to append to " + new string('*', 100))); var jsTime = afterJsSetValue - beforeJsSetValue; - Assert.Less(jsTime, setValueTime / 2.0); + Assert.That(jsTime, Is.LessThan(setValueTime / 2.0)); } [Test] @@ -59,7 +52,7 @@ public void Type_ViaConfiguredGloballyToJs_SetsItFasterThanNormalType() S("#field2").Should(Have.Value("prefix to append to " + new string('*', 100))); var jsTime = afterJsSetValue - beforeJsSetValue; - Assert.Less(jsTime, setValueTime / 2.0); + Assert.That(jsTime, Is.LessThan(setValueTime / 2.0)); } } } diff --git a/NSeleneTests/Integration/SharedDriver/Configuration__HookWaitAction_Specs.cs b/NSeleneTests/Integration/SharedDriver/Configuration__HookWaitAction_Specs.cs index bb672fc..bb4fa61 100644 --- a/NSeleneTests/Integration/SharedDriver/Configuration__HookWaitAction_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/Configuration__HookWaitAction_Specs.cs @@ -1,14 +1,7 @@ -using NUnit.Framework; -using static NSelene.Selene; -using OpenQA.Selenium; +using System.Collections.Generic; namespace NSelene.Tests.Integration.SharedDriver.ConfigurationSpec { - using System; - using System.Collections.Generic; - using System.Linq; - using Harness; - [TestFixture] public class Configuration__HookWaitAction_Specs : BaseTest { @@ -45,8 +38,7 @@ public void HookWaitAction_SetGlobally_CanLogActionsLikeClickAndShould() try { SS(".absent").Should(Have.Count(1)); } catch {} try { S(".parent").All(".child").Should(Have.Count(1)); } catch {} - Assert.AreEqual(log, - @"Browser.All(button).Should(Have.Count = 1): STARTED + Assert.That(@"Browser.All(button).Should(Have.Count = 1): STARTED Browser.All(button).Should(Have.Count = 1): PASSED Browser.Element(button).Should(Have.ExactText(«Click me!»)): STARTED Browser.Element(button).Should(Have.ExactText(«Click me!»)): PASSED @@ -62,7 +54,8 @@ public void HookWaitAction_SetGlobally_CanLogActionsLikeClickAndShould() Browser.All(.absent).Should(Have.Count = 1): FAILED Browser.Element(.parent).All(.child).Should(Have.Count = 1): STARTED Browser.Element(.parent).All(.child).Should(Have.Count = 1): FAILED" - .Split(Environment.NewLine).Select(item => item.Trim()).ToList() + .Split(Environment.NewLine).Select(item => item.Trim()).ToList(), + Is.EqualTo(log) ); } @@ -102,9 +95,8 @@ public void HookWaitAction_SetPerElements_CanLogActionsLikeClickAndShould() try { absent.Should(Have.Text("some")); } catch {} try { allAbsent.Should(Have.Count(1)); } catch {} try { absent.All(".child").Should(Have.Count(1)); } catch {} - - Assert.AreEqual(log, - @"Browser.All(button).Should(Have.Count = 1): STARTED + + Assert.That(@"Browser.All(button).Should(Have.Count = 1): STARTED Browser.All(button).Should(Have.Count = 1): PASSED Browser.Element(button).Should(Have.ExactText(«Click me!»)): STARTED Browser.Element(button).Should(Have.ExactText(«Click me!»)): PASSED @@ -120,7 +112,8 @@ public void HookWaitAction_SetPerElements_CanLogActionsLikeClickAndShould() Browser.All(.absent).Should(Have.Count = 1): FAILED Browser.Element(.absent).All(.child).Should(Have.Count = 1): STARTED Browser.Element(.absent).All(.child).Should(Have.Count = 1): FAILED" - .Split(Environment.NewLine).Select(item => item.Trim()).ToList() + .Split(Environment.NewLine).Select(item => item.Trim()).ToList(), + Is.EqualTo(log) ); } } diff --git a/NSeleneTests/Integration/SharedDriver/ErrorMessages_Specs.cs b/NSeleneTests/Integration/SharedDriver/ErrorMessages_Specs.cs index e607116..dd64f99 100644 --- a/NSeleneTests/Integration/SharedDriver/ErrorMessages_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/ErrorMessages_Specs.cs @@ -1,5 +1,3 @@ -using static NSelene.Selene; -using NUnit.Framework; using NSelene.Support.SeleneElementJsExtensions; using NSelene.Tests.Integration.SharedDriver.Harness; using System; @@ -11,60 +9,43 @@ public class ErrorMessages_Specs : BaseTest { // todo: make it "condition tests" - [TearDown] - public void TeardownTest() - { - Configuration.Timeout = 4; - } - [Test] public void SeleneElement_Click_Failure_OnHiddenElement() { - Configuration.Timeout = 0.25; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody(@" go to Heading 2

Heading 2

" ); - // TODO: consider using Assert.Throws(() => { ... }) - try { + var act = () => { S("a").Click(); - Assert.Fail("should fail on timeout before can be clicked"); - } + }; - catch (TimeoutException error) - { - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(a).ActualWebElement.Click() + Assert.That(act, Does.Timeout($$""" + Browser.Element(a).ActualWebElement.Click() Reason: element not interactable - """.Trim() - )); - } + """)); } [Test] public void SeleneElement_CustomizedToJsClick_Click_Failure_OnAbsentInDomElement() { - Configuration.Timeout = 0.25; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody(@"

Heading 2

"); - // TODO: consider using Assert.Throws(() => { ... }) - try { + var act = () => { S("a").With(clickByJs: true).Click(); - Assert.Fail("should fail on timeout before can be clicked"); - } catch (TimeoutException error) { - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(a).JsClick(centerXOffset: 0, centerYOffset: 0) + }; + + Assert.That(act, Does.Timeout($$""" + Browser.Element(a).JsClick(centerXOffset: 0, centerYOffset: 0) Reason: no such element: Unable to locate element: {"method":"css selector","selector":"a"} - """.Trim() - )); - } + """)); } /// TODO: a raw JsClick test and see what will come... it will fail without waiting @@ -77,24 +58,21 @@ public void SeleneElement_CustomizedToJsClick_Click_Failure_OnAbsentInDomElement [Test] public void SeleneElement_JsClick_Failure_OnAbsentInDomElement() { - Configuration.Timeout = 0.25; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody(@"

Heading 2

"); - // TODO: consider using Assert.Throws(() => { ... }) - try { + var act = () => + { S("a").JsClick(); - Assert.Fail("should fail before can be js-clicked"); - } catch (TimeoutException error) { - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(a).JsClick(centerXOffset: 0, centerYOffset: 0) + }; + + Assert.That(act, Does.Timeout($$""" + Browser.Element(a).JsClick(centerXOffset: 0, centerYOffset: 0) Reason: no such element: Unable to locate element: {"method":"css selector","selector":"a"} - """.Trim() - )); - } + """)); } } } diff --git a/NSeleneTests/Integration/SharedDriver/Harness/BaseTest.cs b/NSeleneTests/Integration/SharedDriver/Harness/BaseTest.cs index c8cda75..5410d4e 100644 --- a/NSeleneTests/Integration/SharedDriver/Harness/BaseTest.cs +++ b/NSeleneTests/Integration/SharedDriver/Harness/BaseTest.cs @@ -1,8 +1,4 @@ -using System; -using NUnit.Framework; -using OpenQA.Selenium; -using OpenQA.Selenium.Chrome; -using static NSelene.Selene; +using System.Reflection; namespace NSelene.Tests.Integration.SharedDriver.Harness { @@ -10,19 +6,37 @@ namespace NSelene.Tests.Integration.SharedDriver.Harness [TestFixture] public class BaseTest { - IWebDriver _driver; + public const double ShortTimeout = 0.25; + public const double MediumTimeout = 0.6; + public const double LongTimeout = 4.0; + public const double PollDuringWaits = 0.1; + public static readonly TimeSpan ShortTimeoutSpan = TimeSpan.FromSeconds(ShortTimeout); + + internal static readonly string EmptyHtmlPath = new Uri( + new Uri(Assembly.GetExecutingAssembly().Location), + "../../../Resources/empty.html" + ).AbsolutePath; + internal static readonly string EmptyHtmlUri = new Uri( + new Uri(Assembly.GetExecutingAssembly().Location), + "../../../Resources/empty.html" + ).AbsoluteUri; + + IWebDriver _driver; [OneTimeSetUp] - public void initDriver() + public void InitDriver() { var options = new ChromeOptions(); options.AddArguments("headless"); this._driver = new ChromeDriver(options); - + } + [SetUp] + public void InitDefaults() + { // explicit resetting defaults Configuration.Driver = this._driver; - Configuration.Timeout = 4.0; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = LongTimeout; + Configuration.PollDuringWaits = PollDuringWaits; Configuration.SetValueByJs = false; Configuration.TypeByJs = false; Configuration.ClickByJs = false; @@ -33,7 +47,7 @@ public void initDriver() } [OneTimeTearDown] - public void disposeDriver() + public void DisposeDriver() { this._driver?.Quit(); this._driver?.Dispose(); diff --git a/NSeleneTests/Integration/SharedDriver/Harness/Constraints/PassAfterConstraint.cs b/NSeleneTests/Integration/SharedDriver/Harness/Constraints/PassAfterConstraint.cs new file mode 100644 index 0000000..2655cd2 --- /dev/null +++ b/NSeleneTests/Integration/SharedDriver/Harness/Constraints/PassAfterConstraint.cs @@ -0,0 +1,35 @@ +using NUnit.Framework.Constraints; + +namespace NSelene.Tests.Integration.SharedDriver.Harness.Constraints +{ + internal class PassAfterConstraint(TimeSpan? delayBeforePass) : Constraint + { + private readonly TimeSpan _delayBeforePass = delayBeforePass ?? TimeSpan.Zero; + + public override ConstraintResult ApplyTo(TActual actual) + { + var beforeCall = DateTime.Now; + try + { + if (actual is Action act) + { + act.Invoke(); + } + else + { + return new ConstraintResult(this, "Not a System.Action object passed to the constraint", ConstraintStatus.Error); + } + } + catch (TimeoutException ex) + { + return new ConstraintResult(this, ex.Message, ConstraintStatus.Failure); + } + var elapsedTime = DateTime.Now.Subtract(beforeCall); + var elapsedTimeLimit = TimeSpan.FromSeconds(Configuration.Timeout); + + return new ConstraintResult(this, elapsedTime, elapsedTime < elapsedTimeLimit && elapsedTime >= _delayBeforePass); + } + + public override string Description => $"Should not timeout" + (_delayBeforePass == TimeSpan.Zero ? "" : $" or pass in less then {_delayBeforePass}"); + } +} diff --git a/NSeleneTests/Integration/SharedDriver/Harness/Constraints/TimeoutConstraint.cs b/NSeleneTests/Integration/SharedDriver/Harness/Constraints/TimeoutConstraint.cs new file mode 100644 index 0000000..56e61cc --- /dev/null +++ b/NSeleneTests/Integration/SharedDriver/Harness/Constraints/TimeoutConstraint.cs @@ -0,0 +1,39 @@ +using NUnit.Framework.Constraints; + +namespace NSelene.Tests.Integration.SharedDriver.Harness.Constraints +{ + internal class TimeoutConstraint(string errorMessage) : Constraint + { + private readonly string errorMessage = $$""" + Timed out after {{Configuration.Timeout}}s, while waiting for: + {{errorMessage}} + """; + + public override ConstraintResult ApplyTo(TActual actual) + { + if (actual is not Action act) + { + return new ConstraintResult(this, "Not a System.Action object passed to the constraint", ConstraintStatus.Error); + } + + var accuracyDelta = 2.0; + var beforeCall = DateTime.Now; + try + { + act.Invoke(); + return new ConstraintResult(this, "Did not timeout", ConstraintStatus.Failure); + } + catch (TimeoutException error) + { + if (!error.Message.Contains(errorMessage)) + { + return new ConstraintResult(this, error.Message, ConstraintStatus.Failure); + } + var elapsedTime = DateTime.Now.Subtract(beforeCall); + return new ConstraintResult(this, elapsedTime, elapsedTime < TimeSpan.FromSeconds(Configuration.Timeout + BaseTest.PollDuringWaits + accuracyDelta) && elapsedTime >= TimeSpan.FromSeconds(Configuration.Timeout)); + } + } + + public override string Description => $"Should timeout and throw TimeoutException with message: \r\n'{errorMessage}'"; + } +} diff --git a/NSeleneTests/Integration/SharedDriver/Harness/Does.cs b/NSeleneTests/Integration/SharedDriver/Harness/Does.cs new file mode 100644 index 0000000..10f3e4f --- /dev/null +++ b/NSeleneTests/Integration/SharedDriver/Harness/Does.cs @@ -0,0 +1,21 @@ +using NSelene.Tests.Integration.SharedDriver.Harness.Constraints; + +namespace NSelene.Tests.Integration.SharedDriver.Harness +{ + internal class Does : NUnit.Framework.Does + { + internal static PassAfterConstraint Pass() + { + return new PassAfterConstraint(null); + } + internal static PassAfterConstraint PassAfter(TimeSpan delayBeforePass) + { + return new PassAfterConstraint(delayBeforePass); + } + + internal static TimeoutConstraint Timeout(string errorMessage) + { + return new TimeoutConstraint(errorMessage); + } + } +} diff --git a/NSeleneTests/Integration/SharedDriver/Harness/Given.cs b/NSeleneTests/Integration/SharedDriver/Harness/Given.cs index 06f74dd..8773b71 100644 --- a/NSeleneTests/Integration/SharedDriver/Harness/Given.cs +++ b/NSeleneTests/Integration/SharedDriver/Harness/Given.cs @@ -1,65 +1,31 @@ -using System; -using System.Reflection; -using NSelene; -using OpenQA.Selenium; - namespace NSelene.Tests.Integration.SharedDriver.Harness { public class When { public static void WithBody(string html) { - Selene.ExecuteScript( - "document.getElementsByTagName('body')[0].innerHTML = `" - + html + "`;" - ); - } - - public static void WithBody(string html, IWebDriver driver) - { - (driver as IJavaScriptExecutor).ExecuteScript( - "document.getElementsByTagName('body')[0].innerHTML = `" - + html + "`;" - ); - } - - public static void WithBodyTimedOut(string html, double timeout) - { - Selene.ExecuteScript(@" - setTimeout( - function(){ - document.getElementsByTagName('body')[0].innerHTML = `" + html + @"` - }, - " + timeout + ");" + Selene.ExecuteScript($""" + document.getElementsByTagName('body')[0].innerHTML = `{html}`; + """ ); } - public static void WithBodyTimedOut(string html, double timeout, IWebDriver driver) + public static void WithBodyTimedOut(string html, TimeSpan timeout) { - (driver as IJavaScriptExecutor).ExecuteScript(@" - setTimeout( - function(){ - document.getElementsByTagName('body')[0].innerHTML = `" + html + @"` - }, - " + timeout + ");" + ExecuteScriptWithTimeout($""" + document.getElementsByTagName('body')[0].innerHTML = `{html}`; + """, timeout ); } public static void ExecuteScriptWithTimeout(string js, double timeout) { - Selene.ExecuteScript( - $"setTimeout(function () {{ {js} }}, {timeout})" - ); + ExecuteScriptWithTimeout(js, TimeSpan.FromMilliseconds(timeout)); } - - public static void ExecuteScriptWithTimeout(string js, double timeout, IWebDriver driver) + public static void ExecuteScriptWithTimeout(string js, TimeSpan timeout) { - (driver as IJavaScriptExecutor).ExecuteScript(@" - setTimeout( - function(){ - " + js + @" - }, - " + timeout + ");" + Selene.ExecuteScript( + $"setTimeout(function () {{ {js} }}, {timeout.TotalMilliseconds})" ); } } @@ -67,22 +33,14 @@ public static void ExecuteScriptWithTimeout(string js, double timeout, IWebDrive public class Given : When { - public static void OpenedEmptyPage(){ - Selene.Open( - new Uri( - new Uri(Assembly.GetExecutingAssembly().Location), - "../../../Resources/empty.html" - ).AbsoluteUri - ); + public static void OpenedEmptyPage() + { + Selene.Open(BaseTest.EmptyHtmlUri); } - public static void OpenedEmptyPage(IWebDriver driver){ - driver.Navigate().GoToUrl( - new Uri( - new Uri(Assembly.GetExecutingAssembly().Location), - "../../../Resources/empty.html" - ).AbsoluteUri - ); + public static void OpenedEmptyPage(IWebDriver driver) + { + driver.Navigate().GoToUrl(BaseTest.EmptyHtmlUri); } public static void OpenedPageWithBody(string html) @@ -91,17 +49,11 @@ public static void OpenedPageWithBody(string html) When.WithBody(html); } - public static void OpenedPageWithBodyTimedOut(string html, double timeout) + public static void OpenedPageWithBodyTimedOut(string html, TimeSpan timeout) { Given.OpenedEmptyPage(); When.WithBodyTimedOut(html, timeout); } - - public static void OpenedPageWithBody(string html, IWebDriver driver) - { - Given.OpenedEmptyPage(driver); - When.WithBody(html, driver); - } } } diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Attribute.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Attribute.cs index 7f23151..64f2d79 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Attribute.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Attribute.cs @@ -1,6 +1,3 @@ -using System.Linq; -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Count.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Count.cs index fe5c2bf..0af466b 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Count.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Count.cs @@ -1,6 +1,3 @@ -using System.Linq; -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/CssClass.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/CssClass.cs index c00cc5d..43a9421 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/CssClass.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/CssClass.cs @@ -1,6 +1,3 @@ -using System.Linq; -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Enabled.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Enabled.cs index fdf381c..bc31231 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Enabled.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Enabled.cs @@ -1,5 +1,3 @@ -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/InDom.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/InDom.cs index d5eb022..a6fe4a6 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/InDom.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/InDom.cs @@ -1,6 +1,3 @@ -using System; -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/JSReturnedTrue.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/JSReturnedTrue.cs index a93a895..5ab441a 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/JSReturnedTrue.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/JSReturnedTrue.cs @@ -1,10 +1,6 @@ -using System; -using NSelene.Conditions; -using OpenQA.Selenium; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { - namespace Conditions + namespace Conditions { public class JSReturnedTrue : DescribedCondition diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Selected.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Selected.cs index d36a063..b04e075 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Selected.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Selected.cs @@ -1,5 +1,3 @@ -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Text.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Text.cs index 3fa6c36..ede457b 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Text.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Text.cs @@ -1,6 +1,3 @@ -using System.Linq; -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Texts.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Texts.cs index 6912e45..9878c57 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Texts.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Texts.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Linq; -using NSelene.Conditions; namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Visible.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Visible.cs index 9001103..b5ba01a 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Visible.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/Conditions/Visible.cs @@ -1,5 +1,3 @@ -using NSelene.Conditions; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { namespace Conditions diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneBrowser_Should_Specs.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneBrowser_Should_Specs.cs index f8a254b..0e7eccb 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneBrowser_Should_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneBrowser_Should_Specs.cs @@ -1,165 +1,125 @@ -using NUnit.Framework; -using static NSelene.Selene; namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { - using System; - using System.Linq; - using System.Reflection; - using Harness; - using OpenQA.Selenium; - - [TestFixture] public class SeleneBrowser_Should_OldStyleConditions_Specs : BaseTest { - // TODO: imrove coverage and consider breaking down into separate test classes + // TODO: improve coverage and consider breaking down into separate test classes [Test] - public void SeleneWaitTo_HaveJsReturned_WaitsForPresenceInDom_OfInitiialyAbsent() + public void SeleneWaitTo_HaveJsReturned_WaitsForPresenceInDom_OfInitialyAbsent() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @"

a

b

", - 300 + ShortTimeoutSpan ); - Selene.WaitTo(Have.JSReturnedTrue( - @" - var expectedCount = arguments[0] - return document.getElementsByTagName('p').length == expectedCount - " - , - 2 - )); + var act = () => + { + Selene.WaitTo(Have.JSReturnedTrue( + @" + var expectedCount = arguments[0] + return document.getElementsByTagName('p').length == expectedCount + ", + 2 + )); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] - public void SeleneWaitTo_HaveNoJsReturned_WaitsForAbsenceInDom_OfInitiialyPresent() + public void SeleneWaitTo_HaveNoJsReturned_WaitsForAbsenceInDom_OfInitialyPresent() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @"

a

b

" ); - var beforeCall = DateTime.Now; + Selene.SS("p").Should(Have.Count(2)); Given.WithBodyTimedOut( @" ", - 300 + ShortTimeoutSpan ); - SS("p").Should(Have.No.Count(2)); - Selene.WaitTo(Have.No.JSReturnedTrue( - @" - var expectedCount = arguments[0] - return document.getElementsByTagName('p').length == expectedCount - " - , - 2 - )); + var act = () => + { + Selene.WaitTo(Have.No.JSReturnedTrue( + @" + var expectedCount = arguments[0] + return document.getElementsByTagName('p').length == expectedCount + ", + 2 + )); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); - Assert.AreEqual( - 0, - Configuration.Driver - .FindElements(By.TagName("p")).Count - ); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); + Assert.That(Configuration.Driver.FindElements(By.TagName("p")), Is.Empty); } - + [Test] public void SeleneWaitTo_HaveJsReturned_IsRenderedInError_OnAbsentElementTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; - try + var act = () => { Selene.WaitTo(Have.JSReturnedTrue( @" var expectedCount = arguments[0] return document.getElementsByTagName('p').length == expectedCount - " - , + ", 2 )); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - OpenQA.Selenium.Chrome.ChromeDriver.Should(JSReturnedTrue) - """.Trim() - )); - } + Assert.That(act, Does.Timeout($$""" + OpenQA.Selenium.Chrome.ChromeDriver.Should(JSReturnedTrue) + Reason: + actual: False + """)); } - + [Test] public void SeleneWaitTo_HaveNoJsReturned_IsRenderedInError_OnInDomElementsTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @"

a

b

" ); - var beforeCall = DateTime.Now; - try + var act = () => { Selene.WaitTo(Have.No.JSReturnedTrue( @" var expectedCount = arguments[0] return document.getElementsByTagName('p').length == expectedCount - " - , + ", 2 )); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - OpenQA.Selenium.Chrome.ChromeDriver.Should(Not.JSReturnedTrue) - """.Trim() - )); - - } + Assert.That(act, Does.Timeout($$""" + OpenQA.Selenium.Chrome.ChromeDriver.Should(Not.JSReturnedTrue) + Reason: + condition not matched + """)); } - // [Test] - // public void SeleneWaitTo_HaveNoJsReturned_WaitsForAsked_OfInitialyOtherResult() // NOT RELEVANT - // { - // } + [Test] + [Ignore("NOT RELEVANT")] + public void SeleneWaitTo_HaveNoJsReturned_WaitsForAsked_OfInitialyOtherResult() + { + } } } diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneCollection_Should_Specs.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneCollection_Should_Specs.cs index dccc8b1..303d4ac 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneCollection_Should_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneCollection_Should_Specs.cs @@ -1,170 +1,114 @@ -using NUnit.Framework; -using static NSelene.Selene; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { - using System; - using System.Linq; - using System.Reflection; - using Harness; - using OpenQA.Selenium; - [TestFixture] public class SeleneCollection_Should_OldStyleConditions_Specs : BaseTest { - // TODO: imrove coverage and consider breaking down into separate test classes + // TODO: improve coverage and consider breaking down into separate test classes [Test] - public void Should_HaveCount_WaitsForPresenceInDom_OfInitiialyAbsent() + public void Should_HaveCount_WaitsForPresenceInDom_OfInitialyAbsent() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @"

a

b

", - 300 + ShortTimeoutSpan ); - SS("p").Should(Have.Count(2)); - var afterCall = DateTime.Now; + var act = () => + { + SS("p").Should(Have.Count(2)); + }; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] - public void Should_HaveNoCount_WaitsForAbsenceInDom_OfInitiialyPresent() + public void Should_HaveNoCount_WaitsForAbsenceInDom_OfInitialyPresent() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @"

a

b

" ); - var beforeCall = DateTime.Now; Given.WithBodyTimedOut( @" ", - 300 + ShortTimeoutSpan ); - SS("p").Should(Have.No.Count(2)); + var act = () => + { + SS("p").Should(Have.No.Count(2)); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); - Assert.AreEqual( - 0, - Configuration.Driver - .FindElements(By.TagName("p")).Count - ); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] public void Should_HaveCount_IsRenderedInError_OnAbsentElementTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; - try - { + var act = () => { SS("p").Should(Have.Count(2)); - } - - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); + }; - // TODO: shoud we check timing here too? - var lines = error.Message.Split(Environment.NewLine).Select( - item => item.Trim() - ).ToList(); - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.All(p).Should(count = 2) + Assert.That(act, Does.Timeout($$""" + Browser.All(p).Should(count = 2) Reason: actual: count = 0 - """.Trim() - )); - } + """)); } [Test] public void Should_HaveNoCount_IsRenderedInError_OnInDomElementsTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @"

a

b

" ); - var beforeCall = DateTime.Now; - try - { + var act = () => { SS("p").Should(Have.No.Count(2)); - } - - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); + }; - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.All(p).Should(Not.count = 2) + Assert.That(act, Does.Timeout($$""" + Browser.All(p).Should(Not.count = 2) Reason: condition not matched - """.Trim() - )); - } + """)); } [Test] public void Should_HaveCount_WaitsForAsked_OfInitialyOtherVisibleCount() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @"

a

" ); - var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @"

a

b

- " - , - 300 + ", + ShortTimeoutSpan ); - SS("p").Should(Have.Count(2)); + var act = () => + { + SS("p").Should(Have.Count(2)); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); - Assert.AreEqual( - 2, - Configuration.Driver - .FindElements(By.TagName("p")).Count - ); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } } } diff --git a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneElement_Should_Specs.cs b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneElement_Should_Specs.cs index b911c4a..f68e78e 100644 --- a/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneElement_Should_Specs.cs +++ b/NSeleneTests/Integration/SharedDriver/OldConditionsSpecs/SeleneElement_Should_Specs.cs @@ -1,72 +1,58 @@ -using NUnit.Framework; -using static NSelene.Selene; - namespace NSelene.Tests.Integration.SharedDriver.OldConditionsSpecs { - using System; - using System.Linq; - using System.Reflection; - using Harness; - using OpenQA.Selenium; - [TestFixture] public class SeleneElement_Should_OldStyleConditions_Specs : BaseTest { - // TODO: imrove coverage and consider breaking down into separate test classes + // TODO: improve coverage and consider breaking down into separate test classes [Test] - public void Should_HaveValue_WaitsForPresenceInDom_OfInitiialyAbsent() + public void Should_HaveValue_WaitsForPresenceInDom_OfInitialyAbsent() { - Configuration.Timeout = 1.0; - Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @" ", - 300 - ); + ShortTimeoutSpan); - S("input").Should(Have.Value("initial")); - var afterCall = DateTime.Now; + var act = () => + { + S("input").Should(Have.Value("initial")); + }; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(1.0)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] - public void Should_HaveNoValue_WaitsForAbsenceInDom_OfInitiialyPresent() + public void Should_HaveNoValue_WaitsForAbsenceInDom_OfInitialyPresent() { - Configuration.Timeout = 1.0; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.WithBodyTimedOut( @" ", - 300 + ShortTimeoutSpan ); - S("input").Should(Have.No.Value("initial")); + var act = () => + { + S("input").Should(Have.No.Value("initial")); + }; + + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(1.0)); try { - Configuration.Driver - .FindElement(By.TagName("input")).GetAttribute("value"); + Configuration.Driver.FindElement(By.TagName("input")).GetAttribute("value"); Assert.Fail("should fail because the element should be already absent"); } catch (WebDriverException error) { - StringAssert.Contains( - "no such element: Unable to locate element: ", error.Message + Assert.That( + error.Message, Does.Contain("no such element: Unable to locate element: ") ); } } @@ -74,405 +60,303 @@ public void Should_HaveNoValue_WaitsForAbsenceInDom_OfInitiialyPresent() [Test] public void Should_HaveValue_IsRenderedInError_OnAbsentElementTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; - try - { + var act = () => { S("input").Should(Have.Value("initial")); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(input).Should(Have.Attribute(value='initial')) + Assert.That(act, Does.Timeout($$""" + Browser.Element(input).Should(Have.Attribute(value='initial')) Reason: no such element: Unable to locate element: {"method":"css selector","selector":"input"} - """.Trim() - )); - } + """)); } [Test] public void Should_HaveNoValue_IsRenderedInError_OnInDomElementTimeoutFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; - try - { + var act = () => { S("input").Should(Have.No.Value("initial")); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(input).Should(Not.Have.Attribute(value='initial')) + Assert.That(act, Does.Timeout($$""" + Browser.Element(input).Should(Not.Have.Attribute(value='initial')) Reason: condition not matched - """.Trim() - )); - } + """)); } [Test] public void Should_HaveText_WaitsForVisibility_OfInitialyHidden() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementsByTagName('label')[0].style.display = 'block'; ", - 300 + ShortTimeoutSpan.Milliseconds ); - S("label").Should(Have.Text("initial")); + var act = () => + { + S("label").Should(Have.Text("initial")); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); - Assert.AreEqual( - "initial", - Configuration.Driver - .FindElement(By.TagName("label")).Text + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, + Is.EqualTo("initial") ); } [Test] public void Should_HaveText_WaitsForAskedText_OfInitialyOtherText() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @" " , - 300 + ShortTimeoutSpan ); - S("label").Should(Have.Text("new")); + var act = () => + { + S("label").Should(Have.Text("new")); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); - Assert.AreEqual( - "new", - Configuration.Driver - .FindElement(By.TagName("label")).Text + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, + Is.EqualTo("new") ); - Assert.AreEqual( - "new", - Configuration.Driver - .FindElement(By.TagName("label")).Text + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, + Is.EqualTo("new") ); } [Test] public void Should_HaveText_IsRenderedInError_OnHiddenElementFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @" " ); - try - { + var act = () => { S("label").Should(Have.Text("initial")); - } - - catch (TimeoutException error) - { - var lines = error.Message.Split(Environment.NewLine).Select( - item => item.Trim() - ).ToList(); + }; - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(label).Should(Have.TextContaining(«initial»)) + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).Should(Have.TextContaining(«initial»)) Reason: Actual text: «» Actual webelement: - """.Trim() - )); - - Assert.AreEqual( - "", Configuration.Driver.FindElement(By.TagName("label")).Text + """)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, Is.EqualTo("") ); - } } [Test] - public void Should_BeVisible_WaitsForVisibility_OfInitiialyHiddenInDom() + public void Should_BeVisible_WaitsForVisibility_OfInitialyHiddenInDom() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementsByTagName('label')[0].style.display = 'block'; ", - 300 + ShortTimeoutSpan ); - S("label").Should(Be.Visible); + var act = () => + { + S("label").Should(Be.Visible); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] - public void Should_BeNotVisible_WaitsForHiddenInDom_FromInitiialyVisible() + public void Should_BeNotVisible_WaitsForHiddenInDom_FromInitialyVisible() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementsByTagName('label')[0].style.display = 'none'; ", - 300 - ); + ShortTimeoutSpan); - S("label").Should(Be.Not.Visible); + var act = () => + { + S("label").Should(Be.Not.Visible); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] - public void Should_BeVisible_WaitsForVisibility_OfInitiialyAbsentInDom() + public void Should_BeVisible_WaitsForVisibility_OfInitialyAbsentInDom() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; Given.WithBodyTimedOut( @" - " - , - 300 - ); + ", + ShortTimeoutSpan); - S("label").Should(Be.Visible); + var act = () => + { + S("label").Should(Be.Visible); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] public void Should_BeNotVisible_WaitsForAbsentInDom_FromInitiallyVisibile() { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; Given.WithBodyTimedOut( @" - " - , - 300 + ", + ShortTimeoutSpan ); - S("label").Should(Be.Not.Visible); + var act = () => + { + S("label").Should(Be.Not.Visible); + }; - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); + Assert.That(act, Does.PassAfter(ShortTimeoutSpan)); } [Test] public void Should_BeVisible_IsRenderedInError_OnHiddenInDomElementFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @" " ); - var beforeCall = DateTime.Now; - - try - { + + var act = () => { S("label").Should(Be.Visible); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(label).Should(Visible) + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).Should(Visible) Reason: actual: False - """.Trim() - )); - - Assert.AreEqual( - false, Configuration.Driver.FindElement(By.TagName("label")).Displayed - ); - } + """)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Displayed, Is.EqualTo(false) + ); } [Test] public void Should_BeNotVisible_IsRenderedInError_OnVisibleElementFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @" " ); - try - { + var act = () => { S("label").Should(Be.Not.Visible); - } + }; - catch (TimeoutException error) - { - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(label).Should(Not.Visible) + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).Should(Not.Visible) Reason: condition not matched - """.Trim() - )); - - Assert.AreEqual( - true, Configuration.Driver.FindElement(By.TagName("label")).Displayed - ); - } + """)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Displayed, Is.EqualTo(true) + ); } [Test] public void Should_BeVisible_IsRenderedInError_OnAbsentInDomElementFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedEmptyPage(); - var beforeCall = DateTime.Now; - try - { + var act = () => { S("label").Should(Be.Visible); - } + }; - catch (TimeoutException error) - { - var afterCall = DateTime.Now; - Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); - var accuracyDelta = 0.2; - Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); - - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(label).Should(Visible) + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).Should(Visible) Reason: no such element: Unable to locate element: {"method":"css selector","selector":"label"} - """.Trim() - )); - } + """)); } [Test] public void Should_HaveText_IsRenderedInError_OnElementDifferentTextFailure() { - Configuration.Timeout = 0.25; - Configuration.PollDuringWaits = 0.1; + Configuration.Timeout = BaseTest.ShortTimeout; Given.OpenedPageWithBody( @" " ); - try - { + var act = () => { S("label").Should(Have.Text("new")); - } + }; - catch (TimeoutException error) - { - Assert.That(error.Message.Trim(), Does.Contain($$""" - Timed out after {{0.25}}s, while waiting for: - Browser.Element(label).Should(Have.TextContaining(«new»)) + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).Should(Have.TextContaining(«new»)) Reason: Actual text: «initial» Actual webelement: - """.Trim() - )); - - Assert.AreEqual( - "initial", Configuration.Driver.FindElement(By.TagName("label")).Text - ); - } + """)); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, Is.EqualTo("initial") + ); } [Test] public void Should_HaveText_DoesNotWaitForNoOverlay() // TODO: but should it? { - Configuration.Timeout = 0.6; - Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @"
initial " ); - var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementById('overlay').style.display = 'none'; ", - 300 + ShortTimeoutSpan ); - S("label").Should(Have.Text("initial")); + var act = () => + { + S("label").Should(Have.Text("initial")); + }; - var afterCall = DateTime.Now; - Assert.Less(afterCall, beforeCall.AddSeconds(0.3)); - Assert.AreEqual( - "initial", - Configuration.Driver - .FindElement(By.TagName("label")).Text + Assert.That(act, Does.Pass()); + Assert.That( + Configuration.Driver.FindElement(By.TagName("label")).Text, + Is.EqualTo("initial") ); - // Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); - // Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); } - // [Test] - // public void Should_HaveText_IsRenderedInError_OnOverlappedWithOverlayFailure() // IS NOT RELEVANT - // { - // Configuration.Timeout = 0.25; - // Configuration.PollDuringWaits = 0.1; - // Given.OpenedPageWithBody( - // @" - //
- //
- - - // - // " - // ); - - // try - // { - // S("label").Should(Have.Text("initial")); - // } - - // catch (TimeoutException error) - // { - // var lines = error.Message.Split(Environment.NewLine).Select( - // item => item.Trim() - // ).ToList(); - - // Assert.Contains("Timed out after 0.25s, while waiting for:", lines); - // Assert.Contains("Browser.Element(label).contains initial", lines); - // Assert.Contains("Reason:", lines); - // Assert.NotNull(lines.Find(item => item.Contains( - // "Element is overlapped by:
+
+ + + + " + ); + + var act = () => + { + S("label").Should(Have.Text("initial")); + }; + + Assert.That(act, Does.Timeout($$""" + Browser.Element(label).contains initial + Reason: + Element is overlapped by: