1. 프로젝트 디렉터리 구조 분석
다음은 grunt-protractor-runner 프로젝트의 디렉터리 구조입니다.
grunt-protractor-runner/
├── scripts/
│ └── webdriver-manager-update
├── tasks/
│ └── protractor.js
├── test/
│ └── protractor/
│ └── conf.js
├── .gitignore
├── .jshintrc
├── .travis.yml
├── Gruntfile.js
├── LICENSE-MIT
├── README.md
└── package.json
주요 디렉터리 및 파일 설명
- scripts/: WebDriver 업데이트를 위한 셸 스크립트를 담고 있습니다.
- tasks/: Grunt 태스크 정의 파일(
protractor.js)이 위치합니다. - test/: Protractor 테스트 설정 파일(
conf.js)을 포함합니다. - .gitignore: Git 버전 관리에서 제외할 파일을 지정합니다.
- .jshintrc: JavaScript 코드 린트 설정 파일입니다.
- .travis.yml: Travis CI 지속적 통합 구성 파일입니다.
- Gruntfile.js: Grunt 태스크 정의의 핵심 파일입니다.
- package.json: 프로젝트 의존성 및 스크립트를 관리합니다.
2. 애플리케이션 시작 및 태스크 정의
Gruntfile.js는 Grunt가 Protractor를 실행하는 방식을 정의합니다.
module.exports = function(grunt) {
grunt.initConfig({
protractor: {
default: {
options: {
configFile: "e2e.conf.js",
keepAlive: false,
noColor: false,
args: {
seleniumAddress: 'http://localhost:4444/wd/hub'
}
}
},
custom: {
options: {
configFile: "node_modules/protractor/example/conf.js",
keepAlive: true,
args: {}
}
}
}
});
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.registerTask('test', ['protractor']);
grunt.registerTask('default', ['protractor:default']);
};
실행 절차
- 의존성 설치:
npm install명령어를 통해 필요한 패키지를 설치합니다. - 테스트 실행:
grunt혹은npm test명령어로 Protractor 테스트를 시작합니다.
3. 프로젝트 설정 파일 상세
package.json
다음은 프로젝트의 종속성과 스크립트를 정의하는 package.json 예시입니다.
{
"name": "grunt-protractor-runner",
"version": "5.0.0",
"description": "Protractor 실행을 위한 Grunt 플러그인",
"main": "Gruntfile.js",
"scripts": {
"test": "grunt test",
"start-webdriver": "webdriver-manager start"
},
"dependencies": {
"protractor": "^5.0.0"
},
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.1.0"
}
}
설정 항목 설명
- name: 프로젝트 이름.
- version: 배포 버전.
- scripts:
test는 Grunt 태스크를 실행,start-webdriver는 WebDriver 서버를 시작합니다. - dependencies:
protractor와 같은 런타임 의존성을 명시합니다. - devDependencies:
grunt,grunt-contrib-jshint같은 개발용 패키지를 포함합니다.
test/protractor/conf.js
Protractor 실행 설정을 정의한 설정 파일입니다.
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: [
'spec/chrome-test.js',
'spec/firefox-test.js'
],
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 2
},
framework: 'jasmine2',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
주요 설정 옵션
- seleniumAddress: Selenium 서버의 URL을 지정합니다.
- specs: 실행할 테스트 스크립트 파일 경로의 배열입니다.
- capabilities: 브라우저 환경(
browserName), 테스트 분할(shardTestFiles), 최대 인스턴스 수(maxInstances)를 설정합니다. - framework: 테스트 프레임워크를 선택합니다(
jasmine2,mocha등). - jasmineNodeOpts: 테스트 실행 시 색상 출력 여부와 타임아웃을 조정합니다.