Created
April 7, 2022 05:24
-
-
Save s4my/14c0765475986ac5fbb9fb90dbd2bf4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {Builder, By} = require("selenium-webdriver"); | |
const firefox = require("selenium-webdriver/firefox"); | |
const path = require("path"); | |
const fs = require("fs"); | |
const manifest = require("../manifest.json"); | |
const addonId = manifest.browser_specific_settings.gecko.id; | |
async function getUUID(driver) { | |
const capabilities = await driver.getCapabilities(); | |
return new Promise((resolve, reject) => { | |
let numberOfAttempts = 0; | |
let interval = setInterval(async () => { | |
try { | |
const userPrefs = fs.readFileSync(path.join(capabilities.get("moz:profile"), | |
"/prefs.js"), "utf-8"); | |
let prefs = {}; | |
for (const pref of userPrefs.split(";")) { | |
if (pref.includes("extensions.webextensions.uuids")) { | |
for (const line of pref.substring(47, pref.length - 3).split(",")) { | |
const entry = line.replace(/"/g, "").replace(")", "") | |
.replace(/\\/g, "").split(":"); | |
prefs[entry[0]] = entry[1]; | |
} | |
if (prefs[addonId] === undefined || prefs[addonId] === "") { | |
throw ("can't seem to find the addon's UUID in the preferences."); | |
} | |
resolve(prefs[addonId]); | |
} | |
} | |
clearInterval(interval); | |
} catch(error) { | |
if (numberOfAttempts > 40) { | |
clearInterval(interval); | |
interval = null; | |
await driver.quit(); | |
reject(`Error: request timeout after 2000 ms, ${error}`); | |
} else { | |
numberOfAttempts++; | |
} | |
} | |
}, 50); | |
}); | |
} | |
test("test case where the user is not logged in.", async () => { | |
let options = new firefox.Options() | |
.setPreference("extensions.firebug.showChromeErrors", true); | |
let driver = await new Builder() | |
.forBrowser("firefox") | |
.setFirefoxOptions(options) | |
.build(); | |
await driver.installAddon("../build/twitch_live_channels-1.0.13.zip", | |
true); | |
const uuid = await getUUID(driver); | |
await driver.get(`moz-extension://${uuid}/popup.html`); | |
const nostreamDiv = await driver.findElement(By.id("nostream")); | |
expect(await nostreamDiv.isDisplayed()).toBe(true); | |
expect(await nostreamDiv.getText()) | |
.toBe("This extension requires your public Twitch account information.\n\n" + | |
"You need to Log In to give it authorization to get the list of channels you" + | |
" follow."); | |
const streamsDiv = await driver.findElement(By.id("streams")); | |
expect(await streamsDiv.getText()).toBe(""); | |
expect(await driver.executeAsyncScript(() => { | |
const callback = arguments[arguments.length - 1]; | |
(async () => { | |
await chrome.browserAction.getBadgeText({}, (badgeText) => { | |
callback(badgeText); | |
}); | |
})(); | |
})).toBe("0"); | |
await driver.quit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment