【发布时间】:2019-11-11 14:03:47
【问题描述】:
我们是使用 Protractor 的新手,已按照以下链接尝试测试设置。 http://maushamgupta.blogspot.com/2016/09/getting-started-with-protractor-cucumber.html
下面是conf文件(命名为protractor.conf.js)。
var config;
config = {
//chromeDriver:'path\\to\\your\\chromedriver.exe',
//seleniumArgs: ['-Dwebdriver.ie.driver=path\\to\\your\\IEDriverServer.exe'], //incase you want to test your application on internet explorer
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
specs: 'testwithpro.feature',
capabilities: {
browserName: 'chrome'
},
framework: 'custom', // need to add for protractor 3.x and above
frameworkPath: './node_modules/protractor-cucumber-framework', // need to add for protractor
output:'./output.json', //3.x and above
cucumberOpts: {
// define your step definitions in this file
require: ['./testwithpro.js'],
//format: './node_modules/pretty',
tags:'false'
}
};
exports.config = config;
testwithpro.feature
功能:测试应用程序
场景:测试登录 鉴于我在登录页面 当我输入用户名 我输入密码 然后我点击登录按钮 然后我应该看到主页
testwithpro.js
var myStepDefinitionsWrapper = function () {
this.Given(/^I am on the login page$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
console.log('testing');
browser.ignoreSynchronization=true; // To be added if the application is non-angular
browser.driver.manage().window().maximize(); // To maximize the window
//browser.get("https://www.facebook.com").then(function(){
// callback(); // To tell the cucumber that we are done with this step
//})
browser.get("https://www.facebook.com");
browser.wait(function () {
browser.sleep(10000);
callback(); // To tell the cucumber that we are done with this step
}, 20 * 10000);
});
this.When(/^I enter username$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
element(by.id("email")).sendKeys("abc@gmail.com").then(function(){
callback();
});
});
this.When(/^I enter password$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
element(by.id("pass")).sendKeys("*****").then(function(){
callback();
});
});
this.When(/^I click on login button$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
element(by.id("u_0_l")).click().then(function(){
callback();
});
});
};
module.exports = myStepDefinitionsWrapper;
package.json (量角器-黄瓜-框架)
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-like": "^0.2.14",
"eslint": "^5.4.0",
"eslint-config-prettier": "^3.0.1",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-prettier": "^2.6.2",
"express": "^4.16.3",
"httpster": "^1.0.4",
"mocha": "^5.2.0",
"multidep": "2.0.2",
"prettier": "^1.14.2",
"protractor": "^5.4.0"
package.json(量角器)
“依赖”:{ "@types/q": "^0.0.32", "@types/selenium-webdriver": "^3.0.0", “阻塞代理”:“^1.0.0”, "browserstack": "^1.5.1", "粉笔": "^1.1.3", "glob": "^7.0.3", “茉莉花”:“2.8.0”, "jasminewd2": "^2.1.0", "乐观主义者": "~0.6.0", “q”:“1.4.1”, “酱实验室”:“^1.5.0”, "selenium-webdriver": "3.6.0", “源地图支持”:“〜0.4.0”, "webdriver-js-extender": "2.1.0", “网络驱动程序管理器”:“^12.0.6” }, “弃用”:错误, "description": "Angular 的 Webdriver E2E 测试包装器。", “开发依赖”:{ "@types/chalk": "^0.4.28", "@types/glob": "^5.0.29", "@types/jasmine": "^2.5.47", "@types/jasminewd2": "^2.0.0", "@types/minimatch": "^2.0.28", "@types/minimist": "^1.1.28", "@types/node": "^6.0.46", "@types/optimist": "^0.0.29", "body-parser": "~1.15.2", "柴": "~3.5.0", "chai-as-promised": "~5.3.0", “clang 格式”:“1.0.49”, “expect.js”:“~0.3.1”, “快递”:“~4.14.0”, "吞咽": "^3.9.1", “gulp-clang 格式”:“1.0.23”, "gulp-tslint": "^7.0.1", "jshint": "^2.9.2", "lodash": "^4.5.1", "标记": "^0.3.3", “摩卡”:“2.5.3”, "rimraf": "~2.5.3", “运行序列”:“^1.1.5”, "semver": "^5.3.0", "tslint": "^4.1.1", "tslint-eslint-rules": "^3.1.0", “打字稿”:“^2.1.5”, “vrsource-tslint-rules”:“^4.0.1” },
package.json(黄瓜)
“依赖”:{ "@babel/polyfill": "^7.2.3", “断言错误格式化程序”:“^2.0.1”, "蓝鸟": "^3.4.1", "cli-table3": "^0.5.1", "颜色": "^1.1.2", “指挥官”:“^2.9.0”, “交叉生成”:“^6.0.5”, “黄瓜表达式”:“^6.0.0”, “黄瓜标签表达式”:“^1.1.1”, “持续时间”:“^0.2.1”, “转义字符串正则表达式”:“^1.0.5”, “数字”:“2.0.0”, "小黄瓜": "^5.0.0", "glob": "^7.1.3", "缩进字符串": "^3.1.0", "is-generator": "^1.0.2", “是流”:“^1.1.0”, "knuth-shuffle-seed": "^1.0.6", "lodash": "^4.17.10", "mz": "^2.4.0", "进度": "^2.0.0", “解决”:“^1.3.3”, “序列化错误”:“^3.0.0”, “堆栈链”:“^2.0.0”, "stacktrace-js": "^2.0.0", “字符串-argv”:“0.1.1”, “标题案例”:“^2.1.1”, “实用程序”:“^1.0.2”, “verror”:“^1.9.0” }, “弃用”:错误, "description": "Cucumber 的官方 JavaScript 实现。", “开发依赖”:{ "@babel/cli": "^7.2.3", "@babel/core": "^7.2.2", "@babel/plugin-proposal-function-bind": "^7.2.0", "@babel/preset-env": "^7.2.3", "@babel/register": "^7.0.0", "ansi-html": "^0.0.7", "babel-eslint": "^10.0.1", "babel-plugin-istanbul": "^5.1.0", "babelify": "^10.0.0", “浏览”:“16.2.2”, "柴": "^4.0.1", “咖啡脚本”:“^1.10.0”, "连接": "^3.4.0", "工作服": "^3.0.0", "依赖-lint": "^5.0.1", "eslint": "^5.10.0", "eslint-config-prettier": "^3.3.0", "eslint-config-standard": "^12.0.0", "eslint-plugin-babel": "^5.3.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-node": "^8.0.0", "eslint-plugin-prettier": "^3.0.0", "eslint-plugin-promise": "^4.0.1", "eslint-plugin-standard": "^4.0.0", "fs-extra": "^6.0.1", "摩卡": "^5.2.0", “小胡子”:“^2.3.0”, “纽约”:“^12.0.2”, “更漂亮”:“^1.5.2”, “服务静态”:“^1.10.0”, "sinon": "^6.0.0", "sinon-chai": "^3.2.0", “流到字符串”:“^1.1.0”, “tmp”:“^0.0.33” },
当我们运行cmd“protractor protractor.conf.js”时,终端显示的输出是这样的-
[23:02:58] I/launcher - 运行 1 个 WebDriver 实例 [23:02:58] I/hosted - 在 http://127.0.0.1:4444/wd/hub 使用 selenium 服务器
0 个场景 0 步 0m00.000s [23:03:02] I/launcher - 0 个 WebDriver 实例仍在运行 [23:03:02] I/launcher - chrome #01 已通过
它不处理功能文件中的场景,也不启动测试定义js文件中定义的网页。奇怪的是,即使我们将 specs 文件名更改为“1testwithpro.feature”(这样它不存在),也会显示相同的输出。不会抛出任何错误。
请让我们知道我们可能做错了什么。感谢您的帮助。
【问题讨论】:
-
specs需要一个数组。试试specs: ['testwithpro.feature'], -
我试过了,结果还是一样——0个场景,0个步骤
-
你能展示你的项目文件夹结构,它可以说明
protractor.conf.js和testwithpro.feature的相对路径 -
所有 3 个文件都在同一个文件夹中 - protractor.conf.js、testwithpro.feature 和 testwithpro.js
-
请出示您的
package.json和testwithpro.feature
标签: protractor cucumber cucumberjs