2016-11-18 2 views
1

각도 2로 샘플 어플리케이션을 설정하려고합니다. 지금 e2e 테스트 파트를 테스트하려고합니다. 나는 Ang2가 사용하는 Jasmine 프레임 워크 또는 각도기 라이브러리에 대해 거의 알지 못합니다.E2E 테스트가 실패했습니다.

그래서 나는 확실하지 않다 왜 내 내가

내가 오류 (내가 각도 CLI를 사용하고 있습니다) ng e2e를 실행할 때이 오류가 :

[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) 

내 테스트 케이스 (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()); 
    } 
}; 
+1

''각도기 '에서 {브라우저, 요소,} 의해 수입 일반적으로는 * 페이지 객체 *에이있을 것'참고 (예를 들어 ['app.po.ts'] (HTTPS 참조 /github.com/textbook/known-for-web/blob/master/e2e/pages/app.po.ts)). 실제로 테스트에서 DOM과 상호 작용하고보다 사용자 친화적 인 API를 노출하는 비즈니스를 추상화합니다. (예 : ['app.e2e-spec.ts'] (https://github.com/textbook/known-for-web/blob/master/e2e/app.e2e-spec.ts)) - 당신의 예제에서'page.getGreetingText()'와'element (by.id ('h2Id')) .getText()'의 차이점. 이것이 CLI가 수행하는 방법입니다. – jonrsharpe

+0

작동하는 것처럼 보입니다. CLI에서 암시 적으로 라이브러리를 가져 왔다고 생각합니다. 응답을 보내 주셔서 감사합니다. – Snedden27

+0

CLI에 자동 생성 된'.po' 파일에 해당 가져 오기가 포함되어 있습니다. 브라우저 및 특정 요소가 아닌'.e2e-spec' 파일에 있습니다. – jonrsharpe

답변

0

app.e2e-spec.ts :

expect(). getText (greeting) .toEqual ('Hello, World!');/:;

=> expect(greeting.getText()).toEqual('Hello, World!'); 
+0

답변을 설명하십시오! – Mazz

+0

StackOverflow에 오신 것을 환영합니다. 여기를 참조하십시오 [코드 서식 방법] (https://stackoverflow.com/editing-help) –

관련 문제