2019-05-20 15:22:50 +08:00
|
|
|
/*eslint no-console: "off"*/
|
|
|
|
|
2017-12-18 16:32:58 +08:00
|
|
|
const args = process.argv.slice(2);
|
|
|
|
|
|
|
|
if (args.length < 1 || args.length > 2) {
|
|
|
|
console.log("Expecting: node {smoke_test.js} {url}");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const url = args[0];
|
|
|
|
|
|
|
|
console.log(`Starting Discourse Smoke Test for ${url}`);
|
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
const puppeteer = require("puppeteer");
|
|
|
|
const path = require("path");
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
(async () => {
|
|
|
|
const browser = await puppeteer.launch({
|
2018-05-17 14:00:43 +08:00
|
|
|
// when debugging localy setting headless to "false" can be very helpful
|
2018-06-05 19:21:46 +08:00
|
|
|
headless: true,
|
2018-06-05 19:08:36 +08:00
|
|
|
args: ["--disable-local-storage", "--no-sandbox"]
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
2018-05-28 10:58:36 +08:00
|
|
|
await page.setViewport({
|
2017-12-18 16:32:58 +08:00
|
|
|
width: 1366,
|
|
|
|
height: 768
|
2018-05-28 10:58:36 +08:00
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
|
2018-05-28 14:19:12 +08:00
|
|
|
const takeFailureScreenshot = function() {
|
2018-09-11 09:16:03 +08:00
|
|
|
const screenshotPath = `${process.env.SMOKE_TEST_SCREENSHOT_PATH ||
|
2019-06-13 09:14:17 +08:00
|
|
|
"tmp/smoke-test-screenshots"}/smoke-test-${Date.now()}.png`;
|
2018-05-28 14:19:12 +08:00
|
|
|
console.log(`Screenshot of failure taken at ${screenshotPath}`);
|
|
|
|
return page.screenshot({ path: screenshotPath, fullPage: true });
|
|
|
|
};
|
|
|
|
|
2017-12-18 16:32:58 +08:00
|
|
|
const exec = (description, fn, assertion) => {
|
|
|
|
const start = +new Date();
|
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
return fn
|
|
|
|
.call()
|
|
|
|
.then(async output => {
|
|
|
|
if (assertion) {
|
|
|
|
if (assertion.call(this, output)) {
|
|
|
|
console.log(`PASSED: ${description} - ${+new Date() - start}ms`);
|
|
|
|
} else {
|
|
|
|
console.log(`FAILED: ${description} - ${+new Date() - start}ms`);
|
|
|
|
await takeFailureScreenshot();
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2017-12-18 16:32:58 +08:00
|
|
|
} else {
|
2018-09-11 09:16:03 +08:00
|
|
|
console.log(`PASSED: ${description} - ${+new Date() - start}ms`);
|
2017-12-18 16:32:58 +08:00
|
|
|
}
|
2018-09-11 09:16:03 +08:00
|
|
|
})
|
|
|
|
.catch(async error => {
|
|
|
|
console.log(
|
|
|
|
`ERROR (${description}): ${error.message} - ${+new Date() - start}ms`
|
|
|
|
);
|
|
|
|
await takeFailureScreenshot();
|
|
|
|
console.log("SMOKE TEST FAILED");
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const assert = (description, fn, assertion) => {
|
|
|
|
return exec(description, fn, assertion);
|
|
|
|
};
|
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
page.on("console", msg => console.log(`PAGE LOG: ${msg.text()}`));
|
2017-12-18 16:32:58 +08:00
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
page.on("response", resp => {
|
2019-06-14 11:30:06 +08:00
|
|
|
if (resp.status() !== 200 && resp.status() !== 302) {
|
2018-09-11 09:16:03 +08:00
|
|
|
console.log(
|
|
|
|
"FAILED HTTP REQUEST TO " + resp.url() + " Status is: " + resp.status()
|
|
|
|
);
|
2018-05-17 14:00:43 +08:00
|
|
|
}
|
|
|
|
return resp;
|
|
|
|
});
|
|
|
|
|
2018-01-03 14:24:06 +08:00
|
|
|
if (process.env.AUTH_USER && process.env.AUTH_PASSWORD) {
|
|
|
|
await exec("basic authentication", () => {
|
2018-01-04 21:30:04 +08:00
|
|
|
return page.setExtraHTTPHeaders({
|
2018-09-11 09:16:03 +08:00
|
|
|
Authorization: `Basic ${new Buffer(
|
|
|
|
`${process.env.AUTH_USER}:${process.env.AUTH_PASSWORD}`
|
|
|
|
).toString("base64")}`
|
2018-01-03 14:24:06 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-21 10:32:14 +08:00
|
|
|
await exec("go to site", () => {
|
|
|
|
return page.goto(url);
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
await exec("expect a log in button in the header", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("header .login-button", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go to latest page", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
return page.goto(path.join(url, "latest"));
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one topic shows up", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-list tbody tr", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go to categories page", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
return page.goto(path.join(url, "categories"));
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("can see categories on the page", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".category-list", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("navigate to 1st topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".main-link a.title:first-of-type");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("at least one post body", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-post", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("click on the 1st user", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".topic-meta-data a:first-of-type");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("user has details", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("#user-card .names", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!process.env.READONLY_TESTS) {
|
|
|
|
await exec("open login modal", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".login-button");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("login modal is open", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".login-modal", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("type in credentials & log in", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
let promise = page.type(
|
|
|
|
"#login-account-name",
|
|
|
|
process.env.DISCOURSE_USERNAME || "smoke_user"
|
|
|
|
);
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
promise = promise.then(() => {
|
2018-09-11 09:16:03 +08:00
|
|
|
return page.type(
|
|
|
|
"#login-account-password",
|
|
|
|
process.env.DISCOURSE_PASSWORD || "P4ssw0rd"
|
|
|
|
);
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".login-modal .btn-primary");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("is logged in", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".current-user", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("go home", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#site-logo, #site-text-logo");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("it shows a topic list", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".topic-list", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("we have a create topic button", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector("#create-topic", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open composer", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#create-topic");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("the editor is visible", () => {
|
|
|
|
return page.waitForFunction(
|
2017-12-20 21:41:49 +08:00
|
|
|
"document.activeElement === document.getElementById('reply-title')"
|
2017-12-18 16:32:58 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-05-09 14:02:45 +08:00
|
|
|
await page.evaluate(() => {
|
|
|
|
document.getElementById("reply-title").value = "";
|
|
|
|
});
|
|
|
|
|
2017-12-18 16:32:58 +08:00
|
|
|
await exec("compose new topic", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
const date = `(${+new Date()})`;
|
2017-12-18 16:32:58 +08:00
|
|
|
const title = `This is a new topic ${date}`;
|
|
|
|
const post = `I can write a new topic inside the smoke test! ${date} \n\n`;
|
|
|
|
|
|
|
|
let promise = page.type("#reply-title", title);
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("updates preview", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".d-editor-preview p", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open upload modal", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".d-editor-button-bar .upload");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("upload modal is open", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
let promise = page.waitForSelector("#filename-input", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
promise.then(() => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".d-modal-cancel");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
2019-05-22 01:01:29 +08:00
|
|
|
await page.waitFor(1000);
|
|
|
|
|
2017-12-18 16:32:58 +08:00
|
|
|
await exec("submit the topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".submit-panel .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("topic is created", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.waitForSelector(".fancy-title", { visible: true });
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("open the composer", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click(".post-controls:first-of-type .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("composer is open", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
return page.waitForSelector("#reply-control .d-editor-input", {
|
|
|
|
visible: true
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
await exec("compose reply", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
const post = `I can even write a reply inside the smoke test ;) (${+new Date()})`;
|
2017-12-18 16:32:58 +08:00
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
2018-06-05 16:58:15 +08:00
|
|
|
await exec("waiting for the preview", () => {
|
2018-09-11 09:16:03 +08:00
|
|
|
return page.waitForXPath(
|
|
|
|
"//div[contains(@class, 'd-editor-preview') and contains(.//p, 'I can even write a reply')]",
|
2017-12-20 21:41:49 +08:00
|
|
|
{ visible: true }
|
2017-12-18 16:32:58 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-05-22 01:01:29 +08:00
|
|
|
await page.waitFor(5000);
|
|
|
|
|
2017-12-18 16:32:58 +08:00
|
|
|
await exec("submit the topic", () => {
|
2017-12-20 21:41:49 +08:00
|
|
|
return page.click("#reply-control .create");
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
await assert(
|
|
|
|
"reply is created",
|
|
|
|
() => {
|
|
|
|
let promise = page.waitForSelector(".topic-post");
|
2017-12-18 16:32:58 +08:00
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.evaluate(() => {
|
|
|
|
return document.querySelectorAll(".topic-post").length;
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
});
|
|
|
|
|
2018-09-11 09:16:03 +08:00
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
output => {
|
|
|
|
return output === 2;
|
|
|
|
}
|
|
|
|
);
|
2019-05-21 17:44:30 +08:00
|
|
|
|
|
|
|
await page.waitFor(1000);
|
|
|
|
|
|
|
|
await exec("open composer to edit first post", () => {
|
|
|
|
return page.click(".post-controls:first-of-type .edit");
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("update post raw in composer", () => {
|
|
|
|
let promise = page.waitForSelector("#reply-control .d-editor-input", {
|
|
|
|
visible: true
|
|
|
|
});
|
|
|
|
|
2019-06-14 12:21:13 +08:00
|
|
|
promise = promise.then(() => page.waitFor(5000));
|
2019-05-21 17:44:30 +08:00
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
const post = `I edited this post`;
|
|
|
|
return page.type("#reply-control .d-editor-input", post);
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
});
|
|
|
|
|
|
|
|
await exec("submit the edit", () => {
|
|
|
|
return page.click("#reply-control .create");
|
|
|
|
});
|
|
|
|
|
|
|
|
await assert(
|
|
|
|
"reply is created",
|
|
|
|
() => {
|
|
|
|
let promise = page.waitForSelector("#reply-control.closed", {
|
|
|
|
visible: false
|
|
|
|
});
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.waitForSelector("#post_1", { visible: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
promise = promise.then(() => {
|
|
|
|
return page.evaluate(() => {
|
|
|
|
return document.querySelector("#post_1 .cooked").textContent;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
output => {
|
|
|
|
return output.includes(`I edited this post`);
|
|
|
|
}
|
|
|
|
);
|
2017-12-18 16:32:58 +08:00
|
|
|
}
|
|
|
|
|
2017-12-23 09:29:22 +08:00
|
|
|
await exec("close browser", () => {
|
|
|
|
return browser.close();
|
|
|
|
});
|
2017-12-18 16:32:58 +08:00
|
|
|
|
|
|
|
console.log("ALL PASSED");
|
|
|
|
})();
|