Angular I am trying to open new tab with URL,
let windowIroh = window.open(URL, '_blank'); /
let windowIroh2 =window.open(URL, '_blank','width=10,height=10');
let windowIroh3 = window.open(URL, '_blank','width=10,height=10');
After setTimeout closed all open tab
setTimeout(() => {
windowIroh?.close();
windowIroh2?.close();
windowIroh3?.close();
}, 5000);
I have checked it in local, unit test case got success and build also fine but it got failed in CICD pipeline,
karmaConfig
browsers: [ 'ChromeHeadless_without_security'],
customLaunchers: {
ChromeHeadless_without_security: {
base: 'ChromeHeadless',
options: {
windowName: 'new-window',
settings: {
webSecurityEnabled: false
},
},
flags: [
'--no-sandbox',
'--disable-gpu',
'--reduce-security-for-testing',
'--allow-insecure-localhost',
'--disable-web-security',
'--disable-site-isolation-trials',
'--disable-setuid-sandbox'
],
How to resolve this problem in Jenkins CICD pipeline
16:30:28 time=2023-01-17T11:00:28.587Z level=INFO message="RETRY: received status 500 from external call"
16:30:30 17 01 2023 03:00:30.300:WARN [Chrome Headless 92.0.4515.107 (Linux x86_64)]: Disconnected (0 times)reconnect failed before timeout of 30000ms (transport close)
16:30:30 Chrome Headless 92.0.4515.107 (Linux x86_64) ERROR
16:30:30 Disconnectedreconnect failed before timeout of 30000ms (transport close)
16:30:30 Chrome Headless 92.0.4515.107 (Linux x86_64) ERROR
16:30:30 Disconnectedreconnect failed before timeout of 30000ms (transport close)
Related
I am trying to setup my first E2E test with Nightwatch on the chromium browser.
nightwatch.json is configured as the following:
{
"src_folders" : ["tests"],
"webdriver" : {
"start_process": true,
"server_path": "node_modules/.bin/chromedriver",
"port": 9515
},
"test_settings" : {
"default" : {
"desiredCapabilities": {
"browserName": "chrome"
}
}
}
}
and the test:
module.exports = {
'Demo test ecosia.org': function (browser) {
browser
.url('https://www.ecosia.org/')
.waitForElementVisible('body')
.assert.titleContains('Ecosia')
.assert.visible('input[type=search]')
.setValue('input[type=search]', 'nightwatch')
.assert.visible('button[type=submit]')
.click('button[type=submit]')
.assert.containsText('.mainline-results', 'Nightwatch.js')
.end();
}
};
When I start test, it shows in the chromium browser:
The output:
[First Spec] Test Suite
=======================
⚠ Error connecting to localhost on port 9515.
_________________________________________________
TEST FAILURE: 1 error during execution; 0 tests failed, 0 passed (10.238s)
✖ first_spec
An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited normally."
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited normally."
at endReadableNT (_stream_readable.js:1221:12)
at process.processTicksAndRejections (internal/process/task_queues.js:84:21)
Error: An error occurred while retrieving a new session: "unknown error: Chrome failed to start: exited normally."
at endReadableNT (_stream_readable.js:1221:12)
What am I doing wrong?
Check your Chrome version and its chrome driver compatibility.
This seems to be a driver compatibility issue.
Also, do check this page for more information
https://chromedriver.chromium.org/downloads
Thanks!
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',
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();
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.
Premise: my app works perfectly, but anyway I decided to imoplement units tests.
My test, that check if a service given object is defined or not fails.
here is my service code:
//app/components/lib/search.js
angular.module("search", ["lazyLoad", "httpInterceptor"])
.service("SearchObject", ['$rootScope', '$location', 'Globals', function ($rootScope, $location, Globals) {
'use strict';
var obj,
SearchObjectPrototype = {};
SearchObjectPrototype.clone = function (source) {
var prop;
for (prop in this) {
if (this.hasOwnProperty(prop)) {
this[prop] = source[prop] || null;
}
}
};
//Definizione SearchObject
obj = Object.create(SearchObjectPrototype, {
q : {value: null, writable: true, enumerable: true},
max_id : {value: null, writable: true, enumerable: true},
next_results : {value: null, writable: true, enumerable: true},
query_debug : {value: null, writable: true, enumerable: true}
});
Object.preventExtensions(obj);
this.getInstance = function () {
return obj;
};
}])
Here is my test code:
console.log(1);
describe('search module', function() {
console.log(2);
beforeEach(module('search'));
describe('SearchObject test', function() {
console.log(3);
var SearchObject;
beforeEach(inject(function(_SearchObject_){
console.log(4);
// The injector unwraps the underscores (_) from around the parameter names when matching
SearchObject = _SearchObject_;
}));
it('should evaluate the injected SearchObject', function (){
console.log(5);
expect(SearchObject).toBeDefined()
});
});
});
Here is my karma.conf.js
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2015-10-20 using
// generator-karma 1.0.0
module.exports = function(config) {
'use strict';
config.set({
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// base path, that will be used to resolve files and exclude
basePath: '../',
// testing framework to use (jasmine/mocha/qunit/...)
// as well as any additional frameworks (requirejs/chai/sinon/...)
frameworks: [
"jasmine"
],
// list of files / patterns to load in the browser
files: [
// bower:js
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-route/angular-route.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/angular-touch/angular-touch.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_components/ngInfiniteScroll/build/ng-infinite-scroll.js',
'bower_components/Chart.js/Chart.js',
'bower_components/angular-chart.js/dist/angular-chart.js',
'bower_components/bootstrap-sass/assets/javascripts/bootstrap.js',
'bower_components/angular-mocks/angular-mocks.js',
// endbower
"app/components/lib/search.js",
// "test/mock/**/*.js",
"test/spec/search.js"
],
// list of files / patterns to exclude
exclude: [
],
// web server port
port: 8080,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: [
"PhantomJS"
],
// Which plugins to enable
plugins: [
"karma-chrome-launcher",
"karma-phantomjs-launcher",
"karma-jasmine"
],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false,
colors: true,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// Uncomment the following lines if you are using grunt's server to run the tests
// proxies: {
// '/': 'http://localhost:9000/'
// },
// URL root prevent conflicts with the site root
// urlRoot: '_karma_'
});
};
Here my Karma output
Running "karma:unit" (karma) task
11 02 2016 11:55:43.447:INFO [karma]: Karma v0.13.19 server started at http://lo
calhost:8080/
11 02 2016 11:55:43.474:INFO [launcher]: Starting browser PhantomJS
11 02 2016 11:55:46.510:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on s
ocket /#OphIJTNigEfxY1NIAAAA with id 56068342
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 1
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 2
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 3
LOG: 5
PhantomJS 2.1.1 (Windows 8 0.0.0) test sul modulo search SearchObject test shoul
d evaluate the injected SearchObject FAILED
C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular/angular.j
s:4459:53
forEach#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular/a
ngular.js:340:24
loadModules#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angul
ar/angular.js:4419:12
createInjector#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/an
gular/angular.js:4344:22
workFn#C:/Users/Rick/Sviluppo/socialsider-fe/bower_components/angular-mo
cks/angular-mocks.js:2428:60
**Expected undefined to be defined.**
C:/Users/Rick/Sviluppo/socialsider-fe/test/spec/search.js:19:45
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs / 0.043 se
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.019 secs
/ 0.043 secs)
As you can see log(4), which is in the same block of SearchObject assignement, didn't get called. The object is undefined and the test fails.
Anyone can explain me why? It can be a dependency problem?
I have found that you need to inject your services/factories yourself:
beforeEach(function() {
module('search'));
inject(function(_SearchObject_) {
SearchObject = _SearchObject_;
});
});
That should make the service available to the tests. I just went back and spot checked some of my own tests and saw that this was the common piece all of my factory and service tests had.
Update:
After further review, there are some really odd things going on here and possibly multiple issues that need to be resolved. I don't have all of your dependency libraries and the angular module wouldn't load at all in the tests without mocking or removing lazyLoad and httpInterceptor. I'm going to assume that isn't your issue though and the module loads. After that once I mocked out Globals it loads just fine.
So in short, be sure you are properly providing lazyLoad, httpInterceptor, and Globals to the test, either with the actual code or through mocking, and the test passes. At least for me it does.