Angular Cucumber 找不到要执行的任何测试
Angular Cucumber not finding any test to execute
我正在尝试 运行 用黄瓜进行端到端测试。我已按照 here 和 运行 我的端到端测试的步骤进行操作。但是,没有找到任何测试。为什么找不到测试?
控制台输出如下:
$ webdriver-manager update --no-gecko --ignore_ssl && ng e2e --no-webdriver-update --protractor-config e2e/protractor.conf.lcl.js
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/config_source - curl -ok /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/standalone-response.xml https://selenium-release.storage.googleapis.com/
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/config_source - curl -ok /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chrome-response.xml https://chromedriver.storage.googleapis.com/
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:55] I/http_utils - ignoring SSL certificate
[14:54:55] I/http_utils - ignoring SSL certificate
[14:54:55] I/update - chromedriver: file exists /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_85.0.4183.87.zip
[14:54:55] I/update - chromedriver: unzipping chromedriver_85.0.4183.87.zip
[14:54:55] I/update - chromedriver: setting permissions to 0755 for /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_85.0.4183.87
[14:54:55] I/update - chromedriver: chromedriver_85.0.4183.87 up to date
[14:54:55] I/update - selenium standalone: file exists /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar
[14:54:55] I/update - selenium standalone: selenium-server-standalone-3.141.59.jar up to date
chunk {main} main.js, main.js.map (main) 1.04 MB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 438 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 694 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.28 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 11.2 MB [initial] [rendered]
Date: 2020-09-23T19:55:19.109Z - Hash: 1453b65c5aa3bb581d3d - Time: 15205ms
** Angular Live Development Server is listening on localhost:4200, open your browser on https://localhost:4200/ **
: Compiled successfully.
[14:55:19] I/launcher - Running 1 instances of WebDriver
[14:55:19] I/local - Starting selenium standalone server...
[14:55:20] I/local - Selenium standalone server started at http://192.168.1.106:49459/wd/hub
0 scenarios
0 steps
0m00.000s
[14:55:24] I/local - Shutting down selenium standalone server.
[14:55:24] I/launcher - 0 instance(s) of WebDriver still running
[14:55:24] I/launcher - chrome #01 passed
Invalid Cucumber JSON file found under ./e2e/reports: e2e/reports/cucumber_report.33165.json
Cucumber HTML report ./e2e/reports/cucumber_report.html generated successfully
文件夹结构如下所示:
e2e
src
features
home-page.feature
pages
home-page.po.ts
steps
home-page.steps.ts
protractor.conf.lcl.js
tsconfig.e2e.json
配置如下所示:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const fs = require('fs-extra')
const path = require('path')
/** @type {import('protractor').Config} */
exports.config = {
allScriptsTimeout: 800000,
getPageTimeout: 400000,
specs: ['./src/features/**/*.feature'],
params: {
pageObjects: require['./src/pages/**/*.po.ts'],
customTimeout: 200000
},
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1
},
// Only works with Chrome and Firefox
directConnect: false,
baseUrl: 'https://localhost:4200/',
useAllAngular2AppRoots: true,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
compiler: 'ts:ts-node/register',
require: ['./src/steps/**/*.steps.ts'],
format: 'json:e2e/reports/cucumber_report.json',
monochrome: true,
strict: true,
tags: '@Regression'
},
beforeLaunch: () => {
// Delete old report files
},
onPrepare() {
// If you need to navigate to a page which does not use Angular,
// you can turn off waiting for Angular
browser.ignoreSynchronization = true
require('ts-node').register({
project: path.join(__dirname, './tsconfig.e2e.json')
})
},
afterLaunch: () => {
var reporter = require('cucumber-html-reporter')
var options = {
theme: 'bootstrap',
jsonDir: './e2e/reports',
jsonFile: './e2e/reports/cucumber_report.html.json',
output: './e2e/reports/cucumber_report.html',
ignoreBadJsonFile: true,
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
'App Version': '0.3.2',
'Test Environment': 'STAGING',
'Browser': 'Chrome 80.0.3987.163',
'Platform': 'Mac',
'Parallel': 'Scenarios',
'Executed': 'Remote'
}
}
reporter.generate(options)
},
}
这是功能:
Feature: Go to the home page
Scenario: Home Page
Given I am on the home page
When I do nothing
Then I should see the title
步骤如下:
import { expect } from 'chai';
import { Before, Given, Then, When } from 'cucumber';
import { HomePage } from '../pages/home-page.po';
let home: HomePage;
Before(() => {
home = new HomePage();
});
Given('I am on the home page', async () => {
await home.navigateHome();
});
When('I do nothing', () => { });
Then('I should see the title', async () => {
expect(await home.getTitleText()).to.equal('Login');
});
specs: ['./src/features/*.feature'],
请更新配置中功能的路径。实际上没有检测到特征。
在场景之前的特征文件中添加@Regression
我正在尝试 运行 用黄瓜进行端到端测试。我已按照 here 和 运行 我的端到端测试的步骤进行操作。但是,没有找到任何测试。为什么找不到测试?
控制台输出如下:
$ webdriver-manager update --no-gecko --ignore_ssl && ng e2e --no-webdriver-update --protractor-config e2e/protractor.conf.lcl.js
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/config_source - curl -ok /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/standalone-response.xml https://selenium-release.storage.googleapis.com/
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/config_source - curl -ok /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chrome-response.xml https://chromedriver.storage.googleapis.com/
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:54] I/http_utils - ignoring SSL certificate
[14:54:55] I/http_utils - ignoring SSL certificate
[14:54:55] I/http_utils - ignoring SSL certificate
[14:54:55] I/update - chromedriver: file exists /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_85.0.4183.87.zip
[14:54:55] I/update - chromedriver: unzipping chromedriver_85.0.4183.87.zip
[14:54:55] I/update - chromedriver: setting permissions to 0755 for /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_85.0.4183.87
[14:54:55] I/update - chromedriver: chromedriver_85.0.4183.87 up to date
[14:54:55] I/update - selenium standalone: file exists /Users/rnaddy/Documents/vscode/projects/user-management-ui/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar
[14:54:55] I/update - selenium standalone: selenium-server-standalone-3.141.59.jar up to date
chunk {main} main.js, main.js.map (main) 1.04 MB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 438 kB [initial] [rendered]
chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 694 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 1.28 MB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 11.2 MB [initial] [rendered]
Date: 2020-09-23T19:55:19.109Z - Hash: 1453b65c5aa3bb581d3d - Time: 15205ms
** Angular Live Development Server is listening on localhost:4200, open your browser on https://localhost:4200/ **
: Compiled successfully.
[14:55:19] I/launcher - Running 1 instances of WebDriver
[14:55:19] I/local - Starting selenium standalone server...
[14:55:20] I/local - Selenium standalone server started at http://192.168.1.106:49459/wd/hub
0 scenarios
0 steps
0m00.000s
[14:55:24] I/local - Shutting down selenium standalone server.
[14:55:24] I/launcher - 0 instance(s) of WebDriver still running
[14:55:24] I/launcher - chrome #01 passed
Invalid Cucumber JSON file found under ./e2e/reports: e2e/reports/cucumber_report.33165.json
Cucumber HTML report ./e2e/reports/cucumber_report.html generated successfully
文件夹结构如下所示:
e2e
src
features
home-page.feature
pages
home-page.po.ts
steps
home-page.steps.ts
protractor.conf.lcl.js
tsconfig.e2e.json
配置如下所示:
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const fs = require('fs-extra')
const path = require('path')
/** @type {import('protractor').Config} */
exports.config = {
allScriptsTimeout: 800000,
getPageTimeout: 400000,
specs: ['./src/features/**/*.feature'],
params: {
pageObjects: require['./src/pages/**/*.po.ts'],
customTimeout: 200000
},
capabilities: {
browserName: 'chrome',
shardTestFiles: true,
maxInstances: 1
},
// Only works with Chrome and Firefox
directConnect: false,
baseUrl: 'https://localhost:4200/',
useAllAngular2AppRoots: true,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
compiler: 'ts:ts-node/register',
require: ['./src/steps/**/*.steps.ts'],
format: 'json:e2e/reports/cucumber_report.json',
monochrome: true,
strict: true,
tags: '@Regression'
},
beforeLaunch: () => {
// Delete old report files
},
onPrepare() {
// If you need to navigate to a page which does not use Angular,
// you can turn off waiting for Angular
browser.ignoreSynchronization = true
require('ts-node').register({
project: path.join(__dirname, './tsconfig.e2e.json')
})
},
afterLaunch: () => {
var reporter = require('cucumber-html-reporter')
var options = {
theme: 'bootstrap',
jsonDir: './e2e/reports',
jsonFile: './e2e/reports/cucumber_report.html.json',
output: './e2e/reports/cucumber_report.html',
ignoreBadJsonFile: true,
reportSuiteAsScenarios: true,
launchReport: false,
metadata: {
'App Version': '0.3.2',
'Test Environment': 'STAGING',
'Browser': 'Chrome 80.0.3987.163',
'Platform': 'Mac',
'Parallel': 'Scenarios',
'Executed': 'Remote'
}
}
reporter.generate(options)
},
}
这是功能:
Feature: Go to the home page
Scenario: Home Page
Given I am on the home page
When I do nothing
Then I should see the title
步骤如下:
import { expect } from 'chai';
import { Before, Given, Then, When } from 'cucumber';
import { HomePage } from '../pages/home-page.po';
let home: HomePage;
Before(() => {
home = new HomePage();
});
Given('I am on the home page', async () => {
await home.navigateHome();
});
When('I do nothing', () => { });
Then('I should see the title', async () => {
expect(await home.getTitleText()).to.equal('Login');
});
specs: ['./src/features/*.feature'],
请更新配置中功能的路径。实际上没有检测到特征。
在场景之前的特征文件中添加@Regression