Synchronization issues in Selenium while testing angular applications in c#

Viewed 25

I am facing Synchronization issues even though I am using Explicit Wait and Implicit wait in my script. So I am using customized waitForAngularRequestTofinish method as shown below.

public void waitForAngularRequestToFinish() {

        var js = (IJavaScriptExecutor)driver;
        string javaScriptToLoadAngular = "return (window.getAllAngularTestabilities()[0]._ngZone.hasPendingMicrotasks == " +
         "false && " +
         "window.getAllAngularTestabilities()[0]._ngZone.hasPendingMacrotasks == false && " +
         "window.getAllAngularTestabilities()[0]._ngZone._nesting == 0 &&" +

         "window.getAllAngularTestabilities()[0]._ngZone.isStable == true &&" +
         "window.document.readyState == 'complete'" +
         ")";


        // string javaScriptToLoadAngular = "return (window.getAngularTestability(window.getAllAngularRootElements()[0]).isStable())";
        WebDriverWait wt = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
        wt.Until<bool>(
          (d) =>
          {
              return (bool)js.ExecuteScript(javaScriptToLoadAngular).Equals(true);
          });
       
    }

However it is taking so much of time, that single scenario is taking almost 15 minutes to execute. I need a solution where i can reduce my execution time.

And also from past 10 days, hasPendingMacroTasks is never set to false in my application, because of that i am unable to execute my scripts at all.

0 Answers
Related