Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e test with karma fails #20

Closed
dutscher opened this issue Jan 23, 2014 · 8 comments
Closed

e2e test with karma fails #20

dutscher opened this issue Jan 23, 2014 · 8 comments

Comments

@dutscher
Copy link

Hey marcos,
at first very awesome work!

And now to my problem. I tried the last hours to get a simple e2e test with karma, but something went wrong.

As template for my test enviroment i used https://github.com/angular/angular-phonecat. The difference is that the phonecat app does'nt use angularAMD and requirejs.

Now to my files

app.js

'use strict';
define(['angularAMD', 'angular-route'], function (angularAMD) {
    var app = angular.module('cameoClientAngular', ['ngRoute']);
    app.config(['$routeProvider', '$locationProvider',
    function($routeProvider, $locationProvider){
        //$locationProvider.html5Mode(true);
        $routeProvider.
        when('/login', angularAMD.route({
            templateUrl: 'tpl/form/login.html',
            controller: 'LoginCtrl'
        })).
        otherwise({
            redirectTo: '/login'
        });
    }]);

    angularAMD.bootstrap(app);

    return app;
});

scenarios.js:

'use strict';
describe('Cameo Client Tests', function() {
    it('should redirect index.html to index.html#/login', function() {
        browser().navigateTo('app/index.html');
        expect(browser().location().url()).toBe('/login');
    });
});

If i run this simple test then i get this error/fail:

describe: Cameo Client Tests
472ms should redirect index.html to index.html#/login
411ms   browser navigate to 'app/index.html'
33ms    $location.url()
http://localhost:8000/test/e2e/scenarios.js:6:16

TypeError: Object [object Object] has no method 'injector'
    at Scope.<anonymous> (http://localhost:8000/app/js/vendor/angular/angular-scenario.js:31892:30)
    at null.<anonymous> (http://localhost:8000/app/js/vendor/angular/angular-scenario.js:31777:18)
    at angular.scenario.Application.executeAction (http://localhost:8000/app/js/vendor/angular/angular-scenario.js:30931:19)
    at Scope.<anonymous> (http://localhost:8000/app/js/vendor/angular/angular-scenario.js:31750:22)

The main error is TypeError: Object [object Object] has no method 'injector' and is thrown throw browser().location().url().
Have you an idea what i do wrong? Or rather exists an example with an e2e test on a angularAMD App?

greetings from germany,
dutscher

@marcoslin
Copy link
Owner

dutscher,

Thanks for the kudos. Really appreciate it.

Can you put your project in a repo that I can have access to? There are so many possible place that is causing this and hard to debug without the rest of the code.

Marcos


If you like angularAMD, please consider Star this project.

@dutscher
Copy link
Author

yeah the star is rated ;)

so here u can find the repo https://github.com/memoConnect/cameoClientAngular/tree/feature-login-directive

i figure out that the karma browser don't excute the app.js. in the nodejs webserver logs is at the end

GET /app/js/bootstrap/main.js Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.76 Safari/537.36

the browser can't also show the app. only i refresh the iframe in karma testing than the app will appear.
i hope it is only a small thing :D

thanks for your help!

greets

@marcoslin
Copy link
Owner

Bad news unfortunately... The core problem is that karma-ng-scenario does not wait for async loaded modules as per this post by Vojta:
https://groups.google.com/forum/#!msg/karma-users/g19LuvZMkOM/EoTG3YbIEi8J

I tried several hacks and I just couldn't get E2E to run. I will try to create an example with Protractor in the angularAMD project.

I am in the middle of a project and probably wont be able to get to for a couple of weeks.

@dutscher
Copy link
Author

Okay great, i will wait for it.

My tries with protractor wouldn't work and of course this is very tricky.

I think your AMD solution is the best and easiest to implement.
And angularjs should implement that!

Tomorrow i would try again to get a successful simple test with protractor.

Do you have a simple example for unit tests?

Greets from germany
dutscher

@marcoslin
Copy link
Owner

When you have a working protractor test, please share it with me. Also, Atul Chaudhary mentioned in a Google+ post that he has successfully done a E2E test of angularAMD with protractor. If you try to contact him via Google+, he might share his code with you. Include me in the post to him.

As for unit test, look under the angularAMD/test directory. You will see the karma config and actual test done on angularAMD.

@marcoslin
Copy link
Owner

I have a working version of e2e test under devel branch. Check it out under the test directory.

@dutscher
Copy link
Author

dutscher commented Feb 4, 2014

wow marcos, now i got and can test the full app. thank you very much. if you merge the test to master then you can write down in the readme that at first start the web-server.
i'am very happy to work with with your angularAMD!
greetz from germany

@dutscher dutscher closed this as completed Feb 4, 2014
@marcoslin
Copy link
Owner

The E2E test is done but I still need a bit of time to setup grunt to automate the testing. In the mean time, the steps to run E2E are (after following steps in README.md):

  • Start the WebDriver/Selenium server by running:
cd angularAMD/
bin/webdriver-manager start
  • Launch a static web server in another shell at port 8444:
cd angularAMD/www
python -m SimpleHTTPServer 8444
  • Run the E2E test, in yet another shell:
cd angularAMD/
bin/protractor test/conf/protractor.e2e.js --browser chrome

** Remove the option --browser chrome to run E2E with phantomjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants