Angular 5 karma unit test bug - karma-jasmine

When I do karma unit test in Angular5, I have some issues.
Chrome 63.0.3239 (Windows 7 0.0.0): Executed 3 of 29 SUCCESS (0 secs /
2.516 secs) Chrome 63.0.3239 (Windows 7 0.0.0) ERROR Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to
load
'ng:///DynamicTestModule/FollowersItemComponent_Host.ngfactory.js'.
Chrome 63.0.3239 (Windows 7 0.0.0) ERROR Uncaught NetworkError:
Failed to execute 'send' on 'XMLHttpRequest': Failed to load
'ng:///DynamicTestModule/FollowersItemComponent_Host.ngfactory.js'.
at http://localhost:9876/_karma_webpack_/polyfills.bundle.js:2281
Chrome 63.0.3239 (Windows 7 0.0.0): Executed 3 of 29 ERROR (0 secs /
2.516 secs) Chrome 63.0.3239 (Windows 7 0.0.0) ERROR Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to
load
'ng:///DynamicTestModule/FollowersItemComponent_Host.ngfactory.js'.
Chrome 63.0.3239 (Windows 7 0.0.0): Executed 3 of 29 ERROR (2.546 secs
/ 2.516 secs)
I am not sure why this problem happened.
Please help me. Thanks.

I don't know if you managed this, but this errors could come from any input the component is waiting :)
If you have #Input() in your component, then you need to provide this input in your tests. Usually you can do it in beforeEach method :
beforeEach(() => {
fixture = TestBed.createComponent(YourComponent);
component = fixture.componentInstance;
component.yourInput = 'anyInput'
});

Related

Getting error in jenkins with test coverage after upgrading from Angular 9 to Angular14

Can someone please point me how to debug this issue further. Get below error when jenkins job is run and the application is one Angular 14.
[32m13 10 2022 23:01:01.881:INFO [karma-server]: [39mKarma v6.4.1 server started at http://localhost:9876/
[32m13 10 2022 23:01:01.884:INFO [launcher]: [39mLaunching browsers ChromeHeadless with concurrency unlimited
[32m13 10 2022 23:01:01.887:INFO [launcher]: [39mStarting browser ChromeHeadless
[32m13 10 2022 23:01:03.202:INFO [Chrome Headless 63.0.3239.132 (Linux x86_64)]: [39mConnected on socket ajz1GfKScPy5uAgXAAAB with id 803388
Chrome Headless 63.0.3239.132 (Linux x86_64): Executed 0 of 0[32m SUCCESS[39m (0 secs / 0 secs)
[1A[2K[31mChrome Headless 63.0.3239.132 (Linux x86_64) ERROR[39m
An error was thrown in afterAll
Uncaught SyntaxError: Unexpected token {
SyntaxError: Unexpected token {
Uncaught SyntaxError: Unexpected token .
SyntaxError: Unexpected token .

Selenium-side-runner failing with `New window did not appear before timeout`

I am trying to run a selenium IDE script (.side) from the command line using side-runner. Currently, the test runs successfully from the IDE, and appears to work successfully from the command line but then fails, throwing: New window did not appear before timeout.
This is my Selenium IDE test. The test is included in the default suite so it should be run. However, when I run it from the command line with:
$ selenium-side-runner -c "browserName=firefox" firefox-test.side
I get:
info: Running firefox-test.side
FAIL ./DefaultSuite.test.js (12.71s)
Default Suite
✕ wikipedia (9332ms)
● Default Suite › wikipedia
New window did not appear before timeout
5 | return hndls.find(h => (!handles.includes(h)));
6 | }
> 7 | throw new Error("New window did not appear before timeout");
| ^
8 | }
9 |
10 | module.exports = {
at Object.waitForWindow (utils.js:7:9)
at Object.<anonymous>.tests.wikipedia (commons.js:34:18)
at Object.<anonymous> (DefaultSuite.test.js:11:5)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 13.353s
Ran all test suites.
However, I can see the firefox window and the tests appear to be working. The window closes, then a new firefox window appears and the error is thrown. I have tried increasing the timeout:
$ selenium-side-runner --timeout 600000 -c "browserName=firefox" firefox-test.side
with the same error. Any ideas?

use normal browser profile as selenium profile

my os is Ubuntu 16.04, the default chrome profile is in :
~/.config/google-chrome
so i setup my selenium option with :
options.add_argument("--user-data-dir=/home/user/.config/google-chrome")
but no luck, the error message :
Message: unknown error: Chrome failed to start: exited abnormally

polymer test -l chrome: Could not request headers from https://download.microsoft.com

I am following simple steps to run polymer test but I am facing issues (https://www.polymer-project.org/1.0/docs/tools/tests).
There are few questions in stackoverflow not answered about similar issue.
Polymer Tests fail waiting for the driver server to start
Polymer2.0 - polymer testing is failing with error
Polymer Web Component Tester Unable to connect to selenium
In case it is relevant I am using Windows 7 and polymer 2.
When I run:
1 - polymer test -l chrome
Result in an error while tring to reach microsoft. Well, very strange since I specify only chrome
Error: Could not request headers from https://download.microsoft.com/download/D/
4/1/D417998A-58EE-4EFE-A7CC-39EF9E020768/MicrosoftWebDriver.exe: Error: getaddri
nfo ENOTFOUND download.microsoft.com download.microsoft.com:443
2 - polymer test --skip-selenium-install
\u00276.1\u0027, java.version: \u00271.8.0_172\u0027\nDriver info: driver.versi
on: unknown","error":"session not created"},"status":33}
at C:\Users\D-CA69TO\AppData\Roaming\npm\node_modules\polymer-cli\node_modul
es\web-component-tester\runner\steps.js:170:27
at Generator.next (<anonymous>)
at fulfilled (C:\Users\D-CA69TO\AppData\Roaming\npm\node_modules\polymer-cli
\node_modules\web-component-tester\runner\steps.js:4:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)

Protractor redirects and times out immediately after loading page

I'm trying to write some e2e specs for an AngularJS application. I have one Jasmine spec in test/e2e/test_spec.js:
describe('basic functionality', function() {
it('loads the home page', function() {
browser.get('/');
expect(browser.getCurrentUrl()).toMatch(/localhost/);
});
});
Terminal output when the spec is run:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
Stacktrace:
Error: waiting for page to load for 10000ms
Wait timed out after 10013ms
at Array.forEach (native)
From: Task: waiting for page to load for 10000ms
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:3:13)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 10.955 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
While the console is sitting on [launcher] Running 1 instances of WebDriver, Chrome opens and displays the index page for a fraction of a second, then changes to a blank page with data:text/html,<html></html> in the address bar.
Here is my protractor.config.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'chrome'
},
specs: 'test/e2e/**/*_spec.js',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
isVerbose: true
},
allScriptsTimeout: 20000,
onPrepare: function() {
return browser.driver.get("http://localhost:8100");
}
};
My webdriver-manager stuff seems to be up to date, although the tool doesn't seem to have a way to output version numbers.
> webdriver-manager status
selenium standalone is up to date
chromedriver is up to date
IEDriver is not present
Why is the spec failing?
Edit: This is what is printed to the terminal when onPrepare is commented out:
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
The last active task was:
unknown
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
timeout: timed out after 30000 msec waiting for spec to complete
Stacktrace:
undefined
Finished in 34.27 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Edit 2: When I do browser.get("http://google.com"), Chrome briefly shows the data: and data:text/html,<html></html> pages, redirects to Google, then times out looking for Angular.
> protractor protractor.config.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
basic functionality
loads the home page - fail
Failures:
1) basic functionality loads the home page
Message:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
Stacktrace:
Error: Angular could not be found on the page http://google.com/ : retries looking for angular exceeded
at Array.forEach (native)
From: Task: Asynchronous test function: it()
Error
at [object Object].<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:2:3)
at Object.<anonymous> (/Users/jdent/swamp-bunny/test/e2e/test_spec.js:1:63)
Finished in 12.186 seconds
1 test, 1 assertion, 1 failure
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
Set baseUrl: 'http://localhost:8100' in your protractor.config.js file. From the Protractor Reference Config:
A base URL for your application under test. Calls to protractor.get() with relative paths will be prepended with this.
It is a sporadic open bug in protractor https://github.com/angular/protractor/issues/5103
Instead of this
browser.get('http://juliemr.github.io/protractor-demo/');
Using this has solved my issue.
browser.driver.get('http://juliemr.github.io/protractor-demo/');
I had that problem in chrome. I read somewhere that protractor starts on that data:text/html,<html></html> page. Calling browser.get(...) navigates away from that page. My idea was to open chrome already on my base url. I accomplished that by adding it to the capabilities like this:
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['--app=www.yourBaseUrl.com']
}
},
It's a bit of a hack, but it seems to have done the trick.