angular / protractor

E2E test framework for Angular apps
http://www.protractortest.org
MIT License
8.75k stars 2.31k forks source link

Problem with disabling angular animations. #2447

Closed drptbl closed 8 years ago

drptbl commented 9 years ago

Hello. Actually I'm having problems with disabling some animations in my tests.

Code I'm using is default one:

    // Disable animations so e2e tests run more quickly
    var disableNgAnimate = function() {
      angular.module('disableNgAnimate', []).run(['$animate', function($animate) {
        $animate.enabled(false);
      }]);
    };

    browser.addMockModule('disableNgAnimate', disableNgAnimate);

    // Store the name of the browser that's currently being used.
    browser.getCapabilities().then(function(caps) {
      browser.params.browser = caps.get('browserName');
    });

Now how it looks.. When I'm running my tests, whole test scenario is run. Each running test case is working good without animations, but one of them got animations and they're not turned off, I dont know why.

Whole suite is available here: https://github.com/drptbl/protractortesting You are able to run it on yours machine.

I'm talking about this step (located in loginPageSpec.js file):

        it('should redirect user to cookie page after click on more.. text', function() {
            loginPage.cookieMore().click();
            expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + urls.cookiesPage());
            expect(loginPage.cookieFrame().isPresent()).toBeTruthy();
            expect(loginPage.cookieText().isPresent()).toBeTruthy();
            expect(loginPage.cookieMore().isPresent()).toBeTruthy();
            expect(loginPage.cookieAcceptButton().isPresent()).toBeTruthy();
        });

So basically.. my test cases are all run on some login page and this test case above gets redirected to another website when

            loginPage.cookieMore().click();

is executed. When it's executed and we're moving to other website - all animations are loaded normally (you can observe this when you look at cookie frame in left bottom corner - on all test cases its popping out instantly, on this one test case mentioned above its fading with animation). Why is this happening? Also this test case is really problematic and something is wrong because sometimes (yeah, really sometimes, got no idea why sometimes it works, sometimes not) it throws me this error:

JMs-MacBook-Pro:protractortesting jm$ protractor protractor.conf.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Spec started

  1 Home Page
    ✓ should render properly (10 secs)
    ✓ should contain proper title (2 secs)

  2 Login Page
    ✓ should render properly (11 secs)
    ✓ should contain proper title (3 secs)

    2.1 Cookie Window
      ✓ should contain cookie frame with elements (3 secs)
      ✓ should contain cookie description (2 secs)
      ✓ should contain cookie more.. text (8 secs)
      ✗ should redirect user to cookie page after click on more.. text (3 secs)
        - Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
      ✓ should contain cookie accept button (3 secs)
      ✓ should close cookie frame after acceptation (2 secs)

**************************************************
*                    Failures                    *
**************************************************

1) Login Page Cookie Window should redirect user to cookie page after click on more.. text
  - Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"
      at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:101:16
      at [object Object].promise.ControlFlow.runInFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1877:20)
      at [object Object].promise.Callback_.goog.defineClass.notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:2464:25)
      at [object Object].promise.Promise.notify_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:563:12)

Executed 10 of 10 specs (1 FAILED) in 48 secs.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

And I have no idea why it's happening. Any suggestions?

Two problems here:

Would love to fix this and hear yours opinion. Regards, drptbl.

drptbl commented 9 years ago

Also I tried to fix second problem with "angular could not be found on the window" error with this:

        it('should redirect user to cookie page after click on more.. text', function() {
            loginPage.cookieMore().click().then(function() {
            expect(browser.getCurrentUrl()).toEqual(browser.baseUrl + urls.cookiesPage());
            expect(loginPage.cookieFrame().isPresent()).toBeTruthy();
            expect(loginPage.cookieText().isPresent()).toBeTruthy();
            expect(loginPage.cookieMore().isPresent()).toBeTruthy();
            expect(loginPage.cookieAcceptButton().isPresent()).toBeTruthy();
            });
        });

without success. Found it somewhere on stackoverflow. With this change made I received this error more often than before (or it was just a bad luck).

drptbl commented 9 years ago

Hint: When this step is executed:

loginPage.cookieMore().click();

I'm moving from one Angular app to another. And this is probably causing the whole issue for me because I'm not doing this anywhere yet, only in this step (and issue exist only in this case actually, no problems with other steps).

Note: In future I'm going to move between angular apps a lot (our service is built on several angular apps). So I really need a good resolve for this issue if this is the cause of the problem.

hankduan commented 9 years ago

For your first question of why some animations don't turn off, are you sure those are Angular-compatible animations? This might help: https://github.com/angular/protractor/issues/2448#issuecomment-135181706

For the second question, is your login page Angular? If not, that'll be why. You'll find a lot of question on stackoverflow on this topic: http://stackoverflow.com/search?q=protractor+non+angular+pages.

For further questions, please ask directly on stackoverflow as we want to reserve github for features, bugs and pull requests

drptbl commented 9 years ago

Ad 1. Yes, all animations are angular-compatible, and the point is - it's the same animation not working after going from first angular app to second (it's copied from first to second and it's cookie window saying that you have to accept cookie policy). Ad 2. Yeah, all pages are wrote in Angular - I have no doubts because devs are sitting next to me.

Main bugs are:

drptbl commented 9 years ago

Thanks for reopening my issue :+1: ! It really needs further investigation.

juliemr commented 8 years ago

I think the problem here is that you're getting reloaded to an Angular website, so Protractor does not know that it needs to re-run adding the mock modules. Closing this in favor of https://github.com/angular/protractor/issues/996