Karma isn't finding unit tests in *Spec.js - karma-runner

For some reason when I run this Karma.conf the test runner runs without errors but it doesn't actually run any of my tests in the *Spec.js files. Any ideas?
// Karma configuration
// Generated on Fri Jan 03 2014 12:02:32 GMT+0000 (GMT)
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'../../root/angular/angular.js',
//'angular/angular-mocks.js',
'../../root/angular/**/*.js',
// 't/js/angularTest/process/filtersSpec.js',
'angularTest/**/*Spec.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress',"coverage"],
preprocessors:{
'**/*.js':'coverage'
},
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// 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
});
};
this is my output from Karma if it helps:
/usr/bin/node /home/me/Desktop/WebStorm-131.515/plugins/js-karma/js_reporter/karma-intellij/lib/intellijRunner.js --karmaPackageDir=/usr/lib/node_modules/karma --serverPort=9876 --urlRoot=/
Testing started at 10:04 ...
Empty test suite.
Process finished with exit code 0

the solution is to not import an angular file:
angular-scenario.js

Related

WebdriverIO can not create session to test Android emulator with Appium

I am using Visual Studio Code and WDIO with Appium to test Android on emulator by Android Studio, but I can not run Appium for some reason. However Android home and Java home has been set and Appium Doctor confirms necessary dependencies are completed, no fix needed.
I have tried with Appium stand-alone and from Command too.
Wit Appium standalone the ERROR log is the below:
ERROR webdriver: Request failed with status 500 due to session not created: Unable to create session from {
"desiredCapabilities": {
"platformName": "android",
"appium:deviceName": "Pixel",
"appium:platformVersion": "10.0",
"appium:app": "\u002fUsers\u002fzsolt\u002fappium_js\u002fApiDemos-debug.apk"
If I add ['appium'] to services in wdio.config.js the ERROR log is the below, though Appium stand-alone is shut:
ERROR #wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: Appium exited before timeout (exit code: 2)
[HTTP] Could not start REST http interface listener. The requested port may already be in use. Please make sure there is no other instance of this server running already.
at ChildProcess.<anonymous> (C:\Users\zsolt\Documents\AppiumTestProject\node_modules\#wdio\appium-service\build\launcher.js:103:16)
at Object.onceWrapper (events.js:417:26)
at ChildProcess.emit (events.js:310:20)
at ChildProcess.EventEmitter.emit (domain.js:482:12)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
This is my wdio.config.js file with using Appium stand-alone:
exports.config = {
runner: 'local',
port: 4723,
specs: [
'./test/specs/**/*.js'
],
exclude: [
// 'path/to/excluded/files'
],
maxInstances: 10,
capabilities: [{
platformName: 'android',
'appium:deviceName': 'Pixel',
'appium:platformVersion': '10.0',
'appium:app': '/Users/zsolt/appium_js/ApiDemos-debug.apk'
}],
logLevel: 'error',
bail: 0,
baseUrl: 'http://localhost',
waitforTimeout: 10000,
connectionRetryTimeout: 120000,
connectionRetryCount: 3,
services: ['selenium-standalone',
/*['appium', {
//command : 'appium'
}]*/],
reporters: ['spec'],
mochaOpts: {
ui: 'bdd',
timeout: 60000
},
These are my:
"devDependencies": {
"#wdio/local-runner": "^6.1.11",
"#wdio/mocha-framework": "^6.1.8",
"#wdio/selenium-standalone-service": "^6.0.16",
"#wdio/spec-reporter": "^6.1.9",
"#wdio/sync": "^6.1.8",
"appium": "^1.17.1"
Has anybody an idea what am I doing wrong?
Welcome to Stack-overflow!
Below is my configuration and I believe you are missing some important details.
{
platformName: 'Android',
maxInstances: 1,
'appium:deviceName': 'Device Name',
'appium:platformVersion': '8'
'appium:orientation': 'PORTRAIT',
'appium:app': 'Path to App',
'appium:automationName': 'UiAutomator2',
'appium:noReset': true,
'appium:newCommandTimeout': 240,
}
There are boilerplates from maintainers themselves here.
I have played with the boilerplates and was able to run the tests on android emulator through Appium finally.
I have then compared the differences in conf.js and figured out, the below is needed to execute the test.
services:[
[
'appium',
{
// For options see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
args: {
// For arguments see
// https://github.com/webdriverio/webdriverio/tree/master/packages/wdio-appium-service
},
command: 'appium',
},
],
],
Interesting but actually the test runs with only the below capabilites too:
capabilities: [{
platformName: 'Android',
'appium:deviceName': 'Pixel 2',
'appium:app': join(process.cwd(), './ApiDemos/ApiDemos-debug.apk'),
}],
When I execute the test it logs almost the same error messages as before though at the end of the execution it runs the test on the emulator. I did not use the Appium Desktop app.
Not perfect but works...
I guess this issue has been sorted out.
Cheers
Also you need to install the Appium service:
$ npm i #wdio/appium-service --save-dev
Finally check in your wdio.conf.js:
port: 4723, // default appium port
services: [
[
'appium',
{
args: {
},
command: 'appium'
}
]
],
Check that the file you are running is inside the correct folder when you do the 'npx wdio'.
this file

How can I fail Karma tests if there are unhandled rejections?

A couple of places propose this solution:
window.addEventListener('unhandledrejection', function(err) {
window.__karma__.error(err); // yeah private API ¯\_(ツ)_/¯
});
But it throws:
Uncaught TypeError: Cannot read property 'error' of undefined
I'm able to get reports of unhandled rejections with the following setup:
karma.conf.js:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha'],
files: [
'setup.js',
'test.js',
],
exclude: [],
preprocessors: {},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
});
};
setup.js:
window.addEventListener('unhandledrejection', function(ev) {
window.__karma__.error("unhandled rejection: " + ev.reason.message);
});
test.js:
it("test 1", () => {
Promise.reject(new Error("Q"));
});
it("test 2", (done) => {
setTimeout(done, 1000);
});
Separating setup.js from test.js is not necessary. I just like to have such setup code separate from the tests proper.
When I run karma start --single-run I get:
25 01 2017 07:20:07.521:INFO [karma]: Karma v1.4.0 server started at http://0.0.0.0:9876/
25 01 2017 07:20:07.523:INFO [launcher]: Launching browser Chrome with unlimited concurrency
25 01 2017 07:20:07.528:INFO [launcher]: Starting browser Chrome
25 01 2017 07:20:08.071:INFO [Chrome 55.0.2883 (Linux 0.0.0)]: Connected on socket g-BGwMfQLsQM128IAAAA with id 22107710
Chrome 55.0.2883 (Linux 0.0.0) ERROR
unhandled rejection: Q
Chrome 55.0.2883 (Linux 0.0.0): Executed 1 of 2 ERROR (0.006 secs / 0.001 secs)
Caveat
Reports of unhandled rejections are asynchronous. This has a few consequences.
The example I gave has a 2nd test that takes 1 second to complete. This gives time to the browser to report the unhandled rejection in the 1st test. Without having this delay, Karma terminates without detecting the unhandled rejection.
Another issue is that an unhandled rejection caused by test X may be discovered while test X+1 is running. The runner's report may make it look like X+1 is the test the caused the issue.

Error on protractor: "Timed out waiting for the WebDriver server at http://127.0.0.1:50636/hub" executing on firefox

I was executing my scripts on firefox and got one notification for Firefox upgrade which I closed. Started execution again but I'm getting error as below,
Rohits-MacBook-Pro:FFAutomation rohitgathibandhe$ /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/bin/protractor conf.js
Report destination: target/screenshots/Report.html
Using FirefoxDriver directly...
[launcher] Running 1 instances of WebDriver
/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:50636/hub
at Error (native)
at onError (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/http/util.js:83:11)
at Promise.invokeCallback_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1329:14)
at TaskQueue.execute_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2790:14)
at TaskQueue.executeNext_ (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2773:21)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2652:27
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:639:7
at process._tickCallback (node.js:406:9)
From: Task: WebDriver.createSession()
at acquireSession (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:62:22)
at Function.createSession (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:295:12)
at Driver (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/selenium-webdriver/firefox/index.js:271:38)
at [object Object].DirectDriverProvider.getNewDriver (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/driverProviders/direct.js:76:16)
at [object Object].Runner.createBrowser (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/runner.js:203:37)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/built/runner.js:293:21
at _fulfilled (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:834:54)
at self.promiseDispatch.done (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:863:30)
at Promise.promise.promiseDispatch (/Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:796:13)
at /Users/rohitgathibandhe/npm-global/lib/node_modules/protractor/node_modules/q/q.js:556:49
[launcher] Process exited with error code 1
My config file is as below,
var HtmlScreenshotReporter = require('protractor-jasmine2-screenshot-reporter');
var reporter = new HtmlScreenshotReporter({
dest: 'target/screenshots',
filename: 'Report.html',
reportTitle: 'Execution Report',
showSummary: true,
showQuickLinks: true,
pathBuilder: function(currentSpec, suites, browserCapabilities) {
// will return chrome/your-spec-name.png
return browserCapabilities.get('browserName') + '/' + currentSpec.fullName;
}
});
exports.config = {
directConnect: true,
//seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {'browserName': 'firefox'},
framework: 'jasmine',
specs: ['Login_spec2.js','Article_spec.js'],
allScriptsTimeout: 200000,
getPageTimeout: 200000,
jasmineNodeOpts: {
defaultTimeoutInterval: 200000
},
// Setup the report before any tests start
beforeLaunch: function() {
return new Promise(function(resolve){
reporter.beforeLaunch(resolve);
});
},
// Close the report after all tests finish
afterLaunch: function(exitCode) {
return new Promise(function(resolve){
reporter.afterLaunch(resolve.bind(this, exitCode));
});
},
onPrepare: function() {
var width = 1300;
var height = 1200;
browser.driver.manage().window().setSize(width,height);
jasmine.getEnv().addReporter(reporter);
afterAll(function(done) {
process.nextTick(done);
})
}
};
Other details are:
Other details are as below: protractor#3.2.2, nodeVersion: 4.2.4, npmVersion: 2.14.12, jasmine: 2.4.1, selenium-webdriver: 2.52.0, firefox: 47
Kindly help me with solution to this issue.
You have to do the following to make it work:
upgrade protractor to the latest, currently 3.3.0, version which would also bring selenium-webdriver 2.53
downgrade firefox to version 46 and don't let it update for a while (there are compatibility issues)
In my case it was the local firewall (iptables on Linux) that was very restrictive such that WebDriver could not contact the Selenium server hub at whatever TCP port.
To make it work I turned off the firewall. The long term solution was to adjust the firewall rules such that this type of connection is allowed.
If you want your scripts communicate directly with the Firefox|Chrome Driver (bypassing the Selenium server entirely) then try adding the directConnect: true in your protractor.conf.js
I solved it by change the browser (use Chrome instead of Firefox).
In C:__projectWorkspace__\src\test\javascript\protractor.conf.js
modify the entry
capabilities: {
'browserName': 'firefox',
to
capabilities: {
'browserName': 'chrome',
That wasn't enough. I had to change also the webBrowserDriver 'cause after the JHipster installation the 2.22 version was written in protractor.conf.js file but in the path:
node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.25.exe
the chromedriver was 2.25 version so i edited the entry
webbrowserDriver = prefix + 'node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.25.exe';
and it worked!
I solved this by restarting the computer.
I don't know why, but I think that "suspending" the computer can cause some bad configuration with Selenium Server.
Ah, I run commands on the command prompt as an administrator.
I fixed this issue by changing directConnect to true in base.config.js from repository folder.
or
webdriver-manager clean and then webdriver-manager start

I'm not able to run protractor test in firefox but in chrome it runs fine

When I am trying to run Protractor e2e test in firefox, it launches the browser but my test scripts do not get executed.
I am using windows Server 2012 R2 machine with firefox version 46.0.1 and Selenium 2.53.0.
It gives me the following error:
Using FirefoxDriver directly...
[launcher] Running 1 instances of WebDriver
code\ui\dgui\node_modules\protractor\node_modules\selenium-webdriver\http\util.js:89
Error('Timed out waiting for the WebDriver server at ' + url));
^
Error: Timed out waiting for the WebDriver server at http://127.0.0.1:58798/hub
I tried running Selenium standalone
code\ui\dgui\node_modules\protractor\selenium>java -jar selenium-server-standalone-2.53.0.jar
09:37:21.214 INFO - Launching a standalone Selenium Server
09:37:21.285 INFO - Java: Oracle Corporation 25.91-b14
09:37:21.285 INFO - OS: Windows Server 2012 R2 6.3 amd64
09:37:21.293 INFO - v2.53.0, with Core v2.53.0. Built from revision 35ae25b
09:37:21.332 INFO - Driver class not found: com.opera.core.systems.OperaDriver
09:37:21.332 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
09:37:21.336 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN8
09:37:21.336 INFO - Driver class not found: org.openqa.selenium.htmlunit.HtmlUnitDriver
09:37:21.336 INFO - Driver provider org.openqa.selenium.htmlunit.HtmlUnitDriver is not registered
09:37:21.434 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
09:37:21.434 INFO - Selenium Server is up and running
I am using npm run e2e command to execute my test
my Config file:
exports.config = {
allScriptsTimeout: 30000,
suites: {
test Suit: 'e2e/TestSuites/Tests/*.js',
},
multiCapabilities: [
// We will want to eventually include the following options to split out tests to multiple instances
{'browserName': 'firefox'}
],
// only for firefox and chrome - IE will require using a selenium server
directConnect : true,
// make sure that the baseURL reflects the configuration of the web server
baseUrl: 'http://10.26.5.13:8000/',
framework: 'jasmine2',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
onPrepare: function() {
var jasmineReporters = require('jasmine-reporters');
browser.driver.manage().window().maximize();
return browser.getProcessedConfig().then(function(config) {
var browserName = config.capabilities.browserName;
var junitReporter = new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: 'tests/test-results',
// this will produce distinct xml files for each capability
filePrefix: browserName + '-xmloutput',
modifySuiteName: function(generatedSuiteName, suite) {
// this will produce distinct suite names for each capability,
// e.g. 'firefox.login tests' and 'chrome.login tests'
return browserName + '.' + generatedSuiteName;
}
});
jasmine.getEnv().addReporter(junitReporter);
});
},
resultJsonOutputFile: 'tests/test-results/output.json'
};
Found this link: https://github.com/angular/protractor/issues/3182,
I was also facing similar issue.
I tried installing Firefox v44.0.2 and then executed my scripts, it worked.
I was using Firefox v46 earlier, and my scripts were not executing with Firefox v46.
Had the same problem with firefox version 49.0.2 and Selenium 2.52.0
I installed Firefox portable 46 and everything worked for me.
And in my protractor.config-file i set:
...
capabilities: {
// FIREFOX portable in version 46.0.1
'browserName': 'firefox',
"firefox_binary": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe",
"binary_": "C:/DEV/FirefoxPortable64-46.0.1/FirefoxPortable64/FirefoxPortable.exe"
},
// tells protractor to directly connect to the webdriver
directConnect: true
...
I downloaded Firefox Portable here: http://www.m64.info/index.php/firefox-64-bit-portable
That's also a good opportunity to have more than one version of firefox "installed" :-)
Hope somebody will help it!
Follow Protractor setup here:
http://www.protractortest.org/#/tutorial#setup
These versions are what worked for me:
Node: v6.9.4
NPM: v3.10.10
Protractor: v5.1.0
Selenium WebDriver: 3.0.1
Firefox: 51.0.1
conf.js:
exports.config = {
framework: 'jasmine',
// no need for seleniumAddress for firefox and chrome
specs: ['spec.js'],
capabilities: {
browserName: 'firefox',
firefoxPath: 'C:/Program Files/Mozilla Firefox/firefox.exe'
},
directConnect: true // for firefox and chrome
}
https://github.com/angular/protractor/blob/master/lib/config.ts
Add the binary (firefox.exe) location as moz:firefoxOptions capability
exports.config = {
capabilities: {
browserName: 'firefox',
shardTestFiles: false,
'moz:firefoxOptions': {
'binary': "<your_path>/Mozilla Firefox/firefox.exe"
}
},

Karma preprocessor not running

My karma.conf.js includes:
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-ng-html2js-preprocessor'
],
preprocessors: {
'../../mypath/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
moduleName: 'templates'
},
(I've tried without specifying any plugins, too.)
My devDependencies include:
"karma-ng-html2js-preprocessor": "^0.2.0"`
My tests include:
beforeEach(module('templates'));
These give the error:
Module 'templates' is not available!
Running karma with --log-level debug, I do not see any [preprocessor.html2js] entries. (I do get Loading plugin karma-ng-html2js-preprocessor.)
What am I doing wrong?
The issues were that the templates must be listed under files as well, and that the glob pattern in preprocessors must match. This is implied by the documentation.
files: [
'../../Scripts/angular-app/directives/*.html',
// .js files
],
preprocessors: {
'../../Scripts/angular-app/**/*.html': ['ng-html2js']
},
Note that **/*.html does not match parent directories of the basePath.
karma start --log-level debug will display DEBUG [preprocessor.html2js] entries when everything is correct.
I was also able to remove the plugins section.
To get the correct cache ID, I used:
ngHtml2JsPreprocessor: {
// Load this module in your tests of directives that have a templateUrl.
moduleName: 'templates',
cacheIdFromPath: function (filepath) {
return filepath.substring(filepath.indexOf('/Scripts/angular-app/'));
}
},
If a template references a custom filter, the filter must be loaded in files and the filter's module must be loaded in your directive tests.