Issue in export and import ES6 Classes in protractor testing - protractor

I'm facing two issues while using ES6 class export and import. First, while import, methods cannot be accessible from imported class. Second, while executing the code through visual studio code im facing the following error "SyntaxError: Unexpected token import". Please provide correction or suggestion.
Below are my my class file "Login_pageobj.js"
export default class Login_pageobj {
constructor() {
//userName
this.enterUserName = element(by.xpath('//input[#id="username"]'));
//Password
this.enterPassword = element(by.xpath('//input[#id="password"]'));
//Login Button
this.clickLoginBtn = element(by.buttonText('LOGIN'));
//invalid UserName Password Error
this.inValErrMsg = element(by.xpath('//div[#class="subtext"]'));
}
//Please enter a user name (required). method
isDisplyedUserNameErrorMsg() {...}
This below code is My Protractor spec file Login_spec.js
import Login_pageobj from '../ES6_pageobj/login_pageobj';
describe('Login Page Validation', function() {
it('Launch Commercial URL',function(){
browser.get('http://applicationurl');
browser.manage().window().maximize();
expect(browser.getTitle()).toBe('LoginWeb');
});
it('Login Button should Disabled',function(){
console.log('----------------------------------------------------');
let lgin_pgobj = new login_pageobj();
lgin_pgobj.verifyLgnBtnEnabled();//***unable to access this method***
});
});
While run this code through Visual studio code debugger i'm getting following error.
Debugging with inspector protocol because Node.js v8.9.1 was detected.
node --inspect-brk=23169 node_modules\protractor\bin\protractor
e:\CommercialPOC/conf.js --suite es6
Debugger listening on ws://127.0.0.1:23169/e3dfd326-8468-4a3a-a2e3-3094d97c5571
(node:4708) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
(node:4708) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
warning.js:18
[22:00:06] I/launcher - Running 1 instances of WebDriver
logger.js:155
[22:00:06] I/direct - Using ChromeDriver directly...
logger.js:155
null
conf.js:48
[22:00:25] E/launcher - Error:
e:\commercialPOC\ES6_moduleScenarios\0Login_spec.js:1
logger.js:155
(function (exports, require, module, __filename, __dirname) { import
Login_pageobj from '../ES6_pageobj/login_pageobj';
^^^^^^
SyntaxError: Unexpected token import
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at e:\CommercialPOC\node_modules\jasmine\lib\jasmine.js:93:5
[22:00:25] E/launcher - Process exited with error code 100

You should use such import constructure:
const Login_pageobj = require('../ES6_pageobj/login_pageobj')

Related

Problem with "npm" installation in VS Code - tried different ways, no result

The error:
C:\\Users\\RC\>npm install -g #angular/cli
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module './utils/unsupported.js'
Require stack:
- C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js
- C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js
\[90m at Function.Module.\_resolveFilename (node:internal/modules/cjs/loader:933:15)\[39m
\[90m at Function.Module.\_load (node:internal/modules/cjs/loader:778:27)\[39m
\[90m at Module.require (node:internal/modules/cjs/loader:1005:19)\[39m
\[90m at require (node:internal/modules/cjs/helpers:102:18)\[39m
at module.exports (C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\\[4mnpm\[24m\\lib\\cli.js:14:59)
at Object.\<anonymous\> (C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\\[4mnpm\[24m\\bin\\npm-cli.js:2:25)
\[90m at Module.\_compile (node:internal/modules/cjs/loader:1103:14)\[39m
\[90m at Object.Module.\_extensions..js (node:internal/modules/cjs/loader:1157:10)\[39m
\[90m at Module.load (node:internal/modules/cjs/loader:981:32)\[39m
\[90m at Function.Module.\_load (node:internal/modules/cjs/loader:822:12)\[39m {
code: \[32m'MODULE_NOT_FOUND'\[39m,
requireStack: \[
\[32m'C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js'\[39m,
\[32m'C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'\[39m
\]
}
C:\\Users\\RC\>npm install -g #angular/cli
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module './utils/unsupported.js'
Require stack:
- C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js
- C:\\Users\\RC\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js
If you install Node.js, then also npm is installed. That might be the easiest to do.
You can download Node.js here:
https://nodejs.org/en/download/
VS Code then finds npm, no further setup is required.

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'],
};

Type Script : SyntaxError: Unexpected token

I am trying to Implement this simple typescript code. But having weird error while running through node command. Can someone please help?
Main.ts
class Wedding {
bond:string;
money:number;
isWeddingPossible() {
if(this.bond === 'Strong' && this.money > 10000 ){
console.log('Wedding can be done.');
}
else{
console.log("Go to hell");
}
}
}
let wedding = new Wedding();
wedding.bond = 'Not Strong';
wedding.money = 500;
wedding.isWeddingPossible();
Run commands : tsc main.ts && node main.ts
Error :
/ts-hello/main.ts:3
bond:string;
^
SyntaxError: Unexpected token :
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
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 Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
You should run node main.js instead of main.ts. You compile your .ts file and it creates it's .js file. So you need to run that compiled .js file via node.

Intel Edison Johnny five error

I have been trying to run my hello-worlds.js file on my intel Edison (shown below):
var five = require("johnny-five");
var Edison = require("galileo-io");
var board = new five.Board({
io: new Edison()
});
board.on("ready", function() {
var led = new five.Led(13);
led.blink(500);
});
I have installed Node.js, I also used npm install galileo-io johnny-five and downloaded files to my file directory of folder my-robotics-project.
When i execute using node hello-worlds.js, I get the following error:
This OS image is no longer supported.
Please upgrade to IoTkit Image with libmraa0 support
c:\User\Mohamed\my-robotics-project\node_modules\galileo\lib\galileo.js:66
if <Pin.IO.getPlatformType<> === 2> {
TypeError: Cannot read property 'getPlatformType' of undefined
at Object.<anonymous> <c:\User\Mohamed\my-robotics-
project\node_modules\galileo\lib\galileo.js:66:11>
at Module._compile <module.js:435:26>
at Object.Module.extensions..js <module.js:442:10>
at Module.load <module.js:356:32>
at function.Module._load <module.js:311:12>
at Module.require <module.js:366:17>
at require <module.js:385:17>
at Object.<anonymous> <c:\User\Mohamed\my-robotics-project\hello-
worlds.js:2:14>
at Module._compile <module.js:435:26>
at Object.Module._extensions..js <module.js:442:10>

Keystone and openshift, getting 503 error

Can anyone please help me install keystone.js on my openshift app?
I've pushed all my files to the remote, but get a 503 error when I browse to my page. I'm quite new to Openshift, can anyone please point me in the right direction?
I have tried changing keystone.init to:
var connectionString = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" + process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "#" + process.env.OPENSHIFT_MONGODB_DB_HOST + dbName;
console.log(connectionString);
keystone.set('mongo', connectionString);
keystone.init({
'mongo': connectionString,
Still no joy, I dont get any console errors either.
Any advice much appreciated.
UPDATE: checked logs and found the following:
SyntaxError: Unexpected end of input
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/lib/openshift/5501b0c04382ecfefe0000a2/app-root/runtime/repo/node_modules/keystone/index.js:3:6)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
DEBUG: Program node keystone.js exited with code 8
DEBUG: Starting child process with 'node keystone.js'
hit me
/var/lib/openshift/5501b0c04382ecfefe0000a2/app-root/runtime/repo/node_modules/underscore/underscore.js:561
});
SyntaxError: Unexpected end of input
at Module._compile (module.js:439:25)
Keystone.js
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
// Require keystone
var keystone = require('keystone');
// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.
var dbName = "node";
var connectionString = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" + process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "#" + process.env.OPENSHIFT_MONGODB_DB_HOST + dbName;
console.log(connectionString);
keystone.set('mongo', connectionString);
keystone.init({
'mongo': connectionString,
'name': 'node',
'brand': 'node',
'sass': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': 'jade',
'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
'cookie secret': '^<S0$!?a778,)~[Fx4wQvgcTw]fWq.)<s`cAJc:bExU*(L&ty9;mSV?`am:*7f.P'
});
// Load your project's Models
keystone.import('models');
// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
_: require('underscore'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable
});
// Load your project's Routes
keystone.set('routes', require('./routes'));
// Setup common locals for your emails. The following are required by Keystone's
// default email templates, you may remove them if you're using your own.
// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
'posts': ['posts', 'post-categories'],
'enquiries': 'enquiries',
'users': 'users'
});
// Start Keystone to connect to your database and initialise the web server
keystone.start();
Fixed this by making sure all node modules were on the server, pushing to the repo using sourcetree kept timing out, so the modules weren't there. I FTP'd them instead.