-3

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
Murali
  • 23
  • 2
  • 8
  • you see that error only when run code in debigger? That error appears if you make `export/import` in a worng way. – Oleksii Feb 07 '18 at 10:51

1 Answers1

0

You should use such import constructure:

const Login_pageobj = require('../ES6_pageobj/login_pageobj')

Oleksii
  • 1,623
  • 20
  • 26