Skip to content

Commit

Permalink
[fix] open test addon popup properly
Browse files Browse the repository at this point in the history
  • Loading branch information
asciimoo committed Aug 13, 2024
1 parent 6aad755 commit 68127e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
16 changes: 0 additions & 16 deletions ext/src/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,6 @@ function checkStatus(res) {
}

function executeScriptToPromise(functionToExecute) {
// This is only for test purposes, see https://github.com/puppeteer/puppeteer/issues/2486
if(window.location.hash) {
return new Promise(resolve => {
browser.tabs.getCurrent(tab => {
chrome.tabs.query({ currentWindow: true, active: false }, tabs => {
const tabId = tabs[tabs.length-1].id;
browser.scripting.executeScript(tabId, {
code: `(${functionToExecute})()`
},
(data) => {
resolve(data);
});
});
});
});
}
//let [tab] = await chrome.tabs.query({ active: true, currentWindow: true }
return new Promise(resolve => {
browser.tabs.query({currentWindow: true, active: true}).then(tabs => {
Expand Down
21 changes: 14 additions & 7 deletions tests/e2e/extension/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,25 @@ async function login(browser) {
async function testPageSnapshot(browser) {
let page = await browser.newPage();
await page.goto(serverAddr+'static/test/index.html', {waitUntil: 'load'});
let addonPage = await browser.newPage();
await addonPage.goto(extBaseUrl+'popup.html#test', {waitUntil: 'load'});
await addonPage.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
const title = await addonPage.$("#title");
addonPage.evaluate((btnSelector) => {
const workerTarget = await browser.waitForTarget(
target => target.type() == "service_worker"
);
const worker = await workerTarget.worker();
await worker.evaluate("chrome.action.openPopup();");
const popup = await browser.waitForTarget(
(target) =>
target.type() === "page" &&
target.url() === extBaseUrl+'popup.html'
);
const addonPopup = await popup.asPage();
addonPopup.evaluate((btnSelector) => {
document.querySelector(btnSelector).click();
}, 'input[type="submit"]');
const status = await addonPage.waitForSelector("#status");
const status = await addonPopup.waitForSelector("#status");
const result = await status.evaluate(el => el.getAttribute('class'));
//await page.waitForTimeout(50*1000);
assert(result == 'success');
addonPage.close();
addonPopup.close();
const resp = await page.goto(serverAddr+testPageUrl, {waitUntil: 'load'});
assert(resp.status() == 200);
}
Expand Down

0 comments on commit 68127e3

Please sign in to comment.