Reputation: 441
I have created an Angular2 Project without using angular-cli. But while working with protractor when i am running my protractor.conf.js, its throwing error Unexpected token import(browser,element, by) from 'Protractor'.
I am using type script for test cases.
Following is the code for app.po.ts
import { browser, element, by, protractor } from 'protractor';
export class MainPage {
navigateTo() {
return browser.get('/');
}
getTitle() {
return browser.getTitle();
}
getDasboardTitle() {
return element(by.css('.al-title')).getText();
}
}
Following is the code for app.ts
import { MainPage } from './app.po';
describe('demo-project App', function() {
let page: MainPage ;
beforeEach(() => {
page = new MainPage ();
});
it('Application should have a title', () => {
page.navigateTo();
expect(page.getTitle()).toEqual('Operator - Flight Operation Management');
});
it('Dasbord should have a heading', function() {
expect(page.getTitle()).toEqual('DASHBOARD');
});
});
And Following is the error while running the protractor
[11:45:08] E/launcher - Error: c:\Angular2\ui\src\protractor\app.ts:1 (function (exports, require, module, __filename, __dirname) { import { OperatorMainPage } from './app.po';
^^^^^^ SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:76:16)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:\Node\npm\node_modules\protractor\node_modules\jasmine\lib\jasmine.js:71:5
at Array.forEach (native) [11:45:08] E/launcher - Process exited with error code 100
Upvotes: 3
Views: 6590
Reputation: 5016
You are importing MainPage
but calling OperatorMainPage
. OperatorMainPage
type does not exist.
import { MainPage } from './app.po';
describe('demo-project App', function() {
let page: MainPage;
beforeEach(() => {
page = new MainPage();
});
it('Application should have a title', () => {
page.navigateTo();
expect(page.getTitle()).toEqual('Operator - Flight Operation Management');
});
it('Dashbaord should have a heading', function() {
expect(page.getTitle()).toEqual('DASHBOARD');
});
});
Upvotes: 1