Set config's 'browsers' property in the command line in karma runner - angularjs

I usually use browsers=['PhantomJS'] for running my specs with karma because it's faster than chrome and I find a bit annoying when chrome opens the browser in front of the window on every boot.
But when I have a bug and I need to debug, I change karma.conf.js browsers to ['Chrome'].
I would like to set this property when I start karma, something like: 'karma start --browsers=[Chrome]'.
Is this posible?

you just have to use the --browsers parameter and it'll overide your config file browsers part.
$ karma start config/testacular.conf.js --browsers Chrome
where Chrome is the name of the browser or a path to a binary.
For example, I have only a small Qt browser configured. if I use the line above, it runs Chrome instead.
INFO [karma]: Karma server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 24.0 (Linux)]: Connected on socket id DxbVJNX0jIoe1CbaWf9V
Chrome 24.0 (Linux): Executed 74 of 74 SUCCESS (0.443 secs / 0.232 secs)
...
or, for example, I have firefox beta, aurora and release in my home. I run beta with:
$ karma start config/testacular.conf.js --browsers ~/firefox/firefox
$ karma start --help
Karma - Spectacular Test Runner for JavaScript.
START - Start the server / do a single run.
Usage:
karma start [<configFile>] [<options>]
Options:
--port <integer> Port where the web server is running.
--runner-port <integer> Port where the server is listening for runner.
--auto-watch Auto watch source files and run on change.
--no-auto-watch Do not watch source files.
--log-level <disable | error | warn | info | debug> Level of logging.
--colors Use colors when reporting and printing logs.
--no-colors Do not use colors when reporting or printing logs.
--reporters List of reporters (available: dots, progress, junit).
--browsers List of browsers to start (eg. --browsers Chrome,ChromeCanary,Firefox).
--capture-timeout <integer> Kill browser if does not capture in given time [ms].
--single-run Run the test when browsers captured and exit.
--no-single-run Disable single-run.
--report-slower-than <integer> Report tests that are slower than given time [ms].
--help Print usage and options.
--version Print current version.

Related

Problems facing while running codeception acceptance tests on Mac

I am using phpStorm IDE with composer and codeception to write selenium acceptance tests in my mac machine.But I couldn't able to run my tests.
I started my Selenium Stand alone jar and chromedriver in my mac machine using the below command.
java -Dwebdriver.chrome.driver="/Users/krishna/Downloads/chromedriverNewChrome" -jar selenium-server-standalone-3.141.59.jar
Below is the console information and not sure if the Chrome driver is running or not.
00:34:19.637 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
00:34:19.722 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-02-08 00:34:19.777:INFO::main: Logging initialized #348ms to org.seleniumhq.jetty9.util.log.StdErrLog
00:34:19.985 INFO [WebDriverServlet.] - Initialising WebDriverServlet
00:34:20.086 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
<?php
use \AcceptanceTester;
class IndexTest
{
public function _before(AcceptanceTester $I){}
// tests
public function tryToTest(AcceptanceTester $I)
{
$I->amOnUrl('http://codeception.com');
$I->amOnPage('/quickstart'); // moves to http://codeception.com/quickstart
}
}
acceptance.yml file
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost/'
window_size: false # disabled in ChromeDriver
port: 43008
browser: chrome
Running in the following way:
Go to PhpStorm>Run>EditConfiguration>Codeception>Select Type as acceptance tests and run it.
I see following error in the console after I run the tests.
Testing started at 00:50 ...
/usr/bin/php /private/var/folders/4v/cltv5gzs79n6v77b53zw52z00000gn/T/ide-codeception.php run --report -o "reporters: report: PhpStorm_Codeception_ReportPrinter" --no-ansi --no-interaction -c /Users/kabothu/PhpstormProjects/CodeCeptionAutomation/codeception.yml acceptance
Warning: Declaration of PhpStorm_Codeception_ReportPrinter::writeProgress($progress): void should be compatible with PHPUnit\TextUI\ResultPrinter::writeProgress(string $progress): void in /private/var/folders/4v/cltv5gzs79n6v77b53zw52z00000gn/T/ide-codeception_24_70.php on line 2
Codeception PHP Testing Framework v2.5.3
Powered by PHPUnit 7.5.3 by Sebastian Bergmann and contributors.
Running with seed:
Time: 148 ms, Memory: 8.00MB
No tests executed!
Process finished with exit code 0
You named your test class IndexTest, it would work if it extended PhpUnit\Framework\TestCase or Codeception\Test\Unit.
However your test code shows that you wanted to implement test in Cest format,
to get it working you must rename your test class to IndexCestand file to IndexCest.php.

Cannot start Chrome / Cannot start Firefox errors with Karma in Vagrant box Ubuntu 12.04

I am following the Angular Tutorial at https://docs.angularjs.org/tutorial/step_02.
I want to run the following command:
npm test
karma start karma.conf.js
And getting the following error:
> karma start karma.conf.js
WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/**/*.module.js" does not match any file.
WARN [watcher]: Pattern "/var/angularapp/angular-phonecat/app/!(bower_components)/**/*!(.module|.spec).js" does not match any file.
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
INFO [launcher]: Starting browser Firefox
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Firefox
INFO [launcher]: Trying to start Firefox again (1/2).
ERROR [launcher]: Cannot start Firefox
INFO [launcher]: Trying to start Firefox again (2/2).
17 08 2016 18:46:51.434:ERROR [launcher]: Cannot start Firefox
ERROR [launcher]: Firefox failed 2 times (cannot start). Giving up.
ERROR [launcher]: Cannot start Chrome
INFO [launcher]: Trying to start Chrome again (1/2).
ERROR [launcher]: Cannot start Chrome
[launcher]: Trying to start Chrome again (2/2).
[launcher]: Cannot start Chrome
ERROR [launcher]: Chrome failed 2 times (cannot start). Giving up.
karma.config.js:
browsers: ['Firefox', 'Chrome'],
I installed Firefox and Chrome using the following commands:
sudo apt-install chromium-browser
sudo apt-install firefox
And set the env variables in ~/.bachrc:
export FIREFOX_BIN=/usr/bin/firefox
export CHROME_BIN=/usr/bin/chromium-browser
I even typed the following command, but did not help:
source ~/.bashrc
My node version is 0.12.15 and npm is 2.15.1. Please note that this is a vagrant box that I am talking about.
Please help :)
Someone suggested that I should use Phantomjs instead! So I did it and below is what I did exactly and made the test pass:
Install PhantomJS:
sudo npm install -g phantomjs-prebuilt
Update the env variable by adding the following line to ~/.bashrc:
export PHANTOMJS_BIN=/usr/bin/phantomjs
Add the following line to devdependencies in package.json file within the project:
"karma-phantomjs-launcher": "^0.2.0",
Add the following line to karma.config.js file:
plugins: [
...
'karma-phantomjs-launcher',
...
]
And finally change the browsers in karma.config.js to be:
browsers: ['PhantomJS'],
However, I still do not know why Chrome and Firefox did not work, and Phantomjs did the job. The way I view it is my vagrant box is just an Ubuntu machine, and should not be different than any other machines! It would be great if someone explains to me the reasons. And please consider that I am a newbie.
I've posted an answer in the related thread:
Karma - Chrome failed 2 times (cannot start). Giving up
Basically, for me chrome was not able to start because fonts were missing.
The tests weren't running for me either. I changed the following in karma.conf.js to so that Karma would only try to use Chrome:
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-jasmine'
]
I'm assuming that not having Firefox installed on my machine was causing Karma to fail.

Can't start the karma server in angular

Hi I'm trying to get the test script running on the angular tutorial (step 2, writing and running test part 1) but I'm stuck at trying to run the karma server but when I run the command in the GitBash terminal I get this error
John#JOHN-PC ~/angular-phonecat ((step-2))
$ ./scripts/test.sh
Starting Karma Server (http://karma-runner.github.io)
-------------------------------------------------------------------
INFO [karma]: Karma v0.10.2 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
ERROR [launcher]: Cannot start Chrome
Can not find the binary C:\Users\John\AppData\Local\Google\Chrome\Applic
ation\chrome.exe
Please set env variable CHROME_BIN
any idea what this means
here's the link to the tutorial http://docs.angularjs.org/tutorial/step_02
As Cristian Ternus had already pointed out you will have to set the correct value of the CHROME_BIN env variable. Dont copy the path as it is provided in the comment. You will have to find out where crome.exe is present on your machine. Please refer http://bardevblog.wordpress.com/2013/07/28/setting-up-angularjs-angular-seed-node-js-and-karma/ which is a nice tutorial about running angular test cases. Step 8 in the tutorial is addressing your issue.
Do you have Google Chrome installed? If not, install it.
If it's installed, is it in that path (C:\Users\John\AppData\Local\Google\Chrome\Applic
ation\chrome.exe)?
If not, set the environment variable CHROME_BIN to the path of chrome.exe.

Access error running chrome from grunt test

I am trying to run karma tests on my angular project. I used yeoman to create the angular project. However when I am trying to run tests, I am getting following errors
grunt test
Running "clean:server" (clean) task
Running "concurrent:test" (concurrent) task
Running "coffee:dist" (coffee) task
Running "coffee:test" (coffee) task
Done, without errors.
Running "connect:test" (connect) task
Started connect web server on localhost:9000.
Running "karma:unit" (karma) task
INFO [karma]: Karma server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
WARN [watcher]: Pattern "/home/arpit/proj/proj1/views/test/mock/**/*.js" does not
match any file.
ERROR [launcher]: Cannot start Chrome
Error: spawn EACCES
INFO [launcher]: Trying to start Chrome again.
ERROR [launcher]: Cannot start Chrome
Error: spawn EACCES
INFO [launcher]: Trying to start Chrome again.
ERROR [launcher]: Cannot start Chrome
Error: spawn EACCES
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
I can run chrome from bash using same account successfully with which I am trying to run grunt test
Also, sudo grunt test is running fine.
On the Mac, it's important to set CHROME_CANARY_BIN
to binary file, not just to app package.
In my case, problem emerged from installing Chrome via brew cask, so I had to set
export CHROME_CANARY_BIN="/opt/homebrew-cask/Caskroom/google-chrome-canary/latest/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
In most cases you have to set a environment variable "CHROME_BIN" to point at your chrome.exe
Windows:
set CHROME_BIN=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Mac 10.7.5
I was able to set it using the following
export CHROME_BIN=/Applications/Chrome.app/Contents/MacOS/Google\ Chrome
You get to the exec file by right clicking on the .app and selecting the Show Package Contents option. Follow this down to the executable and click it. It brought up the path in the terminal.

how to make angularjs e2e-test auto reload after code change

when I run the e2e-testing, it does it job but then disconnects when the tests succeed. Is there a way to just have it continuously test?
./scripts/e2e-test.sh
Starting Testacular Server (http://vojtajina.github.com/testacular)
-------------------------------------------------------------------
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser Chrome
info (Chrome 24.0): Connected on socket id E1loZJU6dCI4eyW9ewyo
Chrome 24.0: Executed 3 of 3 SUCCESS (1.027 secs / 0.697 secs)
info: Disconnecting all browsers
In your testacular/karma config, change/add
autoWatch = True
singleRun = False
You can find the config by opening up your ./scripts/e2e-test.sh and where it says testacular start or karma start the file name should be there. I'm assuming you are using the angular seed or tutorial, in which case the file is located at the config folder usually under something.conf.js

Resources