Testcafe - How to run code after all the fixtures are run
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
sql-server automated-tests e2e-testing testcafe
add a comment |
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
sql-server automated-tests e2e-testing testcafe
add a comment |
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
sql-server automated-tests e2e-testing testcafe
I want to create a snapshot of the SQL server DB and then restore it after "all the fixtures" are run.
I can do it after every fixture through .after hook in a fixture. However, that is causing issues while running tests since the DB may be still in transition after a restore. So I would prefer to do it after all the fixtures.
sql-server automated-tests e2e-testing testcafe
sql-server automated-tests e2e-testing testcafe
edited Nov 13 '18 at 7:45
Alex Skorkin
2,1171532
2,1171532
asked Nov 12 '18 at 21:47
Mano
1,55521213
1,55521213
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I have found a workaround for now. The workaround is:
- Add dependency for ts-node. I also had to add tsconfig.json with compiler options' lib property set to es2015 and dom. If not, it was complaining about Promise.
- I created a file called create-snapshot and created the snapshot there.
- I created another file called restore-snapshot and restored the snapshot in that file.
- I added two entries in package.json's scripts like
"create-ss": "ts-node ./create-snapshot.ts"
,"restore-ss": "ts-node ./restore-snapshot.ts"
- Now from Powershell, I run the tests with the command:
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;.
I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
add a comment |
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc =>
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
)
.then(failedCount =>
// Clean up your database here...
testcafe.close();
);
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
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%2f53270589%2ftestcafe-how-to-run-code-after-all-the-fixtures-are-run%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I have found a workaround for now. The workaround is:
- Add dependency for ts-node. I also had to add tsconfig.json with compiler options' lib property set to es2015 and dom. If not, it was complaining about Promise.
- I created a file called create-snapshot and created the snapshot there.
- I created another file called restore-snapshot and restored the snapshot in that file.
- I added two entries in package.json's scripts like
"create-ss": "ts-node ./create-snapshot.ts"
,"restore-ss": "ts-node ./restore-snapshot.ts"
- Now from Powershell, I run the tests with the command:
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;.
I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
add a comment |
I have found a workaround for now. The workaround is:
- Add dependency for ts-node. I also had to add tsconfig.json with compiler options' lib property set to es2015 and dom. If not, it was complaining about Promise.
- I created a file called create-snapshot and created the snapshot there.
- I created another file called restore-snapshot and restored the snapshot in that file.
- I added two entries in package.json's scripts like
"create-ss": "ts-node ./create-snapshot.ts"
,"restore-ss": "ts-node ./restore-snapshot.ts"
- Now from Powershell, I run the tests with the command:
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;.
I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
add a comment |
I have found a workaround for now. The workaround is:
- Add dependency for ts-node. I also had to add tsconfig.json with compiler options' lib property set to es2015 and dom. If not, it was complaining about Promise.
- I created a file called create-snapshot and created the snapshot there.
- I created another file called restore-snapshot and restored the snapshot in that file.
- I added two entries in package.json's scripts like
"create-ss": "ts-node ./create-snapshot.ts"
,"restore-ss": "ts-node ./restore-snapshot.ts"
- Now from Powershell, I run the tests with the command:
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;.
I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
I have found a workaround for now. The workaround is:
- Add dependency for ts-node. I also had to add tsconfig.json with compiler options' lib property set to es2015 and dom. If not, it was complaining about Promise.
- I created a file called create-snapshot and created the snapshot there.
- I created another file called restore-snapshot and restored the snapshot in that file.
- I added two entries in package.json's scripts like
"create-ss": "ts-node ./create-snapshot.ts"
,"restore-ss": "ts-node ./restore-snapshot.ts"
- Now from Powershell, I run the tests with the command:
npm run create-ss;npm run test-chrome-hl;npm run restore-ss
. This runs the commands sequentially in Powershell. In other terminals you may need to use && or something else instead of ;.
I can avoid "npm run create-ss" by using the .before hook of the fixture by keeping track of a variable to ensure it runs only once. However I cannot do a similar approach when the last test gets executed.
Its a bit of a pain to remember the three commands but I dont see another way so far.
answered Nov 13 '18 at 14:20
Mano
1,55521213
1,55521213
add a comment |
add a comment |
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc =>
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
)
.then(failedCount =>
// Clean up your database here...
testcafe.close();
);
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
add a comment |
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc =>
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
)
.then(failedCount =>
// Clean up your database here...
testcafe.close();
);
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
add a comment |
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc =>
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
)
.then(failedCount =>
// Clean up your database here...
testcafe.close();
);
You can also use the TestCafe Programming Interface API. The TestCafe Runner class returns a Promise object. You can use this object to run your custom cleanup code after all tests/fixtures are completed.
Here's an example:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', 1337, 1338)
.then(tc =>
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src(['tests/fixture1.js', 'tests/fixture2.js', 'tests/fixture3.js'])
.browsers(['chrome', 'safari'])
.run();
)
.then(failedCount =>
// Clean up your database here...
testcafe.close();
);
answered Nov 16 '18 at 12:42
Alex Skorkin
2,1171532
2,1171532
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
add a comment |
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
Thanks! I did read about it from the documentation. There were a few things I was not sure are: How do I change the browsers at run time. Do I pass them as arguments and use that there? Does the src takes a wild card saying? For e.g, can I say any fixture under src folder (any folders deep) and not update the src every time I add a new fixture.
– Mano
Nov 16 '18 at 18:23
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
You are welcome. Check out the 'src' argument topic. You can use glob patterns to include (or exclude) multiple files. I'm not sure why you need to switch browsers at runtime though. Specify them in the corresponding browsers argument and execute your tests.
– Alex Skorkin
Nov 19 '18 at 13:48
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53270589%2ftestcafe-how-to-run-code-after-all-the-fixtures-are-run%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