Protractor - Unable to run protractor tests - javascript

My tests are throwing the following error. It used to run fine before. Please advise.
My Config file:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
allScriptsTimeout: 20000,
baseUrl: 'https://mylink/#/',
// frameworks to use
frameworks: ['jasmine'],
// Capabilities to be passed to the webdriver instance.
multiCapabilities: [{
'browserName': 'chrome'
//}, {
// 'browserName': 'firefox'
//
}],
// Spec patterns are relative to the current working directory.
specs: [
'tests/HomePage.js'
],
onPrepare: function() {
browser.driver.manage().window().maximize();
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true. true));
},
jasmineNodeOpts: {
showColors: true
}
}
My Spec file:
// spec.js
describe('MyTest homepage', function() {
var ptor;
require('protractor-linkuisref-locator')(protractor);
beforeEach(function() {
browser.ignoreSynchronization = true;
ptor = protractor.getInstance();
browser.rootEl = 'div';
//browser.driver.manage().window().setSize(1280, 1024);
browser.debugger();
});
it('Should enter homepage url and credentials', function() {
browser.get('/#/');
element(by.name('userName')).sendKeys('');
element(by.name('password')).sendKeys('');
element(by.xpath("//button[#class=' btn orange small wide']")).click();
});
it('Should the title contain', function() {
expect(browser.getTitle()).toEqual('');
});
it('Should click on the PowerGuide', function() {
element(by.linkUiSref('locator')).click();
ptor.sleep(100);
//expect(ptor.getCurrentUrl(locator)).toEqual('');
});
it('Should click on Month', function() {
element(by.id('month-tab')).click();
ptor.sleep(100);
});
//it('Should load the images', function() {
// element(by.css('.pure-u-1-2')).click();
//var icons = element.all(by.css('.pure-u-1-2')).click();
//icons.first().click();
//});
});
This is the error I am getting.
seleniumProcess.pid: 1380
14:43:45.163 INFO - Launching a standalone server
Setting system property webdriver.chrome.driver to C:\Users\sramamoorthy\AppData\Roaming\npm\node_modules\protractor\sel
enium\chromedriver.exe
14:43:45.342 INFO - Java: Oracle Corporation 25.40-b25
14:43:45.342 INFO - OS: Windows 7 6.1 amd64
14:43:45.373 INFO - v2.45.0, with Core v2.45.0. Built from revision 5017cb8
14:43:45.597 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
14:43:45.597 INFO - Version Jetty/5.1.x
14:43:45.597 INFO - Started HttpContext[/selenium-server,/selenium-server]
14:43:45.779 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler#23223dd8
14:43:45.781 INFO - Started HttpContext[/wd,/wd]
14:43:45.781 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
14:43:45.781 INFO - Started HttpContext[/,/]
14:43:45.789 INFO - Started SocketListener on 0.0.0.0:4444
14:43:45.789 INFO - Started org.openqa.jetty.jetty.Server#133314b
14:44:41.384 INFO - Executing: [new session: Capabilities [{count=1, browserName=chrome}]])
14:44:41.399 INFO - Creating a new session for Capabilities [{count=1, browserName=chrome}]
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 44385
Only local connections are allowed.
14:44:43.309 INFO - Done: [new session: Capabilities [{count=1, browserName=chrome}]]
14:44:43.567 INFO - Executing: [set script timeoutt: 20000])
14:44:43.584 INFO - Executing: [delete session: 64c8dac4-559f-416d-b77b-78c5184b6538])
14:44:43.590 INFO - Done: [set script timeoutt: 20000]
14:44:45.303 INFO - Done: [delete session: 64c8dac4-559f-416d-b77b-78c5184b6538]
Test Error: This is the error I am getting where i am calling the Conf.js file from
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
[launcher] Error: TypeError: undefined is not a function
at
at Object.exports.run (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\frameworks\jasmine.js:6
2:17)
at C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:326:35
at _fulfilled (C:\Users\sr\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:
826:30)
at Promise.promise.promiseDispatch (C:\Users\ppData\Roaming\npm\node_modules\protractor\node_modules\q
\q.js:759:13)
[launcher] Process exited with error code 100

There is a typo inside onPrepare():
onPrepare: function() {
browser.driver.manage().window().maximize();
require('jasmine-reporters');
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true. true));
// HERE^
},
You meant instead:
jasmine.getEnv().addReporter(
new jasmine.JUnitXmlReporter('xmloutput', true, true));

Error: TypeError: undefined is not a function
at
at Object.exports.run (C:\Users\AppData\Roaming\npm\node_modules\protractor\lib\frameworks\jasmine.js:6
The error is from the library. I think you might missed some dependencies that the library requires.

Removing this line fixed a similar problem for me:
seleniumAddress: 'http://localhost:4444/wd/hub',

Related

Error 1 during test end to end

I am doing a angular exercise where i have to do a e2e test, when I run the protractor protractor.conf.js i have the following errors:
[launcher] Running 1 instances of WebDriver
(node:3032) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108
var template = new Error(this.message);
^
SessionNotCreatedError: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"6904.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=59.0.3071.86)
(Driver info: chromedriver=2.19.346078 (6f1f0cde889532d48ce8242342d0b84f94b114a1),platform=Windows NT 10.0 x86_64)
at new bot.Error (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
at Object.bot.response.checkResponse (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
at C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:160:24
at promise.ControlFlow.runInFrame_ (C:/Users/Aurora/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
at wrappedCtr.notify (C:/Users/Aurora/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
at promise.Promise.notify_ (C:/Users/Aurora/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
at Array.forEach (native)
at promise.Promise.notifyAll_ (C:/Users/Aurora/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
at goog.async.run.processWorkQueue (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
at <anonymous>
From: Task: WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:157:22)
at Function.webdriver.WebDriver.createSession (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:131:30)
at new Driver (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:810:36)
at DirectDriverProvider.getNewDriver (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\direct.js:68:16)
at Runner.createBrowser (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:182:37)
at C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:263:21
at _fulfilled (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
at C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:525:49
[launcher] Process exited with error code 1
Can anybody help me to figure out what's wrong?
I attach the file protractor.conf.js and the file that contain all the e2e tests that I execute on the application:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3001/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
'use strict';
describe('conFusion App E2E Testing', function() {
//Introduce the tests into this file
it('should automatically redirect to / when location hash/fragment is empty', function() {
browser.get('index.html');
expect(browser.getLocationAbsUrl()).toMatch("/");
});
//Set up a simple test for the index file to check if the page title is set correctly
describe('index', function() {
beforeEach(function() {
browser.get('index.html#/');
});
it('should have a title', function() {
expect(browser.getTitle()).
toEqual('Ristorante Con Fusion');
});
});
//We will navigate to the first menu item, and test a few properties there
describe('menu 0 item', function() {
beforeEach(function() {
browser.get('index.html#/menu/0');
});
it('should have a name', function() {
var name = element(by.binding('dish.name'));
expect(name.getText()).
toEqual('Uthapizza Hot $4.99');
});
it('should show the number of comments as', function() {
expect(element.all(by.repeater('comment in dish.comments'))
.count()).toEqual(7);
});
it('should show the first comment author as', function() {
element(by.model('critiria')).sendKeys('author');
expect(element.all(by.repeater('comment in dish.comments'))
.count()).toEqual(7);
var author = element.all(by.repeater('comment in dish.comments'))
.first().element(by.binding('comment.author'));
expect(author.getText()).toContain('25 Cent');
});
});
});
For a reason below, I've added Chromedriver Web Version 2.19 again and installed
Chrome version 44, I always get an error:
C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:172 callback(new Error(message)); ^ Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:55368 at ClientRequest.
<anonymous> (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\http\index.js:172:16) at emitOne (events.js:115:13) at ClientRequest.emit (events.js:210:7) at Socket.socketErrorListener (_http_client.js:399:9) at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7) at emitErrorNT (internal/streams/destroy.js:62:8) at _combinedTickCallback (internal/process/next_tick.js:102:11) at process._tickCallback (internal/process/next_tick.js:161:9) From: Task: WebDriver.createSession() at
Function.webdriver.WebDriver.acquireSession_ (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:157:22) at Function.webdriver.WebDriver.createSession (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:131:30)
at new Driver (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\chrome.js:810:36) at DirectDriverProvider.getNewDriver (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\direct.js:68:16)
at Runner.createBrowser (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:182:37) at C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:263:21 at _fulfilled (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30) at Promise.promise.promiseDispatch (C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13) at C:\Users\Aurora\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:525:49
[launcher] Process exited with error code 1
You are using:
Chromedriver version 2.19
Chrome version 59
These two are not compatible - you need ChromeDriver 2.30 to work with Chrome 59:
Latest Release: ChromeDriver 2.30
Supports Chrome v58-60
Update your ChromeDriver. Typically done via:
webdriver-manager update

gulp task works when called manually, but throws errors when called by gulp.watch

I am using gulp's built-in method gulp.watch to spy on changes in my Javascript files.
This is the buildJs task definition:
gulp.task('buildJs', function() {
var combined = combiner.obj([
gulp.src([
'./bower_components/jquery/dist/jquery.min.js',
'./bower_components/knockout/dist/knockout.js',
'./bower_components/lodash/lodash.min.js',
paths.dev.js + '**/*.js'
]),
sourcemaps.init(),
concat('all.js'),
sourcemaps.write('.'),
rename('all.min.js'),
gulp.dest(paths.pub.js)
]);
combined.on('error', console.error.bind(console));
return combined;
});
When I call the gulp buildJs manually, all works like a charm, no matter whether the file that is supposed to be created (all.min.js) already exists or not:
gulp buildJs
[16:21:40] Using gulpfile c:\src\portal\branches\octopus-working\Modules\gulpfile.js
[16:21:40] Starting 'buildJs'...
[16:21:40] Finished 'buildJs' after 124 ms
Process finished with exit code 0
When I assign this task to a watcher, it seems it properly calls buildJs task, but this time with a different outcome:
gulp watchJs
[16:15:44] Using gulpfile c:\src\portal\branches\octopus-working\Modules\gulpfile.js
[16:15:44] Starting 'watchJs'...
[16:15:44] Finished 'watchJs' after 16 ms
[16:15:56] Starting 'buildJs'...
{ [Error: UNKNOWN: unknown error, open 'c:\src\portal\branches\octopus-working\Modules\Static\Portal\js\all.min.js']
errno: -4094,
code: 'UNKNOWN',
syscall: 'open',
path: 'c:\\src\\portal\\branches\\octopus-working\\Modules\\Static\\Portal\\js\\all.min.js' }
[16:15:56] 'buildJs' errored after 107 ms
[16:15:56] Error: UNKNOWN: unknown error, open 'c:\src\portal\branches\octopus-working\Modules\Static\Portal\js\all.min.js'
at Error (native)
This is my watch definition:
gulp.task('watchJs', function() {
gulp.watch(paths.dev.js + '**/*.js', ['buildJs']);
});
And just for the sake of completeness, here's my paths object:
var paths = {
dev: {
scss: './assets/styles/',
js: './assets/scripts/',
html: './Templates/__DEV_static_html/'
},
pub: {
css: './Static/Portal/css',
js: './Static/Portal/js',
html: './Static/Portal'
}
};
So why does it work when called manually, but not when called by gulp.watch?

Protractor not testing, WebDriver fails after 1 minute

I'm really new to Protractor and everything NodeJS, and i'm trying to get started using Protractor with AngularJS.
I used the Yeoman generator-gulp-angular to generate a project and all is well, but when i try to protractor protractor.conf.js (i've installed Java and Chromium) the following happens:
vagrant#server:/var/www/html/project/$ protractor protractor.conf.js
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.103.173:38573/wd/hub
It hangs here for 1 minute, and then spurts out the following:
/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113
var template = new Error(this.message);
^
UnknownError: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Linux 3.13.0-24-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.69 seconds
Build info: version: '2.45.0', revision: '5017cb8', time: '2015-02-26 23:59:50'
System info: host: 'server', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-24-generic', java.version: '1.7.0_75'
Driver info: org.openqa.selenium.chrome.ChromeDriver
at new bot.Error (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:113:18)
at Object.bot.response.checkResponse (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/response.js:106:9)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:152:24
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
at notifyAll (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:442:7)
at resolve (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:420:7)
at fulfill (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:535:5)
at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:149:22)
at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:123:30)
at Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:294:22)
at DriverProvider.getNewDriver (/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
at Runner.createBrowser (/usr/local/lib/node_modules/protractor/lib/runner.js:180:37)
at /usr/local/lib/node_modules/protractor/lib/runner.js:257:21
at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)
at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
[launcher] Process exited with error code 1
And exits.
This is my protractory.conf.js:
'use strict';
var paths = require('./.yo-rc.json')['generator-gulp-angular'].props.paths;
exports.config = {
node_modules/protractor/config.json
capabilities: {
'browserName': 'chrome'
},
specs: [paths.e2e + '/**/*.js'],
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
I hope someone can help me out!
EDIT
I've added my (single) test code to provide more insight:
'use strict';
describe('The main view', function () {
var page;
beforeEach(function () {
browser.get('http://localhost:3000/index.html');
page = require('./main.po');
});
it('Should display the homepage', function() {
expect(page.header.getText()).toContain("Home");
});
});
And my Page Object file:
'use strict';
var MainPage = function() {
this.header = element(by.tagName('header'));
};
module.exports = new MainPage();

Mocha unit tests running with Karma - done() is not defined

I'm trying to get tests written with Mocha to work running Karma, and they sort of work, but I cannot use the done() method to implement async tests, which essentially makes the tools useless to me. What am I missing?
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '../..',
frameworks: ['mocha', 'requirejs', 'qunit'],
client: {
mocha: {
ui: 'bdd'
}
},
files: [
{pattern: 'libs/**/*.js', included: false},
{pattern: 'src/**/*.js', included: false},
{pattern: 'tests/mocha/mocha.js', included: false},
{pattern: 'tests/should/should.js', included: false},
{pattern: 'tests/**/*Spec.js', included: false},
'tests/karma/test-main.js'
],
exclude: [
'src/main.js'
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress', 'dots'],
port: 9876,
colors: true,
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_WARN,
autoWatch: true,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
test-main.js (configuring RequireJS)
var allTestFiles = [];
var pathToModule = function(path) {
return path.replace(/^\/base\//, '../').replace(/\.js$/, '');
};
Object.keys(window.__karma__.files).forEach(function(file) {
if (/Spec\.js$/.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
}
});
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/src',
paths: {
'should': '../tests/should/should',
'mocha': '../tests/mocha/mocha',
'pubsub': '../libs/pubsub/pubsub',
'jquery': '../libs/jquery/jquery-1.10.2',
'jquery-mobile': '//code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min'
},
// dynamically load all test files
deps: allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});
tests/fooSpec.js
define(['music/note'], function(Note) {
describe('nothing', function(done) {
it('a silly test', function() {
var note = new Note;
note.should.not.eql(32);
});
done();
});
...
Though this is a contrived example, it succeeds if I remove the done() call. As it is, I get:
Uncaught TypeError: undefined is not a function
at /Library/WebServer/Documents/vg/tests/mocha/fooSpec.js:8
This is the done() line. How/why is this not defined? I'm not understanding where else to configure Mocha (or with what options). Is there some sort of global namespace or meta-programming magic causing RequireJS to interfere with Mocha?
I'm running the tests in Chrome 33 on OS X 10.9.2, in case that is at all relevant. I've killed a ton of time on this and am ready to give up on automated testing :( -- had similar brick walls with QUnit/Karma/RequireJS and have not been able to find any alternative to successfully automate tests. I feel like an idiot.
In Mocha, the done callback is for it, before, after, beforeEach, afterEach. So:
describe('nothing', function() {
it('a silly test', function(done) {
var note = new Note;
note.should.not.eql(32);
done();
});
});
Here's the doc.
The test you are running in that example doesn't require the done() callback. It is not asynchronous. An example of when the done callback is need....
describe('Note', function() {
it('can be retrieved from database', function(done) {
var note = new Note();
cb = function(){
note.contents.should.eql("stuff retrieved from database");
done()
}
//cb is passed into the async function to be called when it's finished
note.retrieveFromDatabaseAsync(cb)
});
});
Your test should not have a done callback
describe('nothing', function() {
it('umm...', function() {
var note = new Note;
note.should.not.eql(32);
});
});
Only the 'it' function provides a done callback. describe does not. Your problem does not rest with karma. Your mocha tests are not defined correctly.
Holy %$##!
I would never in a million years have thought this would barf:
describe('nothing', function(done) {
it('umm...', function() {
var note = new Note;
note.should.not.eql(32);
});
done(); // throws error that undefined is not a function
});
But this works just fine:
describe('nothing', function(done) {
it('umm...', function() {
var note = new Note;
note.should.not.eql(32);
});
setTimeout(function() {
done(); // MAGIC == EVIL.
}, 1000);
});

Intern with Phantomjs GhostDriver

I'm trying to setup Intern to run with PhantomJS on a Windows 7 machine
Since now my setup is as follows:
demo test root/unit/tests/phantom.js:
define([
'intern!object',
'intern/chai!assert'
], function(registerSuite, assert) {
registerSuite({
name: 'PhantomTest',
'dummy': function () {
assert(true, "Works!");
}
});
});
Configuration file root/unit/intern.config.js:
define({
proxyPort: 9000,
proxyUrl: 'http://localhost:9000/',
capabilities: {
'selenium-version': '2.30.0'
},
environments: [
{
browserName: 'phantom'
}
],
maxConcurrency: 3,
useSauceConnect: false,
webdriver: {
host: 'localhost',
port: 4444
},
// used here
loader: {
},
suites: [ 'unit/tests/phantom.js' ],
functionalSuites: [ /* 'myPackage/tests/functional' */ ],
excludeInstrumentation: /^tests\//
});
By running this test and config in a browser it just works.
To run Intern with PhantomJS i execute:
phantomjs --webdriver=4444
And:
cd root
node node_modules\intern\runner.js config=unit/intern.config
The console running Phantomjs then returns:
[INFO - 2013-07-01T21:29:07.253Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 42ba5b50-e295-11e2-86f7-e331eb8b922d
While the other one outputs the following message without any further log:
Defaulting to "runner" reporter
Listening on 0.0.0.0:9000
Initialised phantomjs 1.9.1 on windows-7-32bit
Any hint on what i'm missing?
The reason for this is https://github.com/ariya/phantomjs/issues/10522; phantomjs is using an extremely old version of JavaScriptCore that has no Function.prototype.bind. Your best bet at this moment is to switch to using the geezer version of Intern, which should work properly in this older environment.

Categories

Resources