Skip to content

Commit

Permalink
[#101] TEST: fix tests to pass on CI - try 3
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Sep 7, 2024
1 parent f08003e commit 747ae4f
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 118 deletions.
5 changes: 3 additions & 2 deletions NSelene/Conditions/Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;

namespace NSelene
Expand Down Expand Up @@ -28,8 +29,8 @@ public override void Invoke(SeleneElement entity)
{
throw new ConditionNotMatchedException(() =>
(maybeActual == null
? $"Actual {this.name}: Null (attribute is absent)\n"
: $"Actual {this.name}: «{maybeActual}»\n"
? $"Actual {this.name}: Null (attribute is absent){Environment.NewLine}"
: $"Actual {this.name}: «{maybeActual}»{Environment.NewLine}"
)
+ (
entity.Config.LogOuterHtmlOnFailure ?? false
Expand Down
7 changes: 4 additions & 3 deletions NSelene/Conditions/AttributeWithValueMatching.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using System;
using System.Text.RegularExpressions;

namespace NSelene
{
Expand Down Expand Up @@ -29,8 +30,8 @@ public override void Invoke(SeleneElement entity)
{
throw new ConditionNotMatchedException(() =>
(maybeActual == null
? $"Actual {this.name}: Null (attribute is absent)\n"
: $"Actual {this.name}: «{maybeActual}»\n"
? $"Actual {this.name}: Null (attribute is absent){Environment.NewLine}"
: $"Actual {this.name}: «{maybeActual}»{Environment.NewLine}"
)
+ (
entity.Config.LogOuterHtmlOnFailure ?? false
Expand Down
2 changes: 1 addition & 1 deletion NSelene/Conditions/BaseConditions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override void Invoke(TEntity entity)
}
// TODO: try fixing that following code will call webelement outerhtml rendering a few times, and log it with duplication in error message
throw new ConditionNotMatchedException(
() => string.Join("\n", errors.Select(its => its.Message))
() => string.Join(Environment.NewLine, errors.Select(its => its.Message))
);
}
}
Expand Down
10 changes: 8 additions & 2 deletions NSelene/Conditions/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public override void Invoke(SeleneElement entity)
if (!actual.Contains(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual text: «{actual}»\n"
$$"""
Actual text: «{{actual}}»
"""
+ (
entity.Config.LogOuterHtmlOnFailure ?? false
? $"Actual webelement: {webelement.GetAttribute("outerHTML")}"
Expand Down Expand Up @@ -57,7 +60,10 @@ public override void Invoke(SeleneElement entity)
if (!actual.Equals(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual text: «{actual}»\n"
$$"""
Actual text: «{{actual}}»
"""
+ (
entity.Config.LogOuterHtmlOnFailure ?? false
? $"Actual webelement: {webelement.GetAttribute("outerHTML")}"
Expand Down
7 changes: 5 additions & 2 deletions NSelene/Conditions/Title.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public override void Invoke(IWebDriver entity)
if (!actual.Equals(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual title: «{actual}»\n"
$$"""
Actual title: «{actual}»
"""
);
}
}
Expand All @@ -51,7 +54,7 @@ public override void Invoke(IWebDriver entity)
if (!actual.Contains(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual title: «{actual}»\n"
$"Actual title: «{actual}»{Environment.NewLine}"
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions NSelene/Conditions/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void Invoke(IWebDriver entity)
if (!actual.Equals(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual url: «{actual}»\n"
$"Actual url: «{actual}»{Environment.NewLine}"
);
}
}
Expand All @@ -51,7 +51,7 @@ public override void Invoke(IWebDriver entity)
if (!actual.Contains(this.expected))
{
throw new ConditionNotMatchedException(() =>
$"Actual url: «{actual}»\n"
$"Actual url: «{actual}»{Environment.NewLine}"
);
}
}
Expand Down
24 changes: 18 additions & 6 deletions NSelene/Selene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,13 @@ public static TResult WaitFor<TResult>(
}
if (!(DateTime.Now < otherDateTime))
{
string text = $"\nTimed out after {timeoutSpan.TotalSeconds} seconds " +
$"\nwhile waiting entity with locator: {entity} " +
$"\nfor condition: {condition}";
string text =
$$"""
Timed out after {{timeoutSpan.TotalSeconds}} seconds "
while waiting entity with locator: {{entity}} "
for condition: {{condition}}
""";
throw new WebDriverTimeoutException(text, lastException);
}
Thread.Sleep(TimeSpan.FromSeconds(pollDuringWaits).Milliseconds);
Expand Down Expand Up @@ -260,9 +264,17 @@ public static TResult WaitForNot<TResult>(
}
if (!(DateTime.Now < otherDateTime))
{
string text = string.Format( "\nTimed out after {0} seconds \nwhile waiting entity with locator: {1}\nfor condition: not "
, timeoutSpan.TotalSeconds, entity
);
string text = string.Format(
"""
Timed out after {0} seconds
while waiting entity with locator: {1}
for condition: not
"""
,
timeoutSpan.TotalSeconds,
entity
);
text = text + condition;
throw new WebDriverTimeoutException(text, lastException);
}
Expand Down
4 changes: 2 additions & 2 deletions NSelene/SeleneElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private IWebElement ActualVisibleWebElement {
"Element not visible" // TODO: should we render here also the current element locator? (will be redundant for S but might help in S.S, SS.S.S)
+ (
(this.Config.LogOuterHtmlOnFailure ?? false)
? $":\n{webElement.GetAttribute("outerHTML")}"
? $":{Environment.NewLine}{webElement.GetAttribute("outerHTML")}"
: ""
)
);
Expand Down Expand Up @@ -190,7 +190,7 @@ private IWebElement ActualNotOverlappedWebElement {
? $": {webElement.GetAttribute("outerHTML")}"
: ""
) // TODO: ... while not applied here?
+ $"\n is overlapped by: {cover.GetAttribute("outerHTML")}"
+ $"{Environment.NewLine} is overlapped by: {cover.GetAttribute("outerHTML")}"
);
}
return webElement;
Expand Down
34 changes: 18 additions & 16 deletions NSelene/SeleneLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ public override IWebElement Find ()
var maybeHtmlElements = this.context.Config.LogOuterHtmlOnFailure ?? false
? webelments.ToList().Select(element => element.GetAttribute("outerHTML")).ToArray()
: null;
throw new NotFoundException("element was not found in collection by condition "
+ condition
+ "\n Actual visible texts : " + "[" + string.Join(",", actualTexts) + "]" // TODO: think: this line is actually needed in the case of FindBy(ExactText ...) ... is there any way to add such information not here?
+ maybeHtmlElements != null
? "\n Actual html elements : " + "[" + string.Join(",", maybeHtmlElements) + "]"
: ""
// TODO: should we add here some other info about elements? e.g. visiblitiy?
);
throw new NotFoundException(
"element was not found in collection by condition "
+ condition
+ $"{Environment.NewLine} Actual visible texts : " + "[" + string.Join(",", actualTexts) + "]" // TODO: think: this line is actually needed in the case of FindBy(ExactText ...) ... is there any way to add such information not here?
+ maybeHtmlElements != null
? $"{Environment.NewLine} Actual html elements : " + "[" + string.Join(",", maybeHtmlElements) + "]"
: ""
// TODO: should we add here some other info about elements? e.g. visiblitiy?
);
/*
* TODO: think on better messages
*/
Expand Down Expand Up @@ -226,14 +227,15 @@ public override IWebElement Find ()
var maybeHtmlElements = this.context.Config.LogOuterHtmlOnFailure ?? false
? webelments.ToList().Select(element => element.GetAttribute("outerHTML")).ToArray()
: null;
throw new NotFoundException("element was not found in collection by condition "
+ condition
+ "\n Actual visible texts : " + "[" + string.Join(",", actualTexts) + "]" // TODO: think: this line is actually needed in the case of FindBy(ExactText ...) ... is there any way to add such information not here?
+ maybeHtmlElements != null
? "\n Actual html elements : " + "[" + string.Join(",", maybeHtmlElements) + "]"
: ""
// TODO: should we add here some other info about elements? e.g. visiblitiy?
);
throw new NotFoundException(
"element was not found in collection by condition "
+ condition
+ $"{Environment.NewLine} Actual visible texts : " + "[" + string.Join(",", actualTexts) + "]" // TODO: think: this line is actually needed in the case of FindBy(ExactText ...) ... is there any way to add such information not here?
+ maybeHtmlElements != null
? $"{Environment.NewLine} Actual html elements : " + "[" + string.Join(",", maybeHtmlElements) + "]"
: ""
// TODO: should we add here some other info about elements? e.g. visiblitiy?
);
/*
* TODO: think on better messages
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ 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("\n").Select(item => item.Trim()).ToList()
.Split(Environment.NewLine).Select(item => item.Trim()).ToList()
);
}

Expand Down Expand Up @@ -120,7 +120,7 @@ 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("\n").Select(item => item.Trim()).ToList()
.Split(Environment.NewLine).Select(item => item.Trim()).ToList()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,6 @@ public void SeleneWaitTo_HaveJsReturned_IsRenderedInError_OnAbsentElementTimeout
""".Trim()
));
}

// 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("\n").Select(
// item => item.Trim()
// ).ToList();

// Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
// Assert.Contains("Browser.All(p).count = 2", lines);
// Assert.Contains("Reason:", lines);
// Assert.Contains("actual: count = 0", lines);
// }
}

[Test]
Expand Down Expand Up @@ -172,24 +154,6 @@ public void SeleneWaitTo_HaveNoJsReturned_IsRenderedInError_OnInDomElementsTimeo
));

}

// 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("\n").Select(
// item => item.Trim()
// ).ToList();

// Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
// Assert.Contains("Browser.All(p).not count = 2", lines);
// Assert.Contains("Reason:", lines);
// Assert.Contains("actual: count = 2", lines);
// }
}

// [Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Should_HaveCount_IsRenderedInError_OnAbsentElementTimeoutFailure()
Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta));

// TODO: shoud we check timing here too?
var lines = error.Message.Split("\n").Select(
var lines = error.Message.Split(Environment.NewLine).Select(
item => item.Trim()
).ToList();
Assert.That(error.Message.Trim(), Does.Contain($$"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void Should_HaveText_IsRenderedInError_OnHiddenElementFailure()

catch (TimeoutException error)
{
var lines = error.Message.Split("\n").Select(
var lines = error.Message.Split(Environment.NewLine).Select(
item => item.Trim()
).ToList();

Expand Down Expand Up @@ -556,7 +556,7 @@ public void Should_HaveText_DoesNotWaitForNoOverlay() // TODO: but should it?

// catch (TimeoutException error)
// {
// var lines = error.Message.Split("\n").Select(
// var lines = error.Message.Split(Environment.NewLine).Select(
// item => item.Trim()
// ).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,6 @@ public void SeleneWaitTo_HaveJsReturned_IsRenderedInError_OnAbsentElementTimeout
""".Trim()
));
}

// 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("\n").Select(
// item => item.Trim()
// ).ToList();

// Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
// Assert.Contains("Browser.All(p).count = 2", lines);
// Assert.Contains("Reason:", lines);
// Assert.Contains("actual: count = 0", lines);
// }
}

[Test]
Expand Down Expand Up @@ -172,24 +154,6 @@ public void SeleneWaitTo_HaveNoJsReturned_IsRenderedInError_OnInDomElementsTimeo
""".Trim()
));
}

// 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("\n").Select(
// item => item.Trim()
// ).ToList();

// Assert.Contains("Timed out after 0.25s, while waiting for:", lines);
// Assert.Contains("Browser.All(p).not count = 2", lines);
// Assert.Contains("Reason:", lines);
// Assert.Contains("actual: count = 2", lines);
// }
}

// [Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Clear_IsRenderedInError_OnAbsentElementFailure()
catch (TimeoutException error)
{
// TODO: shoud we check timing here too?
var lines = error.Message.Split("\n").Select(
var lines = error.Message.Split(Environment.NewLine).Select(
item => item.Trim()
).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ element not interactable

// catch (TimeoutException error)
// {
// var lines = error.Message.Split("\n").Select(
// var lines = error.Message.Split(Environment.NewLine).Select(
// item => item.Trim()
// ).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public void Should_HaveText_DoesNotWaitForNoOverlay() // TODO: but should it?

// catch (TimeoutException error)
// {
// var lines = error.Message.Split("\n").Select(
// var lines = error.Message.Split(Environment.NewLine).Select(
// item => item.Trim()
// ).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void Submit_Fails_OnNonFormElement()

catch (TimeoutException error)
{
var lines = error.Message.Split("\n").Select(
var lines = error.Message.Split(Environment.NewLine).Select(
item => item.Trim()
).ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Type_FailsOnHiddenInputOfTypeFile()

catch (TimeoutException error)
{
var lines = error.Message.Split("\n").Select(
var lines = error.Message.Split(Environment.NewLine).Select(
item => item.Trim()
).ToList();

Expand Down

0 comments on commit 747ae4f

Please sign in to comment.