aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/selenium.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/selenium.test.ts')
-rw-r--r--test/selenium.test.ts87
1 files changed, 75 insertions, 12 deletions
diff --git a/test/selenium.test.ts b/test/selenium.test.ts
index 0e334f62..600408a9 100644
--- a/test/selenium.test.ts
+++ b/test/selenium.test.ts
@@ -1,9 +1,11 @@
-import { Builder, By, until, WebDriver } from "selenium-webdriver";
+import { Builder, By, until, WebDriver, WebElement } from "selenium-webdriver";
import * as Chrome from "selenium-webdriver/chrome";
import * as Path from "path";
+import * as fs from "fs";
+
test("Selenium Chrome test", async () => {
- let driver;
+ let driver: WebDriver;
try {
driver = await setup();
} catch (e) {
@@ -27,6 +29,22 @@ test("Selenium Chrome test", async () => {
await setSegmentActionType(driver, 0, 1, false);
await editSegments(driver, 0, "0:05.000", "0:13.211", "5", "7.5", "0:05.000 to 0:07.500", false);
await muteSkipSegment(driver, 5, 7.5);
+
+ // Full video
+ await setSegmentActionType(driver, 0, 2, false);
+ await driver.wait(until.elementIsNotVisible(await getDisplayTimeBox(driver, 0)));
+
+ await toggleWhitelist(driver);
+ await toggleWhitelist(driver);
+
+ } catch (e) {
+ // Save file incase there is a layout change
+ const source = await driver.getPageSource();
+
+ fs.mkdirSync("./test-results");
+ fs.writeFileSync("./test-results/source.html", source);
+
+ throw e;
} finally {
await driver.quit();
}
@@ -37,6 +55,8 @@ async function setup(): Promise<WebDriver> {
options.addArguments("--load-extension=" + Path.join(__dirname, "../dist/"));
options.addArguments("--mute-audio");
options.addArguments("--disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies");
+ options.addArguments("--headless=chrome");
+ options.addArguments("--window-size=1920,1080");
const driver = await new Builder().forBrowser("chrome").setChromeOptions(options).build();
driver.manage().setTimeouts({
@@ -57,7 +77,7 @@ async function waitForInstall(driver: WebDriver, startingTab = 0): Promise<void>
async function goToVideo(driver: WebDriver, videoId: string): Promise<void> {
await driver.get("https://www.youtube.com/watch?v=" + videoId);
- await driver.wait(until.elementIsVisible(await driver.findElement(By.className("ytd-video-primary-info-renderer"))));
+ await driver.wait(until.elementIsVisible(await driver.findElement(By.css(".ytd-video-primary-info-renderer, #above-the-fold"))));
}
async function createSegment(driver: WebDriver, startTime: string, endTime: string, expectedDisplayedTime: string): Promise<void> {
@@ -90,8 +110,7 @@ async function editSegments(driver: WebDriver, index: number, expectedStartTimeB
}
let editButton = await driver.findElement(By.id("sponsorTimeEditButtonSubmissionNotice" + index));
- let sponsorTimeDisplays = await driver.findElements(By.className("sponsorTimeDisplay"));
- let sponsorTimeDisplay = sponsorTimeDisplays[index];
+ const sponsorTimeDisplay = await getDisplayTimeBox(driver, index);
await sponsorTimeDisplay.click();
// Ensure edit time appears
await driver.findElement(By.id("submittingTime0SubmissionNotice" + index));
@@ -100,22 +119,39 @@ async function editSegments(driver: WebDriver, index: number, expectedStartTimeB
await editButton.click();
await editButton.click();
- const startTimeBox = await driver.findElement(By.id("submittingTime0SubmissionNotice" + index));
- expect((await startTimeBox.getAttribute("value"))).toBe(expectedStartTimeBox);
+ const startTimeBox = await getStartTimeBox(driver, index, expectedStartTimeBox);
await startTimeBox.clear();
await startTimeBox.sendKeys(startTime);
- const endTimeBox = await driver.findElement(By.id("submittingTime1SubmissionNotice" + index));
- expect((await endTimeBox.getAttribute("value"))).toBe(expectedEndTimeBox);
+ const endTimeBox = await getEndTimeBox(driver, index, expectedEndTimeBox);
await endTimeBox.clear();
await endTimeBox.sendKeys(endTime);
editButton = await driver.findElement(By.id("sponsorTimeEditButtonSubmissionNotice" + index));
await editButton.click();
- sponsorTimeDisplays = await driver.findElements(By.className("sponsorTimeDisplay"));
- sponsorTimeDisplay = sponsorTimeDisplays[index];
- await driver.wait(until.elementTextIs(sponsorTimeDisplay, expectedDisplayedTime));
+ await getDisplayTimeBox(driver, index, expectedDisplayedTime);
+}
+
+async function getStartTimeBox(driver: WebDriver, index: number, expectedStartTimeBox: string): Promise<WebElement> {
+ const startTimeBox = await driver.findElement(By.id("submittingTime0SubmissionNotice" + index));
+ expect((await startTimeBox.getAttribute("value"))).toBe(expectedStartTimeBox);
+ return startTimeBox;
+}
+
+async function getEndTimeBox(driver: WebDriver, index: number, expectedEndTimeBox: string): Promise<WebElement> {
+ const endTimeBox = await driver.findElement(By.id("submittingTime1SubmissionNotice" + index));
+ expect((await endTimeBox.getAttribute("value"))).toBe(expectedEndTimeBox);
+ return endTimeBox;
+}
+
+async function getDisplayTimeBox(driver: WebDriver, index: number, expectedDisplayedTime?: string): Promise<WebElement> {
+ const sponsorTimeDisplay = (await driver.findElements(By.className("sponsorTimeDisplay")))[index];
+ if (expectedDisplayedTime) {
+ driver.wait(until.elementTextIs(sponsorTimeDisplay, expectedDisplayedTime));
+ }
+
+ return sponsorTimeDisplay;
}
async function setSegmentCategory(driver: WebDriver, index: number, categoryIndex: number, openSubmitBox: boolean): Promise<void> {
@@ -162,4 +198,31 @@ async function muteSkipSegment(driver: WebDriver, startTime: number, endTime: nu
await driver.sleep(duration * 1000 + 300);
expect(await video.getAttribute("muted")).toBeNull(); // Default is null for some reason
await driver.executeScript("document.querySelector('video').pause()");
+}
+
+async function toggleWhitelist(driver: WebDriver): Promise<void> {
+ const popupButton = await driver.findElement(By.id("infoButton"));
+ if ((await popupButton.getCssValue("display")) !== "none") {
+ await driver.actions().move({ origin: popupButton }).perform();
+ await popupButton.click();
+ }
+
+ const popupFrame = await driver.findElement(By.css("#sponsorBlockPopupContainer iframe"));
+ await driver.switchTo().frame(popupFrame);
+
+ const whitelistButton = await driver.findElement(By.id("whitelistButton"));
+ await driver.wait(until.elementIsVisible(whitelistButton));
+
+ const whitelistText = await driver.findElement(By.id("whitelistChannel"));
+ const whitelistDisplayed = await whitelistText.isDisplayed();
+
+ await whitelistButton.click();
+ if (whitelistDisplayed) {
+ const unwhitelistText = await driver.findElement(By.id("unwhitelistChannel"));
+ await driver.wait(until.elementIsVisible(unwhitelistText));
+ } else {
+ await driver.wait(until.elementIsVisible(whitelistText));
+ }
+
+ await driver.switchTo().defaultContent();
} \ No newline at end of file