I am new to Karma. When i run:
karma start myconfigfile.js
Karma is starting up with chrome, but it hangs at karma starting and nothing more is happening. However i can go into http://localhost:9876/debug.html and can see that tests have been running in console. My test is inside vendor/Jasmine/spec/PlayerSpec.js.
Is this the correct way of using karma for testing or are there some more UI-frendly ways?
Because I can see that karma window should look like this.
Have anyone had same problem?
here is my config file:
module.exports = function(config) {
config.set({
basePath: '/',
frameworks: ['jasmine'],
files: [
'nodejs/node_modules/karma-jasmine/lib/jasmine.js',
'nodejs/node_modules/karma-jasmine/lib/adapter.js',
'nodejs/node_modules/requirejs/*.js',
'vendor/Jasmine/spec/PlayerSpec.js',
'angular/angular.min.js',
'angular/angular-mocks.js'
],
exclude: [
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_DEBUG,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
Karma is made of two main components: a server and a runner.
The first one prepare the test environment and spawn the browsers, but is the second one that starts the tests.
To start the server you have to run karma start, while for the second one you have to start in a second shell karma run <configuration_file_path> - try it and see the tests running.
If you want to start it automatically, just change this line in your config file:
singleRun: true // => is was false
At this point Karma will setup the server, run the tests and shutdown when completed.
Related
Have a very strange issue with Monaco Editor. When developing, and running NPM RUN WATCH, editor displays perfectly in browser. After running NPM RUN PROD, the view breaks. See below. I have tried everything to resolve this, webpack changes, CSS changes, Moved out of Patternfly Code Block elements.
The only error I get after NPM RUN PROD in the console is
'Element already has context attribute: pf-c-code-editor__code-pre'
Ignoring the actual attribute, I get the same error when attribute is present. I think this is a red herring though.
Running VUE3, Laravel, latest Monaco. Sample editor code below
See any tips or advice and what to do next?
const codeEditorDiv = document.getElementById('pf-c-code-editor__code-pre');
meditor = monaco.editor.create(codeEditorDiv, {
value: meditorValue.value,
language: language.value || 'javascript',
lineNumbers: lineNumbers.value,
roundedSelection: false,
readOnly: false,
theme: darkmode.value,
scrollBeyondLastLine: true,
wordWrap: 'on',
wrappingStrategy: 'advanced',
automaticLayout: true,
minimap: {
enabled: false
}
});
Updated Screenshots, before (NPM RUN DEV) and after (NPM RUN PROD)
I have to run Jasmine tests in headless mode and I could find PhantomJS Laucher but the project has been suspended PhantomJS
Is there any other way to run Jasmine tests in headless mode? If so, please point me to helpful docs, posts etc.
I found a nice post. You can use HeadlessChrome for the headless mode.
ng test --browsers ChromeHeadless
It is also possible to change the karma and protractor configuration to create a custom laucher or to change the capabilities for the chrome browser.
Protractor configuration you can make necessary changes
Run in it on Chrome Headless using below config
capabilities = {
browserName: 'chrome',
chromeOptions: {
args: ['--headless', '--no-sandbox']
}
};
Run in on Firefox as headless using below config
capabilities: {
browserName: 'firefox',
firefoxOptions: {
args: ['--headless']
}
}
I am using protractor 1.3.1 and running iedriverserver.exe 2.43.0.0 with IE11 installed (windows).
This is my spec:
describe('quick test IE driver', function () {
it('should go to ng homepage', function () {
browser.driver.get('https://angularjs.org/');
var title =element(by.css('h1')).getText();
expect(title).toBe('HTML enhanced for web apps!');
});
});
And this is my protractor.conf.js:
exports.config = {
// The address of a running selenium server.
//seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'internet explorer',
'platform': 'ANY',
'version': '11'
},
// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['main.spec.js'],
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose:true,
includeStackTrace:true
}
};
getting this error though, any ideas for a solution:
UnknownError: The path to the driver executable must be set by the webdriver.ie.driver system property;
Update web manager for IE
First step is to update the ie webdriver using webdriver manager.Open command prompt and run the command given below
webdriver-manager update --ie
Go to npm location In this step move to the NPM_LOCATION(folder where npm is installed at your system. Move to the following path "NPM_LOCATION\node_modules\protractor\selenium" At this location check that IEDriverServer.exe is present or not.
Change for IE in conf.js
// conf.js exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['specs.js'], capabilities: {
'browserName': 'internet explorer' // conf for internet explorer } }
// spec.js describe('Protractor Demo App', function() { it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator'); }); });
Now run protractor conf.js
Note: Make sure you restart server by -->webdriver-manager start
taken from: http://protractorsupport.blogspot.com/2015/05/use-protractor-with-internet-explorer.html
According to the protractor config doc, the config value "seleniumArgs" is deprecated.
So, to have a single answer with all the info, here are the simplified steps:
Install Protactor globally:
npm install -g protractor
Run webdriver-manager update --ie to update the Selenium drivers that Protactor uses. Be aware if you are running the global webdriver-manager or the local webdriver-manager (i.e ./node_modules./bin/webdriver-manager update help); they will unzip the drivers at separate locations; only the local will unzip in [Project dir]
Take a look at the log of the previous command. It must show that the drivers were unzipped at a particular folder. Go to that folder and locate the IEDriverServer. In my case it was: "[Project dir]\node_modules\protractor\node_modules\webdriver-manager\selenium\IEDriverServer_x64_X.XX.X.exe. You will need to give the relative path to this file in the next step.
Inside your conf.js file, add the following keys & values. Note the use of localSeleniumStandaloneOpts, which means you should remove the property seleniumAddress if you have it:
multiCapabilities : [
{
'browserName' : 'chrome'
}, {
'browserName' : 'internet explorer'
}
],
localSeleniumStandaloneOpts : {
jvmArgs : ["-Dwebdriver.ie.driver=<RELATIVE PATH TO IE DRIVER>"] // e.g: "node_modules/protractor/node_modules/webdriver-manager/selenium/IEDriverServer_x64_X.XX.X.exe"
},
That was all I needed to do. I don't start the server beforehand, I simply run protactor conf.js. Easier now, I guess.
Download the IEDriverServer.exe
Please specify the same in your config file
seleniumArgs: ['-Dwebdriver.ie.driver=<path to IEDriverServer.exe>']
I was looking around this question for few hours, the best way seems to be:
1) download
webdriver-manager --ie update
This should download the driver from the google.. selenium ... release folder and place it directly in the good place in your npm local repository.
2) setup in config.js file of your tests:
...
multiCapabilities: [
//{
// browserName: 'chrome',
// version: 'ANY'
//},
//{
// browserName: 'firefox',
// version: 'ANY'
//},
{
browserName: 'internet explorer',
version: 'ANY'
},
],
// For some IE functions you may need to specify defaultTimeoutInterval
...
3) setup IE:
follow this post
http://jimevansmusic.blogspot.fr/2012/08/youre-doing-it-wrong-protected-mode-and.html
PS: about the "protected mode" setup of IE, it's important to have the same setup for all zones. I prefer to have protected mode 'on' for all zone
4) patch the registry
as described here: http://heliumhq.com/docs/internet_explorer
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BFCACHE]
"iexplore.exe"=dword:00000000
5) IE 11 update break the way the system work:
My lastest issue was "the server did not provide any stack trace ...." this is due to an update of the 17th of Dec 2014. Uninstall it and then it's good.
https://code.google.com/p/selenium/issues/detail?id=3390
crazy path to make it running. It cannot be like this for a long run, please comment my post with your experiences/feedbacks.
Richard
Here is my config file:
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
capabilities: {
'browserName': 'internet explorer',
},
framework: 'jasmine',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['your_spec_file.js'],
};
The steps to run in IE :
Need two terminals in Visual Studio Code,
In the first terminal, Run command "webdriver-manager start" to start selenium server.
In the second terminal, Run your js config file as :
Protractor conffile_name.js
This will successfully start Internet explorer.
Thanks
I downloaded this vagrant selenium grid setup from GitHub, and tried it out as is. I can get my protractor tests working with the default firefox instances, but I am getting errors when trying to test on the chrome instances. Here is the log output from the node vm's node.log file when I try to run a test with chrome.
I have tried using openjdk 6 & 7, and have tried the latest chromedriver (64Bit) as well as chromedriver 2.9 & 2.8, and tried the latest versions of the selenium-sever-standalone jar file.
I am using protractor 0.23.1 at the moment. Here is my protractor config file:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
chromeOnly: false,
splitTestsBetweenCapabilities: true,
specs: ['./e2e/**/*pec.js'],
multiCapabilities: [{
'browserName': 'firefox',
'platform': 'LINUX',
'maxInstances': 2,
}, {
'browserName': 'chrome',
'platform': 'ANY',
'maxInstances': 2
}],
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
includeStackTrace: true,
defaultTimeoutInterval: 30000
}
};
I have also tried adding the flags below to the script in the conf/upstart/selenium-node.conf file, but chrome still wont startup (same message as in log above).
-browser "browserName=chrome" -Dwebdriver.chrome.driver="/usr/bin/chromedriver"
Does anybody have this setup running with chrome? Or can you see what the problem is here? Any advice could be helpful.
Try opening an issue in that selen repository since the provided vagrant doesn't seem to work out of the box.
Overall seems your goal here is to run selenium+chrome headless.
Take a look at my answer here.
I am using grunt and I'm trying to get the watch/livereload task to run on my local server (MAMP) but with no success.
I'm calling the task based on HTML5 Boilerplate grunt files (https://github.com/h5bp/html5boilerplate.com/blob/master/Gruntfile.js, https://github.com/h5bp/html5boilerplate.com/blob/master/package.json).
I have also tried implementing Tiny-lr (https://github.com/mklabs/tiny-lr) without success either.
My connect and watch options right now are this
connect: {
options: {
hostname: 'localhost',
livereload: 35729,
port: 8888
},
livereload: {
options: {
base: '../',
open: true
}
},
},
watch: {
files: '<%= settings.dir.src %>/**',
less: {
files: ['src/less/*.less'],
tasks: ['less'],
},
options: {
livereload: '<%= connect.options.livereload %>'
},
scripts: {
files: ['<%= settings.dir.src %>/js/*.js', 'css/**/*.scss' ],
tasks: 'default',
options: {
spawn: false,
}
}
}
And here I declare the dev task:
// development task
grunt.registerTask('dev', [
'connect:livereload',
'watch'
]);
When I run 'grunt dev' my browser opens at http://127.0.0.1:8888/ and displays only this: Cannot GET /
I need my browser to open http://localhost:8888/ctrl/ (ctrl being the name of the folder project on MAMP, could be anything), I thought that changing the "base" option was the way to go but nope, it is not, and I cannot add "/ctrl" to host name either, nor to the port.
Any ideas?
Thank you
Here is a link to my whole code: https://github.com/zolitariuz/ctrl
i think you are misunderstanding 2 tasks in grunt,
the connect task is used to create a http server spawned by node js, so no php nor mysql support, you DON'T want to run you WP site thru that.
the watch task is looking for changes in files on YOUR computer, launching the according task after a file change, then trigger the live reload.
you should remove connect completely after you copied the live reload object in your watch task.
the you should run your local lamp stack for running wp then start the watch task for file changes.
on the wp side you should enqueue the live reload script, or use a browser extension that will inject it for you.