Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monkey testing #109

Merged
merged 85 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
42b5db6
Add basic monkey testing functionality
YevgeniyShunevych Dec 3, 2021
82bd0f6
Merge branch 'dev' into monkey-testing
YevgeniyShunevych Dec 3, 2021
e2372d8
Merge branch 'dev' into monkey-testing
YevgeniyShunevych Dec 7, 2021
f929be9
Improve monkey testing functionality
YevgeniyShunevych Dec 9, 2021
909fdc1
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Dec 9, 2021
3b61ce0
Improve monkey testing functionality
YevgeniyShunevych Dec 10, 2021
ecfdcc5
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Dec 10, 2021
33e20f1
Improve monkey testing functionality
YevgeniyShunevych Dec 10, 2021
3124993
Improve monkey testing functionality
YevgeniyShunevych Dec 10, 2021
dfd3217
Improve monkey testing functionality
YevgeniyShunevych Dec 13, 2021
9b6a759
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
60e8926
Update Lombiq.Tests.UI/MonkeyTesting/IMonkeyTestingUrlFilter.cs
YevgeniyShunevych Dec 15, 2021
18c2e19
Update XML comments of `MonkeyTestingUITestContextExtensions`
YevgeniyShunevych Dec 15, 2021
1165e0f
Update Lombiq.Tests.UI.Samples/Tests/MonkeyTests.cs
YevgeniyShunevych Dec 15, 2021
8582e5e
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
d84f289
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
376438d
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
3b51789
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
942dd9c
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
d247556
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
751cb8a
Update Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
YevgeniyShunevych Dec 15, 2021
ae91b36
Refactor `MonkeyTester`
YevgeniyShunevych Dec 15, 2021
a05d1c7
Refactor `MonkeyTestingUITestContextExtensions` and update XML comments
YevgeniyShunevych Dec 15, 2021
f6ffcbe
Update XML comments
YevgeniyShunevych Dec 15, 2021
69540f2
Update MonkeyTestingUrlCleaners
YevgeniyShunevych Dec 15, 2021
8ca2174
Rename `MonkeyTestingUrlCleaner`s to `MonkeyTestingUrlSanitizer`s
YevgeniyShunevych Dec 15, 2021
d5a35c0
Remove try/catch blocks from `MonkeyTester.TestCurrentPageWithRandomS…
YevgeniyShunevych Dec 15, 2021
29e68ae
Add `Driver` null checks to `UITestExecutionSession.ExecuteAsync` and…
YevgeniyShunevych Dec 16, 2021
bacd50c
Update XML comments of `MonkeyTestingOptions.UrlSanitizers`
YevgeniyShunevych Dec 16, 2021
4fa66b7
Refactor MonkeyTestingUrlFilters
YevgeniyShunevych Dec 16, 2021
cb8c427
Refactor `MonkeyTester`
YevgeniyShunevych Dec 16, 2021
cb28aac
Use `NonSecurityRandomizer` in `MonkeyTester`
YevgeniyShunevych Dec 16, 2021
75aed31
Add monkey testing docs
YevgeniyShunevych Dec 16, 2021
d743bb5
Update monkey testing functionality
YevgeniyShunevych Dec 17, 2021
8093f28
Update `MonkeyTester`
YevgeniyShunevych Dec 17, 2021
7f50f3d
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Dec 17, 2021
151cb57
Docs
Piedone Dec 17, 2021
20e8cb0
Monkey test as an example to a restricted test
Piedone Dec 17, 2021
8aae2f0
Code styling
Piedone Dec 17, 2021
bbe2f6c
IMonkeyTestingUrlFilter implementation for simple relative URL Starts…
Piedone Dec 17, 2021
88819f6
Docs
Piedone Dec 17, 2021
c448d18
Code styling
Piedone Dec 17, 2021
997133e
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Dec 25, 2021
3ab73c2
Rename `Clean` method of `IMonkeyTestingUrlSanitizer` to `Sanitize`
YevgeniyShunevych Dec 28, 2021
a849b83
Update XML comment of `MonkeyTestingOptions.PageMarkerPollingInterval…
YevgeniyShunevych Dec 28, 2021
a8060f9
Merge remote-tracking branch 'origin/dev' into task/monkey-testing
Piedone Dec 29, 2021
9b0ee0d
Fixing new code analysis violations
Piedone Dec 29, 2021
c8674cf
Adding page change events to BasicOrchardFeaturesTests
Piedone Dec 29, 2021
cf6b7da
Adding page change events to GoToPage() methods
Piedone Dec 29, 2021
1fa27a7
Merge remote-tracking branch 'origin/dev' into task/monkey-testing
Piedone Dec 29, 2021
50fc297
Analyzer fixes
Piedone Dec 29, 2021
4788e23
Merge branch 'task/monkey-testing' into issue/OSOE-58
Piedone Dec 29, 2021
f6a7640
Better page change events
Piedone Dec 29, 2021
93f4fda
Moving form-related helpers from NavigationUITestContextExtensions to…
Piedone Dec 29, 2021
f9c0393
Fixing async issue with AtataContext
Piedone Dec 29, 2021
197091e
Adding the registration page as an Orchard page too
Piedone Dec 29, 2021
bf90917
Merge pull request #112 from Lombiq/issue/OSOE-58
Piedone Dec 29, 2021
ce938a6
Add async method versions to `MonkeyTestingUITestContextExtensions`
YevgeniyShunevych Jan 4, 2022
19a647d
Change and rename `TestContensAdminAsMonkeyRecursivelyShouldWorkWithA…
YevgeniyShunevych Jan 4, 2022
eb0bc04
Update monkey testing functionality to stop Gremlins script explicitly
YevgeniyShunevych Jan 5, 2022
4b5f63f
Update monkey testing functionality to embed gremlins.js npm package …
YevgeniyShunevych Jan 6, 2022
69836b7
Use `Lombiq.Npm.Targets` in `Lombiq.Tests.UI` project
YevgeniyShunevych Jan 11, 2022
d66aa61
Add docs for `MonkeyTestingOptions.GremlinsAttackDelay`
YevgeniyShunevych Jan 11, 2022
937346c
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Jan 11, 2022
8e1c804
Adding PNPM lock file too
Piedone Jan 12, 2022
09f4993
Docs
Piedone Jan 12, 2022
1a77b1b
Adding monkey tests for troubleshooting
Piedone Jan 12, 2022
edb3164
Fixing that accessibility and HTML validation reports weren't always …
Piedone Jan 12, 2022
b631306
Change `GremlinsScripts.StopGremlinsScript` to remove Gremlins visual…
YevgeniyShunevych Jan 18, 2022
cb61f42
Improve monkey testing functionality
YevgeniyShunevych Jan 22, 2022
d34f340
Merge branch 'dev' into task/monkey-testing
YevgeniyShunevych Jan 22, 2022
54d0737
Code styling
Piedone Jan 24, 2022
6d2c67a
Merge branch 'dev' into task/monkey-testing
Piedone Jan 24, 2022
15774ff
Adding link to monkey tests training section
Piedone Jan 24, 2022
3e587c4
Update monkey testing functionality
YevgeniyShunevych Jan 25, 2022
8970dbc
Merge remote-tracking branch 'origin/dev' into task/monkey-testing
Piedone Jan 25, 2022
e8b02d5
Code styling
Piedone Jan 25, 2022
e660f5b
Note on Gremlin logging
Piedone Jan 25, 2022
9a053c8
Merge branch 'dev' into task/monkey-testing
Piedone Jan 25, 2022
f356563
Fix `MonkeyTester.WaitForGremlinsIndicatorsToDisappear` method
YevgeniyShunevych Jan 26, 2022
7f3bf4c
Fix `MonkeyTester.TestCurrentPageWithRandomSeedAsync` method
YevgeniyShunevych Jan 26, 2022
d8a2b54
Fix `UITestExecutionSession` by unsubscribing from `_configuration.Ev…
YevgeniyShunevych Feb 2, 2022
cbc1b5c
Add temp `MonkeyTests.ShouldFailWith404`
YevgeniyShunevych Feb 2, 2022
3e674f1
Removing log assertion event handler even during UITestExecutionSessi…
Piedone Feb 2, 2022
40db630
Removing debug code
Piedone Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Lombiq.Tests.UI/MonkeyTesting/GremlinsScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ internal static class GremlinsScripts
internal const string StopGremlinsScript =
@"var horde = window.activeGremlinsHorde;
if (horde)
horde.stop();";
horde.stop();

var gremlinElements = document.querySelectorAll('div[style^=""z-index: 2000; border: 3px solid orange;""]');

for (let i = 0; i < gremlinElements.length; i++) {
var element = gremlinElements[i];
element.removeAttribute('style');
}";

internal const string GetLastGremlinsClickLogMessageScript = "return sessionStorage.getItem('lastgremlinsclick');";

private static readonly Lazy<string> _lazyGremlinsScript = new(
() => EmbeddedResourceProvider.ReadEmbeddedFile("gremlins.min.js"));
Expand All @@ -33,9 +42,22 @@ internal string Build()
string speciesPart = Species != null ? string.Join(", ", Species) : null;

string mogwaisPart = Mogwais != null ? string.Join(", ", Mogwais) : null;

return

@$"(function() {{
const customLogger = {{
log: function () {{
console.log.apply(null, arguments);
if (['click', 'dblclick', 'mouseup'].some(x => arguments[2] === x)) {{
Piedone marked this conversation as resolved.
Show resolved Hide resolved
var message = Array.prototype.slice.call(arguments, 2).join(' ');
sessionStorage.setItem('lastgremlinsclick', message);
}}
}},
info: console.info,
warn: console.warn,
error: console.error
}};

window.activeGremlinsHorde = gremlins.createHorde({{
species: [{speciesPart}],
mogwais: [{mogwaisPart}],
Expand All @@ -45,7 +67,8 @@ internal string Build()
delay: {AttackDelay.ToTechnicalString()}
}})
],
randomizer: new gremlins.Chance({RandomSeed.ToTechnicalString()})
randomizer: new gremlins.Chance({RandomSeed.ToTechnicalString()}),
logger: customLogger
}});

window.activeGremlinsHorde.unleash()
Expand Down
5 changes: 5 additions & 0 deletions Lombiq.Tests.UI/MonkeyTesting/MonkeyTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ private TimeSpan TestCurrentPageAndMeasureTestTimeLeft(TimeSpan testTime, int ra

_context.Driver.ExecuteScript(GremlinsScripts.StopGremlinsScript);

string lastGremlinsClickLogMessage = (string)_context.Driver.ExecuteScript(GremlinsScripts.GetLastGremlinsClickLogMessageScript);

if (!string.IsNullOrEmpty(lastGremlinsClickLogMessage))
Log.Info($"Last Gremlins click: {lastGremlinsClickLogMessage}.");

return testTimeLeft;
}

Expand Down
4 changes: 2 additions & 2 deletions Lombiq.Tests.UI/MonkeyTesting/MonkeyTestingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public sealed class MonkeyTestingOptions
/// <para>Gets the gremlins' species.</para>
/// <para>By default contains:</para>
/// <list type="number">
/// <item><description><c>"gremlins.species.clicker()"</c></description></item>
/// <item><description><c>"gremlins.species.clicker({ log: true })"</c></description></item>
/// <item><description><c>"gremlins.species.toucher()"</c></description></item>
/// <item><description><c>"gremlins.species.formFiller()"</c></description></item>
/// <item><description><c>"gremlins.species.scroller()"</c></description></item>
Expand All @@ -45,7 +45,7 @@ public sealed class MonkeyTestingOptions
/// </summary>
public List<string> GremlinsSpecies { get; } = new()
{
"gremlins.species.clicker()",
"gremlins.species.clicker({ log: true })",
"gremlins.species.toucher()",
"gremlins.species.formFiller()",
"gremlins.species.scroller()",
Expand Down
8 changes: 3 additions & 5 deletions Lombiq.Tests.UI/Services/UITestExecutionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,16 @@ private async ValueTask ShutdownAsync()

private async Task<List<BrowserLogMessage>> GetBrowserLogAsync(RemoteWebDriver driver)
{
if (_browserLogMessages != null) return _browserLogMessages;

var allMessages = new List<BrowserLogMessage>();
_browserLogMessages ??= new List<BrowserLogMessage>();

foreach (var windowHandle in _context.Driver.WindowHandles)
Piedone marked this conversation as resolved.
Show resolved Hide resolved
{
// Not using the logging SwitchTo() deliberately as this is not part of what the test does.
_context.Driver.SwitchTo().Window(windowHandle);
allMessages.AddRange(await driver.GetAndEmptyBrowserLogAsync());
_browserLogMessages.AddRange(await driver.GetAndEmptyBrowserLogAsync());
}

return _browserLogMessages = allMessages;
return _browserLogMessages;
}

private Exception PrepareAndLogException(Exception ex)
Expand Down