-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitTest1.cs
More file actions
163 lines (126 loc) · 7.13 KB
/
Copy pathUnitTest1.cs
File metadata and controls
163 lines (126 loc) · 7.13 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Microsoft.Playwright.NUnit;
using Microsoft.Playwright;
using NUnit.Framework;
using System.Threading.Tasks;
using System;
namespace PlaywrightPOC.PlaywrightTests
{
[TestFixture]
public class PlaywrightPoCTests : PageTest
{
/// <summary>
/// Test signing into as a user with Moodle being the provider
/// </summary>
/// <returns></returns>
[Test]
public async Task MoodleSignIn()
{
await Page.GotoAsync("https://automation.staging.panopto.com/Panopto/Pages/Home.aspx").ConfigureAwait(true);
await Page.Locator("#loginButton").ClickAsync().ConfigureAwait(true);
await Page.Locator("#providerDropdown").SelectOptionAsync("moodle41").ConfigureAwait(true);
await Page.Locator("#PageContentPlaceholder_loginControl_externalLoginButton").ClickAsync().ConfigureAwait(true);
await Page.Locator("#username").FillAsync("automation.studentSSO").ConfigureAwait(true);
await Page.Locator("#password").FillAsync("Panopto!123").ConfigureAwait(true);
await Page.Locator("#loginbtn").ClickAsync().ConfigureAwait(true);
await Page.Locator(".user-avatar").ClickAsync().ConfigureAwait(true);
await Assertions.Expect(Page.Locator("#UserMenuContent_currentUser")).ToHaveTextAsync("automation SSO").ConfigureAwait(true);
}
[Test] // Or [TestMethod] for MSTest / [Fact] for Xunit
public async Task MoodleQuizGradeTest()
{
await Page.GotoAsync("https://automation-lti13.staging.panopto.com/Panopto/Pages/Home.aspx").ConfigureAwait(true);
string referenceCopyQuizName = DateTime.Now.ToString("yyyyMMddHHmm") + "(copy)";
// Login as an instructor
await Page.Locator("#loginButton").ClickAsync().ConfigureAwait(true);
await Page.Locator("#providerDropdown").SelectOptionAsync("moodle41").ConfigureAwait(true);
await Page.Locator("#PageContentPlaceholder_loginControl_externalLoginButton").ClickAsync().ConfigureAwait(true);
await Page.Locator("#username").FillAsync("automation.teacherSSO").ConfigureAwait(true);
await Page.Locator("#password").FillAsync("Panopto!123").ConfigureAwait(true);
await Page.Locator("#loginbtn").ClickAsync().ConfigureAwait(true);
// Navigate to home page
await Page.Locator(".home").ClickAsync().ConfigureAwait(true);
// Search for quiz template video
/*
Driver.Wait().UntilClickable(d => SearchField);
SearchField.ClearSendKeys(query + Keys.Enter);
Driver.Wait().UntilPageLoad();
Driver.Wait().Until(d => d.ElementIsDisplayed(d2 => ResultsDiv)
|| d.ElementIsDisplayed(d2 => NoResultsMessage));
*/
await Page.Locator("#searchQuery").FillAsync("automation embed session quiz").ConfigureAwait(true);
}
[Test]
public async Task MoodleVerifyEmbedBasic()
{
await Page.GotoAsync("https://moodle41.d.panopto.com/login/index.php").ConfigureAwait(true);
await Page.Locator("#username").FillAsync("automation.embedUser1").ConfigureAwait(true);
await Page.Locator("#password").FillAsync("Panopto!123").ConfigureAwait(true);
await Page.Locator("#loginbtn").ClickAsync().ConfigureAwait(true);
await NavigateToCourse("AECS", "automation embed course staging").ConfigureAwait(true);
// delete leftover content function here
await Page.Locator("button:text-is('Turn editing on')").ClickAsync().ConfigureAwait(true);
var sectionLocator = Page.Locator("#section-0");
await sectionLocator.Locator(".activity-add-text").ClickAsync().ConfigureAwait(true);
await Page.Locator("#all-3 a[title = 'Add a new Assignment']").ClickAsync().ConfigureAwait(true);
await Page.Locator("#id_name").FillAsync("automation embed assignment").ConfigureAwait(true);
// Driver.Wait().UntilClickable(d => AddPanoptoVideoBtnAtto).Click();
var element1 = Page.Locator("#fitem_id_introeditor button[title = 'Panopto']"); // Replace with the actual selector for element1
var element2 = Page.Locator("#fitem_id_introeditor button[title='Add Panopto Video']"); // Replace with the actual selector for element2
if (await element1.IsVisibleAsync().ConfigureAwait(true))
{
await element1.ClickAsync().ConfigureAwait(true);
}
else
{
await element2.ClickAsync().ConfigureAwait(true);
}
string sessionName = "automation embed session";
// Select the correct session
// "pageframe"
var frameLocator1 = Page.FrameLocator("iframe[src*='tiny/plugins/panoptoltibutton']");
var frameLocator2 = frameLocator1.FrameLocator("#pageframe");
var frameLocator3 = frameLocator2.FrameLocator("#ltiSessionPicker");
await frameLocator3.Locator("#chooseTab").ClickAsync().ConfigureAwait(true);
await frameLocator3.Locator("#choosePane").ClickAsync().ConfigureAwait(true);
await frameLocator3.Locator("tr[data-name='" + sessionName + "']").ClickAsync().ConfigureAwait(true);
}
/*
* In the future, these helper functions should be placed in their own separate classes (for Moodle, for Panopto, etc.)
*/
public async Task NavigateToCourse(string courseName, string courseNameShort)
{
var link = Page.Locator("a:text-is('" + courseNameShort + "')");
var link2 = Page.Locator("a:text-is('" + courseName + "')");
if (await link.IsVisibleAsync().ConfigureAwait(true))
{
await link.ClickAsync().ConfigureAwait(true);
}
else if (await link2.IsVisibleAsync().ConfigureAwait(true))
{
await link2.ClickAsync().ConfigureAwait(true);
}
else
{
Assert.Fail("Course is either not visible or doesn't exist.");
}
}
public void SignInToMoodle(string username, string password)
{
}
public async Task NavigateToSignIn(IPage page, string moodleUrl, string instanceName)
{
await Page.GotoAsync(moodleUrl + "/login/index.php").ConfigureAwait(true);
// Wait for the page to load (Playwright generally handles this well)
// You can add more specific waits if needed (e.g., waiting for a specific element)
// Check if the notification asking to log out is present
var noticeElement = page.Locator("#notice");
if (await noticeElement.IsVisibleAsync().ConfigureAwait(true))
{
// Click the logout button
await page.Locator("button[type='submit'][class*='btn-primary']").ClickAsync().ConfigureAwait(true);
// Wait for the page to reload after clicking the logout button.
await page.WaitForLoadStateAsync().ConfigureAwait(true);
}
}
}
}