Run testcafe headless when passing custom args to Chrome binary via testcafe-browser-tools
Running testcafe inside a Vagrant VM, which is mostly working.
However, Chrome doesn't start properly in this environment with hardware acceleration enabled, so I have to start it with the command line flag --disable-gpu
.
I'm leveraging the 'testcafe-browser-tools' package to accomplish this, by overriding the default browser command via the Runner class in the TestCafe API.
This all works fine for the case of running TestCafe with it opening a browser window, but I've not been able to figure out how to use this same setup to run tests in headless mode. I tried simply adding the --headless
arg when modifying the browser command, but it just hangs and the tests never start.
The testcafe CLI command has a switch for headless mode, like testcafe "chrome:headless" test.js
, and digging through the code that seems to set some internal config variable that does the magic stuff, but I've been unable to figure out how to get that same behavior when customizing the browser command via the API.
For reference, here's the script I wrote up to handle starting my tests:
const format = require('util').format;
const programName = process.argv[1];
const usage = () => {
console.log("Configures Chrome and runs all passed tests.nn");
console.log(format('Usage: %s [--headless] <file_pattern_1> [file_pattern_N]', programName));
}
const args = process.argv.slice(2);
const testFilePatterns = ;
let headless = '';
for (let filePattern of args) {
if (filePattern == '--headless') {
console.log('Headless mode enabled');
headless = '--headless';
}
else {
console.log(format('Adding file pattern %s for testing', filePattern));
testFilePatterns.push(filePattern);
}
}
if (testFilePatterns.length < 1) {
usage();
process.exit(1);
}
const testcafeBrowserTools = require('testcafe-browser-tools');
const createTestCafe = require('testcafe');
(async () => {
const info = await testcafeBrowserTools.getBrowserInfo('/usr/bin/chromium');
info.cmd = `${info.cmd} ${headless} --no-sandbox --disable-gpl`;
console.log(format('Running chrome with command: %s', info.cmd));
const testcafe = await createTestCafe();
const failedCount = await testcafe
.createRunner()
.src(testFilePatterns)
.browsers(info)
.run();
testcafe.close();
})();
Is there some modification to that script that would solve my issue, or another approach that is needed?
automated-tests vagrant e2e-testing google-chrome-headless testcafe
add a comment |
Running testcafe inside a Vagrant VM, which is mostly working.
However, Chrome doesn't start properly in this environment with hardware acceleration enabled, so I have to start it with the command line flag --disable-gpu
.
I'm leveraging the 'testcafe-browser-tools' package to accomplish this, by overriding the default browser command via the Runner class in the TestCafe API.
This all works fine for the case of running TestCafe with it opening a browser window, but I've not been able to figure out how to use this same setup to run tests in headless mode. I tried simply adding the --headless
arg when modifying the browser command, but it just hangs and the tests never start.
The testcafe CLI command has a switch for headless mode, like testcafe "chrome:headless" test.js
, and digging through the code that seems to set some internal config variable that does the magic stuff, but I've been unable to figure out how to get that same behavior when customizing the browser command via the API.
For reference, here's the script I wrote up to handle starting my tests:
const format = require('util').format;
const programName = process.argv[1];
const usage = () => {
console.log("Configures Chrome and runs all passed tests.nn");
console.log(format('Usage: %s [--headless] <file_pattern_1> [file_pattern_N]', programName));
}
const args = process.argv.slice(2);
const testFilePatterns = ;
let headless = '';
for (let filePattern of args) {
if (filePattern == '--headless') {
console.log('Headless mode enabled');
headless = '--headless';
}
else {
console.log(format('Adding file pattern %s for testing', filePattern));
testFilePatterns.push(filePattern);
}
}
if (testFilePatterns.length < 1) {
usage();
process.exit(1);
}
const testcafeBrowserTools = require('testcafe-browser-tools');
const createTestCafe = require('testcafe');
(async () => {
const info = await testcafeBrowserTools.getBrowserInfo('/usr/bin/chromium');
info.cmd = `${info.cmd} ${headless} --no-sandbox --disable-gpl`;
console.log(format('Running chrome with command: %s', info.cmd));
const testcafe = await createTestCafe();
const failedCount = await testcafe
.createRunner()
.src(testFilePatterns)
.browsers(info)
.run();
testcafe.close();
})();
Is there some modification to that script that would solve my issue, or another approach that is needed?
automated-tests vagrant e2e-testing google-chrome-headless testcafe
add a comment |
Running testcafe inside a Vagrant VM, which is mostly working.
However, Chrome doesn't start properly in this environment with hardware acceleration enabled, so I have to start it with the command line flag --disable-gpu
.
I'm leveraging the 'testcafe-browser-tools' package to accomplish this, by overriding the default browser command via the Runner class in the TestCafe API.
This all works fine for the case of running TestCafe with it opening a browser window, but I've not been able to figure out how to use this same setup to run tests in headless mode. I tried simply adding the --headless
arg when modifying the browser command, but it just hangs and the tests never start.
The testcafe CLI command has a switch for headless mode, like testcafe "chrome:headless" test.js
, and digging through the code that seems to set some internal config variable that does the magic stuff, but I've been unable to figure out how to get that same behavior when customizing the browser command via the API.
For reference, here's the script I wrote up to handle starting my tests:
const format = require('util').format;
const programName = process.argv[1];
const usage = () => {
console.log("Configures Chrome and runs all passed tests.nn");
console.log(format('Usage: %s [--headless] <file_pattern_1> [file_pattern_N]', programName));
}
const args = process.argv.slice(2);
const testFilePatterns = ;
let headless = '';
for (let filePattern of args) {
if (filePattern == '--headless') {
console.log('Headless mode enabled');
headless = '--headless';
}
else {
console.log(format('Adding file pattern %s for testing', filePattern));
testFilePatterns.push(filePattern);
}
}
if (testFilePatterns.length < 1) {
usage();
process.exit(1);
}
const testcafeBrowserTools = require('testcafe-browser-tools');
const createTestCafe = require('testcafe');
(async () => {
const info = await testcafeBrowserTools.getBrowserInfo('/usr/bin/chromium');
info.cmd = `${info.cmd} ${headless} --no-sandbox --disable-gpl`;
console.log(format('Running chrome with command: %s', info.cmd));
const testcafe = await createTestCafe();
const failedCount = await testcafe
.createRunner()
.src(testFilePatterns)
.browsers(info)
.run();
testcafe.close();
})();
Is there some modification to that script that would solve my issue, or another approach that is needed?
automated-tests vagrant e2e-testing google-chrome-headless testcafe
Running testcafe inside a Vagrant VM, which is mostly working.
However, Chrome doesn't start properly in this environment with hardware acceleration enabled, so I have to start it with the command line flag --disable-gpu
.
I'm leveraging the 'testcafe-browser-tools' package to accomplish this, by overriding the default browser command via the Runner class in the TestCafe API.
This all works fine for the case of running TestCafe with it opening a browser window, but I've not been able to figure out how to use this same setup to run tests in headless mode. I tried simply adding the --headless
arg when modifying the browser command, but it just hangs and the tests never start.
The testcafe CLI command has a switch for headless mode, like testcafe "chrome:headless" test.js
, and digging through the code that seems to set some internal config variable that does the magic stuff, but I've been unable to figure out how to get that same behavior when customizing the browser command via the API.
For reference, here's the script I wrote up to handle starting my tests:
const format = require('util').format;
const programName = process.argv[1];
const usage = () => {
console.log("Configures Chrome and runs all passed tests.nn");
console.log(format('Usage: %s [--headless] <file_pattern_1> [file_pattern_N]', programName));
}
const args = process.argv.slice(2);
const testFilePatterns = ;
let headless = '';
for (let filePattern of args) {
if (filePattern == '--headless') {
console.log('Headless mode enabled');
headless = '--headless';
}
else {
console.log(format('Adding file pattern %s for testing', filePattern));
testFilePatterns.push(filePattern);
}
}
if (testFilePatterns.length < 1) {
usage();
process.exit(1);
}
const testcafeBrowserTools = require('testcafe-browser-tools');
const createTestCafe = require('testcafe');
(async () => {
const info = await testcafeBrowserTools.getBrowserInfo('/usr/bin/chromium');
info.cmd = `${info.cmd} ${headless} --no-sandbox --disable-gpl`;
console.log(format('Running chrome with command: %s', info.cmd));
const testcafe = await createTestCafe();
const failedCount = await testcafe
.createRunner()
.src(testFilePatterns)
.browsers(info)
.run();
testcafe.close();
})();
Is there some modification to that script that would solve my issue, or another approach that is needed?
automated-tests vagrant e2e-testing google-chrome-headless testcafe
automated-tests vagrant e2e-testing google-chrome-headless testcafe
edited Nov 21 '18 at 12:24
Alex Skorkin
2,16221634
2,16221634
asked Nov 21 '18 at 5:33
hunmonkhunmonk
435
435
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can use the following code to run tests in headless mode:
await testcafe.createRunner()
.src('test.js')
.browsers('chrome:headless --no-sandbox --disable-gpu')
.run();
It's the way how we use the headless mode internally, so it'll be parsed correctly. Could you please check this approach?
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405790%2frun-testcafe-headless-when-passing-custom-args-to-chrome-binary-via-testcafe-bro%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use the following code to run tests in headless mode:
await testcafe.createRunner()
.src('test.js')
.browsers('chrome:headless --no-sandbox --disable-gpu')
.run();
It's the way how we use the headless mode internally, so it'll be parsed correctly. Could you please check this approach?
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
add a comment |
You can use the following code to run tests in headless mode:
await testcafe.createRunner()
.src('test.js')
.browsers('chrome:headless --no-sandbox --disable-gpu')
.run();
It's the way how we use the headless mode internally, so it'll be parsed correctly. Could you please check this approach?
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
add a comment |
You can use the following code to run tests in headless mode:
await testcafe.createRunner()
.src('test.js')
.browsers('chrome:headless --no-sandbox --disable-gpu')
.run();
It's the way how we use the headless mode internally, so it'll be parsed correctly. Could you please check this approach?
You can use the following code to run tests in headless mode:
await testcafe.createRunner()
.src('test.js')
.browsers('chrome:headless --no-sandbox --disable-gpu')
.run();
It's the way how we use the headless mode internally, so it'll be parsed correctly. Could you please check this approach?
answered Nov 21 '18 at 13:52
Alex KamaevAlex Kamaev
1,30139
1,30139
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
add a comment |
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
That works from CLI as well, just have to quote the whole browser string. Also, the --disable-gpu arg isn't necessary when running headless: testcafe 'chrome:headless --no-sandbox' test.js
– hunmonk
Nov 21 '18 at 16:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405790%2frun-testcafe-headless-when-passing-custom-args-to-chrome-binary-via-testcafe-bro%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown