Prashant P
Prashant P

Reputation: 15

Protractor- Unable to locate element after loading the homepage

Not able to find any element on homepage after login.

Scenario: Click on profile name/icon & click on Logout button

it('Signout', function() {
                //tried with following code 
                //browser.waitForAngularEnabled(true);
                //locator below 
                //var profileIcon=element(by.model('user'));
                common.btnClk(homepage.profileIcon);
                common.btnClk(homepage.FCS_signoutbtn);
                browser.close();

            });

Workaround: When home page is refreshed browser.refresh(); then only able to find element. Please suggest solutions without this workaround.

Logs:

[31m- [39m[31mFailed: Timed out waiting for asynchronous Angular tasks to finish after 120 seconds. This may be because the current page is not an Angular application. Please see the FAQ for more details: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular
  While waiting for element with locator - Locator: by.model("user"). 
  The following tasks were pending:
   - $timeout: function (){$rootScope.authenticated=false;$cookies.remove("access_token");$cookies.remove("organizationId");$cookies.remove("authenticated");$cookies.remove("user_infos");$cookies.remove("user_profile_infos");$cookies.remove("user_depts");ChatSocket.disconnect();$state.go('core.login',{},{reload:true});$rootScope.options={position:'toast-top-right',type:'error',iconClass:{name:'error'},timeout:'5000',extendedTimeout:'1000',html:false,closeButton:true,tapToDismiss:true,closeHtml:'<i class="fa fa-times"></i>'};var msg="Your Token is Expired!";$rootScope.openToast("Session Timeout",msg);}[39m

Executed 2 of 2 specs[31m (1 FAILED)[39m in 2 mins 55 secs.

[12:57:53] I/launcher - 0 instance(s) of WebDriver still running
[12:57:53] I/launcher - chrome #01 failed 1 test(s)
[12:57:53] I/launcher - overall: 1 failed spec(s)
[12:57:53] E/launcher - Process exited with error code 1

Additional Info: Tried with browser.ignoreSynchronization = true; & located via xpath, its working. But i want to test with angular approach. ** Website is angular site ** Tried with: browser.driver.manage().window().setSize(1280, 1024); browser.ignoreSynchronization = false; allScriptsTimeout: 160000, defaultTimeoutInterval: 160000

Please suggest any solutions.

Upvotes: 0

Views: 1677

Answers (1)

Ernst Zwingli
Ernst Zwingli

Reputation: 1422

Looks like you have a $timeout pending on your page. As refresh kind of solves it, there could be a bug behind that behavior, related to the login/authentication and the page-change (kind of a timing issue, which might leave a former promise unresolved).

If that's the case, maybe the ControlFlow needs to be "emptied" as last action, before the new page loads. Maybe your dev's can help.

As a workaround, try to do

browser.waitForAngularEnabled(false); //could empty Protractors/Seleniums ChangeDetection on the ControlFlow
browser.waitForAngularEnabled(true); //will observe the ControlFlow for new promises again.

Though, it's a long shot and I'm patially guessing, you might want to give it a try.

Upvotes: 1

Related Questions