无法读取量角器黄瓜 e2e 测试的步骤定义文件
Not able to read the step definitions files of Protractor cucumber e2e tests
我是量角器的新手。
我将量角器与打字稿和 Serenity js 库一起用于报告目的。
项目结构:Project Structure
问题日志:
PS R:\protractor\protractorcucumber_typescript> tsc
PS R:\protractor\protractorcucumber_typescript> npm test
> protractorcucumber_typescript@3.0.0 pretest R:\protractor\protractorcucumber_typescript
> serenity update
info: Serenity BDD CLI jar file is up to date :-)
> protractorcucumber_typescript@3.0.0 test R:\protractor\protractorcucumber_typescript
> protractor protractor.conf.js
(node:9804) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[16:05:03] I/launcher - Running 1 instances of WebDriver
[16:05:03] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
Feature: Angular Home Page
@CucumberScenario
Scenario: angularjs homepage Menu header list
16:05:08.492 | SceneStarts: angularjs homepage Menu header list (category: Angular Home Page, path: R:\protractor\protractorcucumber_types
cript\features\AngularHomepage\AngularHome.feature:4, id: Angular Home Page:4:angularjs homepage Menu header list)
16:05:08.541 | ActivityStarts: Given I visit the Angular homepage
? Given I visit the Angular homepage
16:05:08.564 | ActivityFinished: Given I visit the Angular homepage (result: PENDING)
16:05:08.568 | ActivityStarts: Then Clicking on the Learn Header menu element on the page
? Then Clicking on the Learn Header menu element on the page
16:05:08.574 | ActivityFinished: Then Clicking on the Learn Header menu element on the page (result: PENDING)
16:05:08.576 | ActivityStarts: Then Counting the dropDown list of learn menu Header
? Then Counting the dropDown list of learn menu Header
16:05:08.588 | ActivityFinished: Then Counting the dropDown list of learn menu Header (result: PENDING)
16:05:08.592 | SceneFinished: angularjs homepage Menu header list (category: Angular Home Page, path: R:\protractor\protractorcucumber_typ
escript\features\AngularHomepage\AngularHome.feature:4, id: Angular Home Page:4:angularjs homepage Menu header list) (result: PENDING)
@CucumberScenario
Scenario: Typing the name in The basics tab of Home page
16:05:08.615 | SceneStarts: Typing the name in The basics tab of Home page (category: Angular Home Page, path: R:\protractor\protractorcuc
umber_typescript\features\AngularHomepage\AngularHome.feature:10, id: Angular Home Page:10:Typing the name in The basics tab of Home page)
16:05:08.660 | ActivityStarts: Given I visit the Angular homepage
? Given I visit the Angular homepage
16:05:08.672 | ActivityFinished: Given I visit the Angular homepage (result: PENDING)
16:05:08.676 | ActivityStarts: Then Enterting text in name box of The Basics tab
? Then Enterting text in name box of The Basics tab
16:05:08.682 | ActivityFinished: Then Enterting text in name box of The Basics tab (result: PENDING)
16:05:08.686 | SceneFinished: Typing the name in The basics tab of Home page (category: Angular Home Page, path: R:\protractor\protractorc
ucumber_typescript\features\AngularHomepage\AngularHome.feature:10, id: Angular Home Page:10:Typing the name in The basics tab of Home pag
e) (result: PENDING)
Warnings:
1) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Given I visit the Angular homepage - features\AngularHomepage\AngularHome.feature:5
Message:
Undefined. Implement with the following snippet:
this.Given(/^I visit the Angular homepage$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
2) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Then Clicking on the Learn Header menu element on the page - features\AngularHomepage\AngularHome.feature:6
Message:
Undefined. Implement with the following snippet:
this.Then(/^Clicking on the Learn Header menu element on the page$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
3) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Then Counting the dropDown list of learn menu Header - features\AngularHomepage\AngularHome.feature:7
Message:
Undefined. Implement with the following snippet:
this.Then(/^Counting the dropDown list of learn menu Header$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
4) Scenario: Typing the name in The basics tab of Home page - features\AngularHomepage\AngularHome.feature:10
Step: Given I visit the Angular homepage - features\AngularHomepage\AngularHome.feature:11
Message:
Undefined. Implement with the following snippet:
this.Given(/^I visit the Angular homepage$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
5) Scenario: Typing the name in The basics tab of Home page - features\AngularHomepage\AngularHome.feature:10
Step: Then Enterting text in name box of The Basics tab - features\AngularHomepage\AngularHome.feature:12
Message:
Undefined. Implement with the following snippet:
this.Then(/^Enterting text in name box of The Basics tab$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
2 scenarios (2 undefined)
5 steps (5 undefined)
0m00.040s
[16:05:18] I/launcher - 0 instance(s) of WebDriver still running
[16:05:18] I/launcher - chrome #01 通过
我的配置文件:protractor.conf.ts
import * as path from "path";
import { browser, Config } from "protractor";
const crew = require('serenity-js/lib/stage_crew');
export const config = {
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
SELENIUM_PROMISE_MANAGER: false,
framework: "custom",
frameworkPath: require.resolve('serenity-js'),
serenity: {
dialect: 'cucumber',
crew: [
crew.serenityBDDReporter(),
crew.photographer(),
crew.consoleReporter()
]
},
specs: ['./features/**/*.feature'],
cucumberOpts: {
require: ['/features/**/*Page.ts'],
format: "pretty",
compiler: "ts:ts-node/register",
// require: ['/features/**/*.ts'], // not working
// require: ['/features/stepdefinitions/**/*Page.ts'] // Not working
// The below are tried with config.ts file
// require: ['./features/stepdefinitions/*Page.ts', './features/stepdefinitions/*Page.ts']
// require: ['./features/stepdefinitions/*.ts'], // Not working
// require: ['./features/stepdefinitions/**/*.ts','./features/stepdefinitions/**/*.js'], // Not sure.
// require: ['../../features/**/*.ts','../../features/**/*.js'], // unable to read files
// require: ['./features/**/*.ts','./features/**/*.js'], // unable to read files
// strict: true // getting Error: TypeError: Path must be a string. Received true - if enabled
// require: [process.cwd()+'./features/**/*.ts',process.cwd()+'./features/**/*.js'], // unable to read files
// require: [process.cwd()+'./features/stepdefinitions/*.ts',process.cwd()+'./features/**/*.js'], // unable to read files
},
capabilities: {
browserName: "chrome",
},
onPrepare: () => {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
browser.get("https://angularjs.org/");
},
};
功能文件:AngularHome.feature
功能:Angular 主页
@CucumberScenario
场景:angularjs首页菜单header列表
假设我访问了 Angular 主页
然后单击页面上的 Learn Header 菜单元素
然后统计学习菜单的下拉列表Header
@CucumberScenario
场景:在主页的基本选项卡中键入名称
假设我访问了 Angular 主页
然后在“基本信息”选项卡的名称框中输入文本
我的angularHomePage.ts文件-
import { browser, by, element } from "protractor";
import { homePage } from "../../pages/HomePage";
var { Given, When, Then } = require("cucumber");
const chai = require("chai").use(require("chai-as-promised"));
const expect = chai.expect;
const home_p: homePage = new homePage();
this.Given(/^I visit the Angular homepage$/, function (callback) {
browser.getTitle();
callback(null, 'pending');
});
this.Then(/^Clicking on the Learn Header menu element on the page$/,function (callback) {
var ele = element(by.xpath(".//*[@id='navbar-main']/div/div/ul/li[1]/a")).click();
callback(ele, 'pending');
});
Then(/^Counting the dropDown list of learn menu Header$/, async () => {
var learnList = element.all(by.xpath("//a[text()='Learn']/../ul//li"));
await expect(learnList.count()).to.eventually.equal(5);
learnList.count().then(function(size){
console.log(size);
});
for (var i = 0; i < learnList.length; i++) {
element.all(by.xpath("//a[text()='Learn']/../ul//li//a")).get(i).getText().then(function (text) {
console.log(text);
});
}
});
Then (/^Entering text in name box of the Basics tab$/,async() => {
等待元素(by.model('yourName')).sendKeys("RamaSwamy");
await element(by.css('.well .ng-binding')).getText().then(function(text){
console.log(text)
}); });
我的页面class - homePage.ts
import { $ } from "protractor";
import { browser, element, by } from 'protractor';
export class homePage {
public toDoList: any;
public valueAdd: any;
public toDoListCount: any;
constructor() {
// The below elements are of this site http://www.protractortest.org/#/
this.toDoList = element(by.model('todoList.todoText'));
this.valueAdd = element(by.css('[value="add"]'));
this.toDoListCount = element.all(by.repeater('todo in todoList.todos'));
}
};
我的package.json文件
"main": "index.js",
"scripts": {
"build": "tsc",
"clean": "rimraf typeScript/",
"clean-build": "npm run clean && npm run build",
"test": "protractor protractor.conf.js",
"pretest": "serenity update",
"report": "serenity run",
"webdriver-update": "webdriver-manager update",
"webdriver-start": "webdriver-manager start"
},
"devDependencies": {
"@types/cucumber": "^2.0.1",
"@types/node": "^8.0.3",
"@types/selenium-webdriver": "^3.0.7",
"chai": "^4.0.2",
"chai-as-promised": "^7.0.0",
"cucumber": "1.3.2",
"cucumber-html-reporter": "^3.0.4",
"mkdirp": "^0.5.1",
"protractor": "^5.1.2",
"rimraf": "^2.6.2",
"serenity-cli": "^0.7.0",
"serenity-js": "1.4.1",
"ts-node": "^3.3.0",
"typescript": "^2.5.3"
},
"dependencies": {
"@types/chai": "^4.0.4"
}
问题描述 - 我的步骤定义文件未被识别。它显示未定义的消息。
我使用的是 Cucumber 1.3.3 而不是 Cucumber 3。在带有 serenity 库的 Cucumber 3 中,缺少一个 class 文件,而且关于 serenity 库的报告比 Cucumber 报告更容易理解。
我猜我的步骤文件路径不对。所以也尝试了不同的路径。但运气不好。
生成宁静报告。我需要 运行 - npm 运行 报告。最后。
但所有步骤都处于待定状态,附上下图。
Serenity Report
求助,为什么无法识别步骤?
为什么它们未定义?
问题与 Cucumber 配置有关,而不是 Serenity/JS。
您的项目位于:
R:\protractor\protractorcucumber_typescript
您在该目录中有一个 protractor.conf.ts
文件:
R:\protractor\protractorcucumber_typescript\protractor.conf.ts
您的功能文件位于 features
下:
R:\protractor\protractorcucumber_typescript\features
这一切都说得通,但是在 protractor.conf.ts
中您声明了以下内容:
specs: ['./features/**/*.feature'], // `./` is unnecessary here
cucumberOpts: {
require: ['/features/**/*Page.ts'], // the first slash incorrectly indicates the root directory, so R:\ in your case
format: "pretty",
compiler: "ts:ts-node/register",
},
相反,以与 the seed project 中相同的方式指定路径,因此:
specs: ['features/**/*.feature'], // no `./`
cucumberOpts: {
require: ['features/**/*.ts'], // no forward slash at the beginning
format: "pretty",
compiler: "ts:ts-node/register",
},
希望对您有所帮助!
一月
我是量角器的新手。
我将量角器与打字稿和 Serenity js 库一起用于报告目的。
项目结构:Project Structure
问题日志:
PS R:\protractor\protractorcucumber_typescript> tsc
PS R:\protractor\protractorcucumber_typescript> npm test
> protractorcucumber_typescript@3.0.0 pretest R:\protractor\protractorcucumber_typescript
> serenity update
info: Serenity BDD CLI jar file is up to date :-)
> protractorcucumber_typescript@3.0.0 test R:\protractor\protractorcucumber_typescript
> protractor protractor.conf.js
(node:9804) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
[16:05:03] I/launcher - Running 1 instances of WebDriver
[16:05:03] I/hosted - Using the selenium server at http://127.0.0.1:4444/wd/hub
Feature: Angular Home Page
@CucumberScenario
Scenario: angularjs homepage Menu header list
16:05:08.492 | SceneStarts: angularjs homepage Menu header list (category: Angular Home Page, path: R:\protractor\protractorcucumber_types
cript\features\AngularHomepage\AngularHome.feature:4, id: Angular Home Page:4:angularjs homepage Menu header list)
16:05:08.541 | ActivityStarts: Given I visit the Angular homepage
? Given I visit the Angular homepage
16:05:08.564 | ActivityFinished: Given I visit the Angular homepage (result: PENDING)
16:05:08.568 | ActivityStarts: Then Clicking on the Learn Header menu element on the page
? Then Clicking on the Learn Header menu element on the page
16:05:08.574 | ActivityFinished: Then Clicking on the Learn Header menu element on the page (result: PENDING)
16:05:08.576 | ActivityStarts: Then Counting the dropDown list of learn menu Header
? Then Counting the dropDown list of learn menu Header
16:05:08.588 | ActivityFinished: Then Counting the dropDown list of learn menu Header (result: PENDING)
16:05:08.592 | SceneFinished: angularjs homepage Menu header list (category: Angular Home Page, path: R:\protractor\protractorcucumber_typ
escript\features\AngularHomepage\AngularHome.feature:4, id: Angular Home Page:4:angularjs homepage Menu header list) (result: PENDING)
@CucumberScenario
Scenario: Typing the name in The basics tab of Home page
16:05:08.615 | SceneStarts: Typing the name in The basics tab of Home page (category: Angular Home Page, path: R:\protractor\protractorcuc
umber_typescript\features\AngularHomepage\AngularHome.feature:10, id: Angular Home Page:10:Typing the name in The basics tab of Home page)
16:05:08.660 | ActivityStarts: Given I visit the Angular homepage
? Given I visit the Angular homepage
16:05:08.672 | ActivityFinished: Given I visit the Angular homepage (result: PENDING)
16:05:08.676 | ActivityStarts: Then Enterting text in name box of The Basics tab
? Then Enterting text in name box of The Basics tab
16:05:08.682 | ActivityFinished: Then Enterting text in name box of The Basics tab (result: PENDING)
16:05:08.686 | SceneFinished: Typing the name in The basics tab of Home page (category: Angular Home Page, path: R:\protractor\protractorc
ucumber_typescript\features\AngularHomepage\AngularHome.feature:10, id: Angular Home Page:10:Typing the name in The basics tab of Home pag
e) (result: PENDING)
Warnings:
1) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Given I visit the Angular homepage - features\AngularHomepage\AngularHome.feature:5
Message:
Undefined. Implement with the following snippet:
this.Given(/^I visit the Angular homepage$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
2) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Then Clicking on the Learn Header menu element on the page - features\AngularHomepage\AngularHome.feature:6
Message:
Undefined. Implement with the following snippet:
this.Then(/^Clicking on the Learn Header menu element on the page$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
3) Scenario: angularjs homepage Menu header list - features\AngularHomepage\AngularHome.feature:4
Step: Then Counting the dropDown list of learn menu Header - features\AngularHomepage\AngularHome.feature:7
Message:
Undefined. Implement with the following snippet:
this.Then(/^Counting the dropDown list of learn menu Header$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
4) Scenario: Typing the name in The basics tab of Home page - features\AngularHomepage\AngularHome.feature:10
Step: Given I visit the Angular homepage - features\AngularHomepage\AngularHome.feature:11
Message:
Undefined. Implement with the following snippet:
this.Given(/^I visit the Angular homepage$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
5) Scenario: Typing the name in The basics tab of Home page - features\AngularHomepage\AngularHome.feature:10
Step: Then Enterting text in name box of The Basics tab - features\AngularHomepage\AngularHome.feature:12
Message:
Undefined. Implement with the following snippet:
this.Then(/^Enterting text in name box of The Basics tab$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback(null, 'pending');
});
2 scenarios (2 undefined)
5 steps (5 undefined)
0m00.040s
[16:05:18] I/launcher - 0 instance(s) of WebDriver still running
[16:05:18] I/launcher - chrome #01 通过
我的配置文件:protractor.conf.ts
import * as path from "path";
import { browser, Config } from "protractor";
const crew = require('serenity-js/lib/stage_crew');
export const config = {
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
SELENIUM_PROMISE_MANAGER: false,
framework: "custom",
frameworkPath: require.resolve('serenity-js'),
serenity: {
dialect: 'cucumber',
crew: [
crew.serenityBDDReporter(),
crew.photographer(),
crew.consoleReporter()
]
},
specs: ['./features/**/*.feature'],
cucumberOpts: {
require: ['/features/**/*Page.ts'],
format: "pretty",
compiler: "ts:ts-node/register",
// require: ['/features/**/*.ts'], // not working
// require: ['/features/stepdefinitions/**/*Page.ts'] // Not working
// The below are tried with config.ts file
// require: ['./features/stepdefinitions/*Page.ts', './features/stepdefinitions/*Page.ts']
// require: ['./features/stepdefinitions/*.ts'], // Not working
// require: ['./features/stepdefinitions/**/*.ts','./features/stepdefinitions/**/*.js'], // Not sure.
// require: ['../../features/**/*.ts','../../features/**/*.js'], // unable to read files
// require: ['./features/**/*.ts','./features/**/*.js'], // unable to read files
// strict: true // getting Error: TypeError: Path must be a string. Received true - if enabled
// require: [process.cwd()+'./features/**/*.ts',process.cwd()+'./features/**/*.js'], // unable to read files
// require: [process.cwd()+'./features/stepdefinitions/*.ts',process.cwd()+'./features/**/*.js'], // unable to read files
},
capabilities: {
browserName: "chrome",
},
onPrepare: () => {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
browser.get("https://angularjs.org/");
},
};
功能文件:AngularHome.feature 功能:Angular 主页
@CucumberScenario 场景:angularjs首页菜单header列表 假设我访问了 Angular 主页 然后单击页面上的 Learn Header 菜单元素 然后统计学习菜单的下拉列表Header
@CucumberScenario 场景:在主页的基本选项卡中键入名称 假设我访问了 Angular 主页
然后在“基本信息”选项卡的名称框中输入文本
我的angularHomePage.ts文件-
import { browser, by, element } from "protractor";
import { homePage } from "../../pages/HomePage";
var { Given, When, Then } = require("cucumber");
const chai = require("chai").use(require("chai-as-promised"));
const expect = chai.expect;
const home_p: homePage = new homePage();
this.Given(/^I visit the Angular homepage$/, function (callback) {
browser.getTitle();
callback(null, 'pending');
});
this.Then(/^Clicking on the Learn Header menu element on the page$/,function (callback) {
var ele = element(by.xpath(".//*[@id='navbar-main']/div/div/ul/li[1]/a")).click();
callback(ele, 'pending');
});
Then(/^Counting the dropDown list of learn menu Header$/, async () => {
var learnList = element.all(by.xpath("//a[text()='Learn']/../ul//li"));
await expect(learnList.count()).to.eventually.equal(5);
learnList.count().then(function(size){
console.log(size);
});
for (var i = 0; i < learnList.length; i++) {
element.all(by.xpath("//a[text()='Learn']/../ul//li//a")).get(i).getText().then(function (text) {
console.log(text);
});
}
});
Then (/^Entering text in name box of the Basics tab$/,async() => { 等待元素(by.model('yourName')).sendKeys("RamaSwamy");
await element(by.css('.well .ng-binding')).getText().then(function(text){
console.log(text)
}); });
我的页面class - homePage.ts
import { $ } from "protractor";
import { browser, element, by } from 'protractor';
export class homePage {
public toDoList: any;
public valueAdd: any;
public toDoListCount: any;
constructor() {
// The below elements are of this site http://www.protractortest.org/#/
this.toDoList = element(by.model('todoList.todoText'));
this.valueAdd = element(by.css('[value="add"]'));
this.toDoListCount = element.all(by.repeater('todo in todoList.todos'));
}
};
我的package.json文件
"main": "index.js",
"scripts": {
"build": "tsc",
"clean": "rimraf typeScript/",
"clean-build": "npm run clean && npm run build",
"test": "protractor protractor.conf.js",
"pretest": "serenity update",
"report": "serenity run",
"webdriver-update": "webdriver-manager update",
"webdriver-start": "webdriver-manager start"
},
"devDependencies": {
"@types/cucumber": "^2.0.1",
"@types/node": "^8.0.3",
"@types/selenium-webdriver": "^3.0.7",
"chai": "^4.0.2",
"chai-as-promised": "^7.0.0",
"cucumber": "1.3.2",
"cucumber-html-reporter": "^3.0.4",
"mkdirp": "^0.5.1",
"protractor": "^5.1.2",
"rimraf": "^2.6.2",
"serenity-cli": "^0.7.0",
"serenity-js": "1.4.1",
"ts-node": "^3.3.0",
"typescript": "^2.5.3"
},
"dependencies": {
"@types/chai": "^4.0.4"
}
问题描述 - 我的步骤定义文件未被识别。它显示未定义的消息。
我使用的是 Cucumber 1.3.3 而不是 Cucumber 3。在带有 serenity 库的 Cucumber 3 中,缺少一个 class 文件,而且关于 serenity 库的报告比 Cucumber 报告更容易理解。
我猜我的步骤文件路径不对。所以也尝试了不同的路径。但运气不好。
生成宁静报告。我需要 运行 - npm 运行 报告。最后。 但所有步骤都处于待定状态,附上下图。 Serenity Report
求助,为什么无法识别步骤? 为什么它们未定义?
问题与 Cucumber 配置有关,而不是 Serenity/JS。
您的项目位于:
R:\protractor\protractorcucumber_typescript
您在该目录中有一个 protractor.conf.ts
文件:
R:\protractor\protractorcucumber_typescript\protractor.conf.ts
您的功能文件位于 features
下:
R:\protractor\protractorcucumber_typescript\features
这一切都说得通,但是在 protractor.conf.ts
中您声明了以下内容:
specs: ['./features/**/*.feature'], // `./` is unnecessary here
cucumberOpts: {
require: ['/features/**/*Page.ts'], // the first slash incorrectly indicates the root directory, so R:\ in your case
format: "pretty",
compiler: "ts:ts-node/register",
},
相反,以与 the seed project 中相同的方式指定路径,因此:
specs: ['features/**/*.feature'], // no `./`
cucumberOpts: {
require: ['features/**/*.ts'], // no forward slash at the beginning
format: "pretty",
compiler: "ts:ts-node/register",
},
希望对您有所帮助!
一月