I am trying to set up a sample application in Angular 2 , right now I am trying to test the e2e testing part. I have little knowledege on the Jasmine framework or the Protractor library that Angular 2 uses.
So I am not sure why I my getting this error when I run ng e2e (I am using Angular CLI)
The error I get:
[09:41:10] I/direct - Using ChromeDriver directly...
[09:41:10] I/launcher - Running 1 instances of WebDriver
[09:41:12] E/launcher - Error: TSError: ? Unable to compile TypeScript
e2e\app.e2e-spec.ts (16,4): Cannot find name 'browser'. (2304)
e2e\app.e2e-spec.ts (17,19): Cannot find name 'element'. (2304)
e2e\app.e2e-spec.ts (17,27): Cannot find name 'by'. (2304)
e2e\app.e2e-spec.ts (18,5): Supplied parameters do not match any signature of ca
ll target. (2346)
My test case (app.e2e-spec.ts)
import { WebPage } from './app.po';
describe('web App', function() {
let page: WebPage;
beforeEach(() => {
page = new WebPage();
});
it('should display message saying app works', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('Hello World');
});
it('Has a greeting', function () {
browser.get('/index.html');
var greeting = element(by.id('h2Id'));
expect().getText(greeting).toEqual('Hello, World!');
});
});
Protrator.config.js
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
useAllAngular2AppRoots: true,
beforeLaunch: function() {
require('ts-node').register({
project: 'e2e'
});
},
onPrepare: function() {
jasmine.getEnv().addReporter(new SpecReporter());
}
};
import { browser, element, by } from 'protractor';Note that usually you would have these in a page object (see e.g.app.po.ts), which abstracts the business of actually interacting with the DOM from the test and exposing a more user-friendly API making your tests more readable (e.g.app.e2e-spec.ts) - the difference betweenpage.getGreetingText()andelement(by.id('h2Id')).getText(), in your example. That's how the CLI does it. - jonrsharpe.pofile, where you're expected to be interacting with the browser and specific elements, not in the.e2e-specfile where you aren't. - jonrsharpe