Forums

Angularjs Jasmine tests with Karma and Protractor

I'm learning about these tests, but just read in the help seccion, another way of testing with Jasmine on Pythonanywhere. Does that means Karma and Protractor can't be used? I believe they open a browser that has to be already installed in the machine.

Hi myfirstapp,

I do know that karma is useable on pythonanywhere. I personally use it to run my js tests within the pythonanywhere console. You will have to install npm install it and any dependencies first though.

Not sure abt protractor- if you do any investigations can you post back here and let us know how it goes?

Ok. Thanks!. I will try.

Conrad, Hope you can help me. What browser are you using for Karma? Did you had to install it? Did you override the path in the Karma plugin for that browser? Thanks!

Hi there,

Here are the two steps that you need to run in bash to start testing with karma.

npm install karma karma-jasmine karma-firefox-launcher   # NB: this makes a node_modules folder in cwd
xvfb-run node_modules/karma/bin/karma start

You'd also need to have a karma.conf.js specifying the framework you are using (jasmine) and the path to the files you want to load (ie. angular.js, any mocking libraries, your code, your tests etc). Go here for an example.

And also, note that you won't be able to use the -g option (eg: if you are lazy and want to do npm install -g karma-cli. Instead, you can do something like ln -s ~/node_modules/karma/bin/karma ~/.local/bin/karma to accomplish the same thing)

It works!. Both Karma and Protractor. Pythonanywhere team is the best!

For Protractor is very similar.

npm install protractor
xvfb-run node_modules/protractor/bin/protractor --version
xvfb-run node_modules/protractor/bin/webdriver-manager update

Follow the instructions on Protractor web site for

1-write a test( todo-spec.js )

2-configuration( conf.js ) *Here I had to make changes.

exports.config = {
    //seleniumAddress: 'http://localhost:4444/wd/hub',
    directConnect: true,
    // Boolean. If true, Protractor will connect directly to the browser Drivers
    // at the locations specified by chromeDriver and firefoxPath. Only Chrome
    // and Firefox are supported for direct connect.

    firefoxPath: null,
    // Path to the firefox application binary. If null, will attempt to find
    // firefox in the default locations.

    specs: [
        //'todo-spec.js'
        'path/to/my/tests/todo-spec.js'
    ],

    capabilities: {
        browserName: 'firefox'
     }

};

Then :

xvfb-run node_modules/protractor/bin/protractor conf.js

After the tests are run, still get an error from webdriver. But test are definitely working and getting correct results on basic tests like

    expect(element(by.model('mymodel')).getText()).toEqual('It works!');