Protractor jasmine2-protractor-util TypeError: Cannot read property 'forEach' of undefined - protractor

I've got a problem with separated protractor specs. I've trying to divide 1 test 1 spec. And got a error message like
E/launcher - Cannot read property 'forEach' of undefined
E/launcher - TypeError: Cannot read property 'forEach' of undefined
at C:\Users\mako\AppData\Roaming\npm\node_modules\jasmine2-protractor-utils\reporter\jasmine2_reporter.js:112:24
at Array.forEach (native)
at self.jasmineDone (C:\Users\mako\AppData\Roaming\npm\node_modules\jasmine2-protractor-utils\reporter\jasmine2_reporter.js:108:16)
at dispatch (C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1966:28)
at ReportDispatcher.jasmineDone (C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1
949:11)
at C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:758:18
at QueueRunner.clearStack (C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:660:9)
at QueueRunner.run (C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1881:12)
at C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1898:16
at C:\Users\mako\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1842:9
E/launcher - Process exited with error code 199
Test cases are running properly, error happens after all suites are done.
Problem disappear if spec have more than on "it" even empty. Have you got any ideas what can be a problem?

I would suggest to add a piece of code which returns a promise , to your onPrepare block of Protractor configuration file.
For Example:
onPrepare: function () {
// returning the promise makes protractor wait for the reporter config before executing tests
return global.browser.getProcessedConfig().then(function (config) {
});
}

I "solve" problem.
/*plugins: [{
package: 'jasmine2-protractor-utils',
disableHTMLReport: false,
disableScreenshot: false,
screenshotPath:'./test_results/E2E/screenshots',
screenshotOnExpectFailure:true,
screenshotOnSpecFailure:true,
clearFoldersBeforeTest: true,
htmlReportDir: './test_results/E2E/htmlReports',
/*failTestOnErrorLog: {
failTestOnErrorLogLevel: 900,
excludeKeywords: ['keyword1', 'keyword2']
}*/
// }],
And the problem is with plugin 'jasmine2-protractor-utils'. If I've got two specs and one test each error happens. Without this plugin or if I add empty test to one of them it works fine.

Related

TypeORM migration gives Maximum call stack size exceeded error with Postgres

When I run a migration, I get the following error. I initially had this in one project - now I've created a new blank project and still get the error. Here is the ormconfig.ts:
import { DataSource } from 'typeorm';
const env = {
"DB_HOST":"localhost",
"DB_PORT":5432,
"DB_USERNAME":"postgres",
"DB_PASSWORD":"postgres",
"DB_DATABASE":"task-management",
}
export const connectionSource = new DataSource({
migrationsTableName: 'migrations',
type: 'postgres',
host: env.DB_HOST,
port: env.DB_PORT,
username: env.DB_USERNAME,
password: env.DB_PASSWORD,
database: env.DB_DATABASE,
logging: false,
synchronize: false,
name: 'default',
migrations: ['migrations/**/*{.ts,.js}'],
});
I run the migration with: typeorm-ts-node-esm migration:run -d migrations/ormconfig.ts
which gives the following error:
Error during migration run:
RangeError: Maximum call stack size exceeded
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:43
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:42
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:27:22)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17
at Array.forEach (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:29:35)
at /Users/christianayscue/Desktop/nestjsClass/nestjs-task-management/node_modules/src/util/DirectoryExportedClassesLoader.ts:30:17
I assume there is some circular dependency causing an infinite loop in DirectoryExportedClassesLoader.ts, so I put a console.log(JSON.stringify(exported)) on line 26 of DirectoryExportedClassesLoader.ts, and I now get:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'DataSource'
| property 'driver' -> object with constructor 'PostgresDriver'
--- property 'connection' closes the circle
at JSON.stringify (<anonymous>)
at loadFileClasses (/Users/christianayscue/Desktop/nestjsClass/typeormTest/src/util/DirectoryExportedClassesLoader.ts:29:25)
It seems DirectoryExportedClassLoader.js is guaranteed to get a Maximum call stack size exceeded error if there are circular dependencies, because it is self-recursive whenever it encounters an object property.
A little help please!
changing this entry from the DataSource config object fixed the issue.
migrations: []
This was one of those ones that just took a lot of trial and error to solve...

Cannot read property 'prototype' of undefined - nestjs with typeorm and mongoDB

I'm setting up a simple API using nestjs with typeorm and mongodb. However when I make a simple http request I get the following error
[Nest] 8852 - 09/28/2021, 6:06:03 PM [ExceptionsHandler] Cannot read property 'prototype' of undefined +4874934ms TypeError: Cannot read property 'prototype' of undefined at FindCursor.cursor.toArray (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:669:37) at MongoEntityManager.<anonymous> (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:60:54) at step (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:143:27) at Object.next (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:124:57) at fulfilled (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:114:62) at processTicksAndRejections (internal/process/task_queues.js:95:5)
offices.controller.ts
#Get('/list')
findAll() {
return this.officesService.findAll();
}
offices.service.ts
async findAll() {
try {
const offices = await this.officesRepository.find();
return { success: true, message: 'Office successfully retrieved!', data: offices }
} catch(e) {
throw new InternalServerErrorException({ success: false, error: e.message })
}
}
I honestly don't know why it gives me error 500 with that message. Any idea what's happening?
These errors seam like a mongodb version problem. If you are using mongodb > 3, Typeorm doesn't support yet. They have PR open at github --> https://github.com/typeorm/typeorm/issues/7907
It's issue of mongodb version with typeorm.
typeorm doesn't have support for >3 version yet.
Run this to resolve issue.
mongodb#3 #types/mongodb#3
Complete dependencies
npm install typeorm #nestjs/typeorm mongodb#3 #types/mongodb#3
Resolved same issue following this.

Time out error when using browser.getCurrentUrl() after URL changes

I am writing a protractor test for login for an AngularJS app and want to verify that the login is successful and the url changes after login. I tried to use Expected condition with urlContains() and also tried with browser.getCurrentUrl().toContain() but I am getting error in both.
exports.config = {
seleniumAddress : 'http://localhost:4444/wd/hub',
specs: ['login.spec.js'],
};
Expected condition passes the test when the url is correct. But when the url is different then it throws timeout error
"Failed: Wait timed out after 5013ms".
expect(browser.getCurrentUrl()).toContain('/dashboard') fails always with below error
Stack:
ScriptTimeoutError: script timeout: result was not received in 11 seconds
(Session info: chrome=75.0.3770.142)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '12.0.1'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: Protractor.waitForAngular()
at thenableWebDriverProxy.schedule (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
at ProtractorBrowser.executeAsyncScript_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/built/browser.js:425:28)
at angularAppRoot.then (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/built/browser.js:456:33)
at ManagedPromise.invokeCallback_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:668:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: Run it("should login successfully") in control flow
at UserContext.<anonymous> (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19)
From asynchronous test:
Error
at Object.<anonymous> (/Users/ProtractorTest/Tests/login.spec.js:17:3)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at /Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/jasmine/lib/jasmine.js:93:5
Below is my code
it('should login successfully', function () {
browser.get("https://example.com/");
loginobj.username.sendKeys(logindata.email);
loginobj.password.sendKeys(logindata.password);
loginobj.loginbtn.click().then(function(){
browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
//var EC = protractor.ExpectedConditions;
//browser.wait(EC.urlContains('/dashboard'), 5000);
})
I expect that when the url is different than the expected one, it should display a valid error message instead of timeout error.
By default protractor handles all the asynchrony for you. Looking at your code you are relying on default protractor behaviour i.e. not setting SELENIUM_PROMISE_MANAGER to false.
In that case, why do you want to do something inside click().then() ? It can be as simple and plain as
loginobj.loginbtn.click();
expect(browser.getCurrentUrl()).toContain('/dashboard');
One theory with your code: once you have something inside click().then(), its out of place from the promise queue that protractor is handling for you. Unless it is absolutely necessary, for ex get value from an element for later use in the spec, I would suggest not to meddle with protractor asynchronous handling as much as possible.
Hope that helps.
I have something similar
const currentUrl = await browser.getCurrentUrl().then(url => url);
expect(currentUrl).toContain('/dashboard')
Try it out maybe it will help, just without await as i see you don't use async functions
or like this
await browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
In protractor default script time out is 11 seconds,
In above code snippet,
browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
statement takes more than 11 seconds to resolve promise.
Solution: In Protractor configuration file, add below statements
allScriptsTimeout: timeout_in_millis.
e.g for 30 second timeout
allScriptsTimeout: 30000
Edited Configuration File:
exports.config = {
allScriptsTimeout: 30000,
seleniumAddress : 'http://localhost:4444/wd/hub',
specs: ['login.spec.js'],
};

'Globals' are not working as expected in protractor 4.0.0?

we have the following setting in our onPrepare function of config file-
exports.config = {
directConnect: true,
baseUrl: env.baseUrl,
capabilities: env.capabilities,
onPrepare: function () {
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
global.expect = chai.expect; // by removing this line error is not thrown
browser.manage().window().maximize();
},
setDefaultTimeout : 60 * 1000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
specs: [
'../Features/*.feature'
],
cucumberOpts: {
monochrome: true,
strict: true,
plugin: ["pretty"],
require: ['../StepDefinitions/*.js', '../Support/*.js'],
tags:'#AddActiveTip,#AddInActiveTip,~#AddActiveManufacturer,~#AddInActiveManufacturer'
//tags:'#TestSplitText'
}
};
since the upgrade to protractor 4.0, I am getting the following error and the browser hangs indefinitely and the error does not help to debug in anyway.
error:
> protractor Config/config.js --troubleshoot
[22:38:12] I/direct - Using FirefoxDriver directly...
[22:38:12] I/launcher - Running 1 instances of WebDriver
/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:87
if (e.message.indexOf(errMsg) !== -1) {
^
TypeError: Cannot read property 'indexOf' of undefined
at Function.ErrorHandler.isError (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:87:30)
at Function.ErrorHandler.parseError (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/exitCodes.js:98:26)
at process.<anonymous> (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/built/launcher.js:169:54)
at emitOne (events.js:82:20)
at process.emit (events.js:169:7)
at process.emit (/Users/pasalar/protractor/psms-protractor/node_modules/protractor/node_modules/source-map-support/source-map-support.js:419:21)
at process._fatalException (node.js:224:26)
npm ERR! Test failed. See above for more details.
is anyone else facing this issue? are there any major changes that I am missing?
The error message shown has nothing to do with "globals", it is working as expected! my scripts were failing randomly due to network latency issues.But the error messages need to improved as the user has no idea what caused the error!
Marking it closed as I was able debug this issue!

selenium standalone terminates with unknown error

when i start my test the browser opens and an ip is displayed after few sec the ip is changed to "data;" in terminal the test is been looped and sends err ms
empresss-Mac-mini:myApp admin$ protractor test/e2e.js
Using the selenium server at http://localhost:4444/wd/hub
[launcher] Running 1 instances of WebDriver
Started
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
F
Failures:
1) header Module should check title text
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Message:
Failed: header is not defined
Stack:
ReferenceError: header is not defined
at Object.<anonymous> (/Users/admin/myApp/www/head.spec.js:8:13)
From: Task: Run it("should check title text") in control flow
From asynchronous test:
Error
at Suite.<anonymous> (/Users/admin/myApp/www/head.spec.js:7:4)
at Object.<anonymous> (/Users/admin/myApp/www/head.spec.js:1:63)
1 spec, 1 failure
Finished in 30.019 seconds
[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
my config file is
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../www/head.spec.js'],
multiCapabilities: [
{
browserName: 'chrome'
}],
onPrepare: function(){
browser.driver.get('http://192.168.1.2:8100');
}
}
i named it as e2e.js
my test file is
describe('header Module', function(){
beforeEach(function() {
var header = element(by.css('title'));
});
it('should check title text',function(){
expect(header.getText()).toContain('Ionic Blank Starter');
});
});
i downloaded an blank ionic app and i want to test the header contains elements "Ionic Blank Starter"
You are not handling async code well in your project. header.getText() returns a promise which you need to resolve before asserting the text. You can do something like this:
describe('header Module', function(){
it('should check title text',function(callback){
var header = element(by.css('.title'));
header.getText()
.then(function (text) {
expect(text).toContain('Ionic Blank Starter');
callback();
});
});
});