Allow screenshotter to be run on IE, Edge, Safari and remote, e.g., BrowserStack (#1661)

* Allow screenshotter on IE, Edge, and Safari

* Set Firefox options only on Firefox

* Add --selenium-capabilities option to support setting capabilities

* Quit web driver after test finishes

* Upgrade to style-loader 0.22.1 for IE compatability
This commit is contained in:
ylemkimon
2018-10-28 17:34:17 +09:00
committed by GitHub
parent 6a06470e99
commit 11490b5e0b

View File

@@ -30,7 +30,7 @@ const newDir = path.normalize(path.join("test", "screenshotter", "new"));
// Process command line arguments // Process command line arguments
const opts = require("commander") const opts = require("commander")
.option("-b, --browser <firefox|chrome>", .option("-b, --browser <firefox|chrome|ie|edge|safari>",
"Name of the browser to use", "firefox") "Name of the browser to use", "firefox")
.option("-c, --container <id>", .option("-c, --container <id>",
"Name or ID of a running docker container to contact") "Name or ID of a running docker container to contact")
@@ -38,6 +38,8 @@ const opts = require("commander")
.option("--selenium-ip <ip>", "IP address of the Selenium web driver") .option("--selenium-ip <ip>", "IP address of the Selenium web driver")
.option("--selenium-port <n>", .option("--selenium-port <n>",
"Port number of the Selenium web driver", 4444, parseInt) "Port number of the Selenium web driver", 4444, parseInt)
.option("--selenium-capabilities <JSON>",
"Desired capabilities of the Selenium web driver", JSON.parse)
.option("--katex-url <url>", "Full URL of the KaTeX development server") .option("--katex-url <url>", "Full URL of the KaTeX development server")
.option("--katex-ip <ip>", "IP address of the KaTeX development server") .option("--katex-ip <ip>", "IP address of the KaTeX development server")
.option("--katex-port <n>", .option("--katex-port <n>",
@@ -229,15 +231,20 @@ let driver;
let driverReady = false; let driverReady = false;
function buildDriver() { function buildDriver() {
const builder = new selenium.Builder().forBrowser(opts.browser); const builder = new selenium.Builder().forBrowser(opts.browser);
if (opts.browser === "firefox") {
const ffProfile = new firefox.Profile(); const ffProfile = new firefox.Profile();
ffProfile.setPreference( ffProfile.setPreference(
"browser.startup.homepage_override.mstone", "ignore"); "browser.startup.homepage_override.mstone", "ignore");
ffProfile.setPreference("browser.startup.page", 0); ffProfile.setPreference("browser.startup.page", 0);
const ffOptions = new firefox.Options().setProfile(ffProfile); const ffOptions = new firefox.Options().setProfile(ffProfile);
builder.setFirefoxOptions(ffOptions); builder.setFirefoxOptions(ffOptions);
}
if (seleniumURL) { if (seleniumURL) {
builder.usingServer(seleniumURL); builder.usingServer(seleniumURL);
} }
if (opts.seleniumCapabilities) {
builder.withCapabilities(opts.seleniumCapabilities);
}
driver = builder.build(); driver = builder.build();
driver.manage().timeouts().setScriptTimeout(3000).then(function() { driver.manage().timeouts().setScriptTimeout(3000).then(function() {
let html = '<!DOCTYPE html>' + let html = '<!DOCTYPE html>' +
@@ -519,15 +526,20 @@ function takeScreenshot(key) {
const reporter = istanbulApi.createReporter(); const reporter = istanbulApi.createReporter();
reporter.addAll(['json', 'text', 'lcov']); reporter.addAll(['json', 'text', 'lcov']);
reporter.write(coverageMap); reporter.write(coverageMap);
done();
process.exit(exitStatus);
}); });
return; return;
} }
// devServer.close(cb) will take too long. done();
process.exit(exitStatus);
} }
} }
function done() {
// devServer.close(cb) will take too long.
driver.quit().then(() => {
process.exit(exitStatus);
});
}
} }
// Wait using a timeout call in the browser, to ensure that the wait // Wait using a timeout call in the browser, to ensure that the wait