-
Notifications
You must be signed in to change notification settings - Fork 3
/
TestCaseUITestContextExtensions.cs
89 lines (74 loc) · 3.85 KB
/
TestCaseUITestContextExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Services;
using OpenQA.Selenium;
using Shouldly;
using System;
using System.Threading.Tasks;
namespace Lombiq.BaseTheme.Tests.UI.Extensions;
public static class TestCaseUITestContextExtensions
{
public static Task TestBaseThemeFeaturesAsync(this UITestContext context, bool skipLogin = false)
{
context.Get(By.Id("footer")).GetAttribute("class").Split().ShouldContain("text-center");
context.TestZoneInsertion();
return context.TestMainMenuWithAuthenticationAsync(skipLogin);
}
public static void TestZoneInsertion(this UITestContext context)
{
context.Get(By.ClassName("zoneInsertionExample_header"))
.Text
.Trim()
.ShouldBe("Here you can easily inject shapes into the zones, kind of like always enabled widgets.");
context.GetAllWhenOneExists(By.ClassName("zoneInsertionExample_footer"))
.Count
.ShouldBe(2);
}
public static async Task TestMainMenuWithAuthenticationAsync(this UITestContext context, bool skipLogin = false)
{
await context.ClickMainMenuPathAsync("Account", "Admin");
context.SwitchToLastWindow();
await context.DoWithRetriesOrFailAsync(() =>
Task.FromResult(new Uri(context.Driver.Url).AbsolutePath == "/Admin"));
context.SwitchToFirstWindow();
await context.ClickMainMenuPathAsync("Account", "Log Out");
if (skipLogin) return;
await context.ClickMainMenuPathAsync("Log In");
context.Exists(By.XPath("//form[@action = '/Login']/*[starts-with(name(), 'h') and contains(., 'Log in')]"));
}
public static async Task TestBaseThemeDependencyIsEnabledAsync(this UITestContext context)
{
await context.GoToAdminRelativeUrlAsync("/Features");
context.Exists(By.Id("btn-disable-Lombiq_HelpfulExtensions_Widgets"));
}
public static void TestBlogRecipeMenuItemsAddedToMainMenu(this UITestContext context)
{
context.Get(By.CssSelector(".menuWidget__content .nav-link[href='/']")).Text.Trim().ShouldBe("Home");
context.Get(By.CssSelector(".menuWidget__content .nav-link[href='/about']")).Text.Trim().ShouldBe("About");
}
public static async Task TestAddingMenuItemToBlogMainMenuAsync(this UITestContext context)
{
// The menu item has to be added through the admin by editing the menu like this because it can't be added
// through a recipe. The setup recipe in OSOCE executes the Blog recipe which already creates a menu with the
// "main-menu" alias. As it uses a random UUID for Content Item ID, it can't be updated from another recipe (if
// attempted the setup will throw "ValidationException: Your alias is already in use." exception).
await context.GoToAdminRelativeUrlAsync("/Contents/ContentItems/Menu");
await context.ClickReliablyOnAsync(By.ClassName("edit"));
await context.ClickReliablyOnAsync(By.XPath("//button[contains(., 'Add Menu Item')]"));
await context.ClickReliablyOnAsync(By.XPath(
"//div[contains(@class, 'card') and .//h4[contains(., 'Content Menu Item')]]//div[contains(@class, 'card-footer')]//a"));
await context.ClickAndFillInWithRetriesAsync(By.Id("ContentMenuItemPart_Name"), "My Content");
await context.SetContentPickerByDisplayTextAsync(
"ContentMenuItemPart",
"SelectedContentItem",
"Man must explore, and this is exploration at its greatest");
await context.ClickPublishAsync();
await context.ClickPublishAsync();
context.ShouldBeSuccess();
await context.GoToHomePageAsync();
context
.Get(By.XPath("id('navigation')//li[contains(@class, 'menuWidget__topLevel')]/a[@href='/blog/post-1']"))
.Text
.Trim()
.ShouldBe("My Content");
}
}