Skip to content

Commit

Permalink
Merge branch 'wjgerritsen-0001-refactor_timeout_testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Dec 8, 2024
2 parents 24ffe02 + 99a4303 commit 94f5944
Show file tree
Hide file tree
Showing 67 changed files with 1,933 additions and 3,080 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# IDE0039: Use local function
csharp_style_prefer_local_over_anonymous_function = false
22 changes: 15 additions & 7 deletions NSelene.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion NSelene/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private _Result<R> _For<R>(_Computation<T, R> computation) // TODO: should we ac

throw failure;
}
Thread.Sleep(TimeSpan.FromSeconds(this.polling).Milliseconds);
Thread.Sleep((int)TimeSpan.FromSeconds(this.polling).TotalMilliseconds);
}
}
// throw failFastError;
Expand Down
11 changes: 10 additions & 1 deletion NSeleneTests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -11,7 +6,7 @@ public class BrowserTest
IWebDriver driver;

[OneTimeSetUp]
public void initDriver()
public void InitDriver()
{
var options = new ChromeOptions();
options.AddArguments("headless");
Expand All @@ -21,10 +16,11 @@ public void initDriver()
}

[OneTimeTearDown]
public void disposeDriver()
public void DisposeDriver()
{
Configuration.BaseUrl = "";
this.driver.Quit();
this.driver.Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
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");
Configuration.Driver = new ChromeDriver(options);
}

[OneTimeTearDown]
public void disposeDriver()
public void DisposeDriver()
{
Configuration.Driver.Quit();
Configuration.Driver.Dispose();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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]
Expand All @@ -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));
}
}
}
Expand Down
72 changes: 35 additions & 37 deletions NSeleneTests/Integration/SharedDriver/Configuration_Specs.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace NSelene.Tests.Integration.SharedDriver.SeleneElementSpec
{

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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]
Expand All @@ -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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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)
);
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
);
}
}
Expand Down
Loading

0 comments on commit 94f5944

Please sign in to comment.