Testcafe - How to run code after all the fixtures are run












1














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.










share|improve this question





























    1














    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.










    share|improve this question



























      1












      1








      1







      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.










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 7:45









      Alex Skorkin

      2,0721431




      2,0721431










      asked Nov 12 at 21:47









      Mano

      1,55021213




      1,55021213
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I have found a workaround for now. The workaround is:




          1. 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.

          2. I created a file called create-snapshot and created the snapshot there.

          3. I created another file called restore-snapshot and restored the snapshot in that file.

          4. I added two entries in package.json's scripts like "create-ss": "ts-node ./create-snapshot.ts", "restore-ss": "ts-node ./restore-snapshot.ts"

          5. 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.






          share|improve this answer





























            0














            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();
            });





            share|improve this answer





















            • 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 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 at 13:48











            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            0














            I have found a workaround for now. The workaround is:




            1. 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.

            2. I created a file called create-snapshot and created the snapshot there.

            3. I created another file called restore-snapshot and restored the snapshot in that file.

            4. I added two entries in package.json's scripts like "create-ss": "ts-node ./create-snapshot.ts", "restore-ss": "ts-node ./restore-snapshot.ts"

            5. 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.






            share|improve this answer


























              0














              I have found a workaround for now. The workaround is:




              1. 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.

              2. I created a file called create-snapshot and created the snapshot there.

              3. I created another file called restore-snapshot and restored the snapshot in that file.

              4. I added two entries in package.json's scripts like "create-ss": "ts-node ./create-snapshot.ts", "restore-ss": "ts-node ./restore-snapshot.ts"

              5. 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.






              share|improve this answer
























                0












                0








                0






                I have found a workaround for now. The workaround is:




                1. 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.

                2. I created a file called create-snapshot and created the snapshot there.

                3. I created another file called restore-snapshot and restored the snapshot in that file.

                4. I added two entries in package.json's scripts like "create-ss": "ts-node ./create-snapshot.ts", "restore-ss": "ts-node ./restore-snapshot.ts"

                5. 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.






                share|improve this answer












                I have found a workaround for now. The workaround is:




                1. 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.

                2. I created a file called create-snapshot and created the snapshot there.

                3. I created another file called restore-snapshot and restored the snapshot in that file.

                4. I added two entries in package.json's scripts like "create-ss": "ts-node ./create-snapshot.ts", "restore-ss": "ts-node ./restore-snapshot.ts"

                5. 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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 13 at 14:20









                Mano

                1,55021213




                1,55021213

























                    0














                    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();
                    });





                    share|improve this answer





















                    • 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 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 at 13:48
















                    0














                    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();
                    });





                    share|improve this answer





















                    • 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 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 at 13:48














                    0












                    0








                    0






                    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();
                    });





                    share|improve this answer












                    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();
                    });






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 16 at 12:42









                    Alex Skorkin

                    2,0721431




                    2,0721431












                    • 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 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 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 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 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 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 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 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 at 13:48


















                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    鏡平學校

                    ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                    Why https connections are so slow when debugging (stepping over) in Java?