Capture pass/fail of Protractor test case for custom reporting










0















I've recently setup Protractor testing for our angular apps at our company - and was looking for a simple way to capture pass/fail status of each scenario in the spec classes. Is there a simple way to do this? I've tried messing with the jasmine-spec-reporter, but maybe I was missing something there to extract the data I need. Any help would be appreciated.



I've tried things like this:



let currentSpec = jasmine.getEnv().currrentSpec, passed = currentSpec.results().passed();


but am always getting issues like




currentSpec not specified




Ideally I would like to capture pass or fail without jasmine reporting, if possible.










share|improve this question




























    0















    I've recently setup Protractor testing for our angular apps at our company - and was looking for a simple way to capture pass/fail status of each scenario in the spec classes. Is there a simple way to do this? I've tried messing with the jasmine-spec-reporter, but maybe I was missing something there to extract the data I need. Any help would be appreciated.



    I've tried things like this:



    let currentSpec = jasmine.getEnv().currrentSpec, passed = currentSpec.results().passed();


    but am always getting issues like




    currentSpec not specified




    Ideally I would like to capture pass or fail without jasmine reporting, if possible.










    share|improve this question


























      0












      0








      0








      I've recently setup Protractor testing for our angular apps at our company - and was looking for a simple way to capture pass/fail status of each scenario in the spec classes. Is there a simple way to do this? I've tried messing with the jasmine-spec-reporter, but maybe I was missing something there to extract the data I need. Any help would be appreciated.



      I've tried things like this:



      let currentSpec = jasmine.getEnv().currrentSpec, passed = currentSpec.results().passed();


      but am always getting issues like




      currentSpec not specified




      Ideally I would like to capture pass or fail without jasmine reporting, if possible.










      share|improve this question
















      I've recently setup Protractor testing for our angular apps at our company - and was looking for a simple way to capture pass/fail status of each scenario in the spec classes. Is there a simple way to do this? I've tried messing with the jasmine-spec-reporter, but maybe I was missing something there to extract the data I need. Any help would be appreciated.



      I've tried things like this:



      let currentSpec = jasmine.getEnv().currrentSpec, passed = currentSpec.results().passed();


      but am always getting issues like




      currentSpec not specified




      Ideally I would like to capture pass or fail without jasmine reporting, if possible.







      javascript angularjs typescript protractor automated-tests






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 6:08









      Al Imran

      709417




      709417










      asked Nov 14 '18 at 19:14









      Coolei WhistlesCoolei Whistles

      93




      93






















          2 Answers
          2






          active

          oldest

          votes


















          0














          Are you using this as well?:
          https://www.npmjs.com/package/protractor-html-reporter-2



          To have a better error description of the error and adding them to the jasmine reporter:
          https://www.npmjs.com/package/jasmine2-custom-message






          share|improve this answer























          • I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

            – Coolei Whistles
            Nov 15 '18 at 15:42


















          0














          What you are looking for is actually specDone not afterEach. You either need to modify the specDone function of the reporter you are currently using or build a custom reporter that fits your needs.



          https://jasmine.github.io/2.1/custom_reporter.html#section-specDone



          Create your custom reporter:



          // myReporter.js
          module.exports =
          specDone: (result) =>
          // do stuff...




          Then in your protractor config you would have something like this:



          const myReporter = require('myReporter');

          // other config properties

          onPrepare: function()
          jasmine.getEnv().addReporter(myReporter);






          share|improve this answer

























          • Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

            – Coolei Whistles
            Nov 15 '18 at 18:33











          • It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

            – tehbeardedone
            Nov 15 '18 at 19:19











          • ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

            – Coolei Whistles
            Nov 15 '18 at 21:40











          • this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

            – Coolei Whistles
            Nov 15 '18 at 21:40












          • Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

            – tehbeardedone
            Nov 15 '18 at 22:57










          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%2f53307269%2fcapture-pass-fail-of-protractor-test-case-for-custom-reporting%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














          Are you using this as well?:
          https://www.npmjs.com/package/protractor-html-reporter-2



          To have a better error description of the error and adding them to the jasmine reporter:
          https://www.npmjs.com/package/jasmine2-custom-message






          share|improve this answer























          • I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

            – Coolei Whistles
            Nov 15 '18 at 15:42















          0














          Are you using this as well?:
          https://www.npmjs.com/package/protractor-html-reporter-2



          To have a better error description of the error and adding them to the jasmine reporter:
          https://www.npmjs.com/package/jasmine2-custom-message






          share|improve this answer























          • I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

            – Coolei Whistles
            Nov 15 '18 at 15:42













          0












          0








          0







          Are you using this as well?:
          https://www.npmjs.com/package/protractor-html-reporter-2



          To have a better error description of the error and adding them to the jasmine reporter:
          https://www.npmjs.com/package/jasmine2-custom-message






          share|improve this answer













          Are you using this as well?:
          https://www.npmjs.com/package/protractor-html-reporter-2



          To have a better error description of the error and adding them to the jasmine reporter:
          https://www.npmjs.com/package/jasmine2-custom-message







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 6:47









          AlexandreAlexandre

          1309




          1309












          • I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

            – Coolei Whistles
            Nov 15 '18 at 15:42

















          • I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

            – Coolei Whistles
            Nov 15 '18 at 15:42
















          I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

          – Coolei Whistles
          Nov 15 '18 at 15:42





          I have looked into it, but am unable to do what I wish. Basically am wanting to have an AfterEach for each "it" block and that will be like if (result.status == 'failed') // code to send results to our api reporting

          – Coolei Whistles
          Nov 15 '18 at 15:42













          0














          What you are looking for is actually specDone not afterEach. You either need to modify the specDone function of the reporter you are currently using or build a custom reporter that fits your needs.



          https://jasmine.github.io/2.1/custom_reporter.html#section-specDone



          Create your custom reporter:



          // myReporter.js
          module.exports =
          specDone: (result) =>
          // do stuff...




          Then in your protractor config you would have something like this:



          const myReporter = require('myReporter');

          // other config properties

          onPrepare: function()
          jasmine.getEnv().addReporter(myReporter);






          share|improve this answer

























          • Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

            – Coolei Whistles
            Nov 15 '18 at 18:33











          • It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

            – tehbeardedone
            Nov 15 '18 at 19:19











          • ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

            – Coolei Whistles
            Nov 15 '18 at 21:40











          • this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

            – Coolei Whistles
            Nov 15 '18 at 21:40












          • Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

            – tehbeardedone
            Nov 15 '18 at 22:57















          0














          What you are looking for is actually specDone not afterEach. You either need to modify the specDone function of the reporter you are currently using or build a custom reporter that fits your needs.



          https://jasmine.github.io/2.1/custom_reporter.html#section-specDone



          Create your custom reporter:



          // myReporter.js
          module.exports =
          specDone: (result) =>
          // do stuff...




          Then in your protractor config you would have something like this:



          const myReporter = require('myReporter');

          // other config properties

          onPrepare: function()
          jasmine.getEnv().addReporter(myReporter);






          share|improve this answer

























          • Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

            – Coolei Whistles
            Nov 15 '18 at 18:33











          • It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

            – tehbeardedone
            Nov 15 '18 at 19:19











          • ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

            – Coolei Whistles
            Nov 15 '18 at 21:40











          • this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

            – Coolei Whistles
            Nov 15 '18 at 21:40












          • Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

            – tehbeardedone
            Nov 15 '18 at 22:57













          0












          0








          0







          What you are looking for is actually specDone not afterEach. You either need to modify the specDone function of the reporter you are currently using or build a custom reporter that fits your needs.



          https://jasmine.github.io/2.1/custom_reporter.html#section-specDone



          Create your custom reporter:



          // myReporter.js
          module.exports =
          specDone: (result) =>
          // do stuff...




          Then in your protractor config you would have something like this:



          const myReporter = require('myReporter');

          // other config properties

          onPrepare: function()
          jasmine.getEnv().addReporter(myReporter);






          share|improve this answer















          What you are looking for is actually specDone not afterEach. You either need to modify the specDone function of the reporter you are currently using or build a custom reporter that fits your needs.



          https://jasmine.github.io/2.1/custom_reporter.html#section-specDone



          Create your custom reporter:



          // myReporter.js
          module.exports =
          specDone: (result) =>
          // do stuff...




          Then in your protractor config you would have something like this:



          const myReporter = require('myReporter');

          // other config properties

          onPrepare: function()
          jasmine.getEnv().addReporter(myReporter);







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 23:04

























          answered Nov 15 '18 at 17:40









          tehbeardedonetehbeardedone

          1,80511119




          1,80511119












          • Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

            – Coolei Whistles
            Nov 15 '18 at 18:33











          • It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

            – tehbeardedone
            Nov 15 '18 at 19:19











          • ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

            – Coolei Whistles
            Nov 15 '18 at 21:40











          • this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

            – Coolei Whistles
            Nov 15 '18 at 21:40












          • Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

            – tehbeardedone
            Nov 15 '18 at 22:57

















          • Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

            – Coolei Whistles
            Nov 15 '18 at 18:33











          • It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

            – tehbeardedone
            Nov 15 '18 at 19:19











          • ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

            – Coolei Whistles
            Nov 15 '18 at 21:40











          • this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

            – Coolei Whistles
            Nov 15 '18 at 21:40












          • Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

            – tehbeardedone
            Nov 15 '18 at 22:57
















          Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

          – Coolei Whistles
          Nov 15 '18 at 18:33





          Looks like specDone is for the entire spec file right. I want it to update based on each "it" block but looks like I'll need to have some reporting dependency still.

          – Coolei Whistles
          Nov 15 '18 at 18:33













          It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

          – tehbeardedone
          Nov 15 '18 at 19:19





          It should run for each 'it' block. First line of the docs: specDone is invoked when an it and its associated beforeEach and afterEach functions have been run.

          – tehbeardedone
          Nov 15 '18 at 19:19













          ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

          – Coolei Whistles
          Nov 15 '18 at 21:40





          ok that makes sense.. still not exactly sure where to specify the specDone piece of it at. in the spec file or the conf file?

          – Coolei Whistles
          Nov 15 '18 at 21:40













          this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

          – Coolei Whistles
          Nov 15 '18 at 21:40






          this is what i have now let myReporter = specDone: function (result) if (result.failedExpectations.length > 0) TEST_STATUS = "FAIL"; else TEST_STATUS = "PASS"; ; afterEach(function (myReporter) home.reportResults(PROJECT_KEY, TEST_CASE_KEY, TEST_CYCLE_KEY, TEST_STATUS, startTime); );`

          – Coolei Whistles
          Nov 15 '18 at 21:40














          Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

          – tehbeardedone
          Nov 15 '18 at 22:57





          Is that actually working? You should probably create a separate myReporter.js file and then set it up in your onPrepare of the protractor config similar to the way other reporters are configured. I'll update my answer with an example.

          – tehbeardedone
          Nov 15 '18 at 22:57

















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307269%2fcapture-pass-fail-of-protractor-test-case-for-custom-reporting%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







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto