diff options
author | Ajay Ramachandran <[email protected]> | 2021-07-30 15:04:05 -0400 |
---|---|---|
committer | Ajay Ramachandran <[email protected]> | 2021-07-30 15:04:05 -0400 |
commit | d93e9a7d8a62dfa6b6a9bc2c1f19e0401dae0e33 (patch) | |
tree | f381accbdcd02d7727fa745aef715f90dc122aec /test | |
parent | 2a3a04a504029be0f544d4c4523c4dd6e37ad2b1 (diff) | |
download | SponsorBlock-d93e9a7d8a62dfa6b6a9bc2c1f19e0401dae0e33.tar.gz SponsorBlock-d93e9a7d8a62dfa6b6a9bc2c1f19e0401dae0e33.zip |
Add basic selenium test
Diffstat (limited to 'test')
-rw-r--r-- | test/selenium.test.ts | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/selenium.test.ts b/test/selenium.test.ts new file mode 100644 index 00000000..4cd292dd --- /dev/null +++ b/test/selenium.test.ts @@ -0,0 +1,44 @@ +import { Builder, By, until, Key } from "selenium-webdriver"; +import * as Chrome from "selenium-webdriver/chrome"; +import * as Path from "path"; + +test("Selenium Chrome test", async () => { + const options = new Chrome.Options(); + options.addArguments("--load-extension=" + Path.join(__dirname, "../dist/")); + options.addArguments("--mute-audio"); + options.addArguments("--disable-features=PreloadMediaEngagementData, MediaEngagementBypassAutoplayPolicies") + + const driver = await new Builder().forBrowser("chrome").setChromeOptions(options).build(); + driver.manage().setTimeouts({ + implicit: 5000 + }); + + try { + // Selenium only knows about the one tab it's on, + // so we can't wait for the help page to appear + await driver.sleep(3000); + // This video has no ads + await driver.get("https://www.youtube.com/watch?v=jNQXAC9IVRw"); + await driver.wait(until.elementIsVisible(await driver.findElement(By.className("ytd-video-primary-info-renderer")))); + + const startSegmentButton = await driver.findElement(By.id("startSegmentButton")); + const cancelSegmentButton = await driver.findElement(By.id("cancelSegmentButton")); + await driver.executeScript("document.querySelector('video').currentTime = 0"); + + await startSegmentButton.click(); + await driver.wait(until.elementIsVisible(cancelSegmentButton)); + + await driver.executeScript("document.querySelector('video').currentTime = 10.33"); + + await startSegmentButton.click(); + await driver.wait(until.elementIsNotVisible(cancelSegmentButton)); + + const submitButton = await driver.findElement(By.id("submitButton")); + await submitButton.click(); + + const sponsorTimeDisplay = await driver.findElement(By.className("sponsorTimeDisplay")); + await driver.wait(until.elementTextIs(sponsorTimeDisplay, "0:00.000 to 0:10.330")); + } finally { + await driver.quit(); + } +}, 100_000);
\ No newline at end of file |