Continue loop after getting alert test from browser in protractor jasmine test











up vote
0
down vote

favorite












I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.



My test code



    for (let company = 0; company < await companyOption.count(); company++) {
await companyOption.get(company);

for (let machine = 0; machine < await machineList.count(); machine++) {
await click.onto(machineList.get(machine));

if (window.alert()) {
//here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
} else {
await expect(machineList.get(machine).isSelected());

}

.................... other code
}


Alert code in typescript



    ngOnInit() {

this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
this.machine = machine;
if (this.machine.type === null)
window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");


});
}









share|improve this question









New contributor




nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.



    My test code



        for (let company = 0; company < await companyOption.count(); company++) {
    await companyOption.get(company);

    for (let machine = 0; machine < await machineList.count(); machine++) {
    await click.onto(machineList.get(machine));

    if (window.alert()) {
    //here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
    } else {
    await expect(machineList.get(machine).isSelected());

    }

    .................... other code
    }


    Alert code in typescript



        ngOnInit() {

    this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
    this.machine = machine;
    if (this.machine.type === null)
    window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");


    });
    }









    share|improve this question









    New contributor




    nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.



      My test code



          for (let company = 0; company < await companyOption.count(); company++) {
      await companyOption.get(company);

      for (let machine = 0; machine < await machineList.count(); machine++) {
      await click.onto(machineList.get(machine));

      if (window.alert()) {
      //here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
      } else {
      await expect(machineList.get(machine).isSelected());

      }

      .................... other code
      }


      Alert code in typescript



          ngOnInit() {

      this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
      this.machine = machine;
      if (this.machine.type === null)
      window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");


      });
      }









      share|improve this question









      New contributor




      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am implementing Protrator framework with jasmine runner in my angular app. I click on each element with expected result. Now I have a list of companies in my app. each company has two or three machines is side bar. I implemented two for loops that with loop throug the company and machines as well. Now in one machine list there is an error and as a result is shows alert from localhost. For this reason the loop breaks and fails. I want to implement a condition there so that it can detect the condition and continue from the loop. But I could not get it how can I implement that.



      My test code



          for (let company = 0; company < await companyOption.count(); company++) {
      await companyOption.get(company);

      for (let machine = 0; machine < await machineList.count(); machine++) {
      await click.onto(machineList.get(machine));

      if (window.alert()) {
      //here i want to implement if browser.switchto.alert() is appear then test should be continue to next loop
      } else {
      await expect(machineList.get(machine).isSelected());

      }

      .................... other code
      }


      Alert code in typescript



          ngOnInit() {

      this.route.paramMap.switchMap((params: ParamMap, index) => this.machineService.load(parseInt(params.get("machineId")))).subscribe(machine => {
      this.machine = machine;
      if (this.machine.type === null)
      window.alert("No machine type assigned for " + this.machine.name + "nAssign a type to view the details.");


      });
      }






      javascript angular protractor jasmin






      share|improve this question









      New contributor




      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 2 days ago





















      New contributor




      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      nick_tec

      12




      12




      New contributor




      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      nick_tec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Try this



          for (let company = 0; company < await companyOption.count(); company++) {

          await companyOption.get(company);

          for (let machine = 0; machine < await machineList.count(); machine++) {

          await click.onto(machineList.get(machine));
          // solution! //
          let errorMessage; // define a variable, which is currently undefined

          try {
          // try run this code, if alert is not present it'll throw an error
          // if alert is present it skips is
          await browser.switchTo().alert().accept();
          } catch (e) {
          // if there was no alert and an error was thrown than assign error to variable
          // if there was alert this block will be skipped and errorMessage will stay undefined
          errorMessage = e.message;
          }

          // this block will be executed if alert was present!
          // otherwise do nothing
          if (errorMessage !== undefined) {
          // ... your code here ...
          }
          // end of solution //
          }


          I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code






          share|improve this answer





















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


            }
            });






            nick_tec is a new contributor. Be nice, and check out our Code of Conduct.










             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373159%2fcontinue-loop-after-getting-alert-test-from-browser-in-protractor-jasmine-test%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








            up vote
            0
            down vote













            Try this



            for (let company = 0; company < await companyOption.count(); company++) {

            await companyOption.get(company);

            for (let machine = 0; machine < await machineList.count(); machine++) {

            await click.onto(machineList.get(machine));
            // solution! //
            let errorMessage; // define a variable, which is currently undefined

            try {
            // try run this code, if alert is not present it'll throw an error
            // if alert is present it skips is
            await browser.switchTo().alert().accept();
            } catch (e) {
            // if there was no alert and an error was thrown than assign error to variable
            // if there was alert this block will be skipped and errorMessage will stay undefined
            errorMessage = e.message;
            }

            // this block will be executed if alert was present!
            // otherwise do nothing
            if (errorMessage !== undefined) {
            // ... your code here ...
            }
            // end of solution //
            }


            I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code






            share|improve this answer

























              up vote
              0
              down vote













              Try this



              for (let company = 0; company < await companyOption.count(); company++) {

              await companyOption.get(company);

              for (let machine = 0; machine < await machineList.count(); machine++) {

              await click.onto(machineList.get(machine));
              // solution! //
              let errorMessage; // define a variable, which is currently undefined

              try {
              // try run this code, if alert is not present it'll throw an error
              // if alert is present it skips is
              await browser.switchTo().alert().accept();
              } catch (e) {
              // if there was no alert and an error was thrown than assign error to variable
              // if there was alert this block will be skipped and errorMessage will stay undefined
              errorMessage = e.message;
              }

              // this block will be executed if alert was present!
              // otherwise do nothing
              if (errorMessage !== undefined) {
              // ... your code here ...
              }
              // end of solution //
              }


              I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Try this



                for (let company = 0; company < await companyOption.count(); company++) {

                await companyOption.get(company);

                for (let machine = 0; machine < await machineList.count(); machine++) {

                await click.onto(machineList.get(machine));
                // solution! //
                let errorMessage; // define a variable, which is currently undefined

                try {
                // try run this code, if alert is not present it'll throw an error
                // if alert is present it skips is
                await browser.switchTo().alert().accept();
                } catch (e) {
                // if there was no alert and an error was thrown than assign error to variable
                // if there was alert this block will be skipped and errorMessage will stay undefined
                errorMessage = e.message;
                }

                // this block will be executed if alert was present!
                // otherwise do nothing
                if (errorMessage !== undefined) {
                // ... your code here ...
                }
                // end of solution //
                }


                I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code






                share|improve this answer












                Try this



                for (let company = 0; company < await companyOption.count(); company++) {

                await companyOption.get(company);

                for (let machine = 0; machine < await machineList.count(); machine++) {

                await click.onto(machineList.get(machine));
                // solution! //
                let errorMessage; // define a variable, which is currently undefined

                try {
                // try run this code, if alert is not present it'll throw an error
                // if alert is present it skips is
                await browser.switchTo().alert().accept();
                } catch (e) {
                // if there was no alert and an error was thrown than assign error to variable
                // if there was alert this block will be skipped and errorMessage will stay undefined
                errorMessage = e.message;
                }

                // this block will be executed if alert was present!
                // otherwise do nothing
                if (errorMessage !== undefined) {
                // ... your code here ...
                }
                // end of solution //
                }


                I checked my code and it is working, if still doesn't work, look for mistakes in YOUR part of the code







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 20 hours ago









                Sergey Pleshakov

                1218




                1218






















                    nick_tec is a new contributor. Be nice, and check out our Code of Conduct.










                     

                    draft saved


                    draft discarded


















                    nick_tec is a new contributor. Be nice, and check out our Code of Conduct.













                    nick_tec is a new contributor. Be nice, and check out our Code of Conduct.












                    nick_tec is a new contributor. Be nice, and check out our Code of Conduct.















                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373159%2fcontinue-loop-after-getting-alert-test-from-browser-in-protractor-jasmine-test%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

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]