我们是使用量角器的新手,已经按照下面的链接尝试测试设置。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","jasmine":"2.8.0","jasminewd2":"^2.1.0",“乐观主义者”:"~0.6.0","q":"1.4.1","saucelabs":"^1.5.0","selenium-webdriver":"3.6.0","source-map-support":"~0.4.0","webdriver-js-extender":"2.1.0","webdriver-manager":"^12.0.6“},”已弃用“:false,"description":”Angular的Webdriver E2E测试包装。“,"devDependencies":{ "@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","chai":"~3.5.0","chai-as-promised":"~5.3.0","clang-format":"1.0.49","expect.js":"~0.3.1","express":"~4.14.0","gulp":"^3.9.1",“gulp clang-format”:"1.0.23","gulp-tslint":"^7.0.1","jshint":"^2.9.2","lodash":"^4.5.1","marked":"^0.3.3","mocha":"2.5.3","rimraf":"~2.5.3","run-sequence":"^1.1.5","semver":"^5.3.0","tslint":"^4.1.1","tslint-eslint-rules":"^3.1.0","typescript":"^2.1.5","vrsource-tslint-rules":"^4.0.1“},
黄瓜( package.json )
“依赖关系”:{ "@babel/polyfill":"^7.2.3","assertion-error-formatter":"^2.0.1","bluebird":"^3.4.1","cli-table3":"^0.5.1","colors":"^1.1.2","commander":"^2.9.0",“交叉衍生”:"^6.0.5",“cucumber-expression”:"^6.0.0",“cucumber-tag-expression”:"^1.1.1","duration":"^0.2.1","escape-string-regexp":"^1.0.5","figures":"2.0.0","gherkin":"^5.0.0","glob":"^7.1.3",“缩进字符串”:"^3.1.0",“is-生成器”:"^1.0.2","is-stream":"^1.1.0","knuth-shuffle-seeded":"^1.0.6","lodash":"^4.17.10","mz":"^2.4.0","progress":"^2.0.0","resolve":"^1.3.3","serialize-error":"^3.0.0","stack-chain":"^2.0.0","stacktrace-js":"^2.0.0","string-argv":"0.1.1","title-case":"^2.1.1","util-arity":"^1.0.2","verror":"^1.9.0“},”已弃用“:false,"description":”黄瓜的官方JavaScript实现。“,"devDependencies":{ "@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-babel”:"^5.1.0","babelify":"^10.0.0","browserify":"16.2.2","chai":"^4.0.1",“coffee script”:"^1.10.0","connect":"^3.4.0","coveralls":"^3.0.0","dependency-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","mocha":"^5.2.0","mustache":"^2.3.0","nyc":"^12.0.2",“漂亮”:"^1.5.2","serve-static":"^1.10.0","sinon":"^6.0.0","sinon-chai":"^3.2.0","stream-to-string":"^1.1.0","tmp":"^0.0.33“},
当我们运行命令"protractor protractor.conf.js“时,terminal中显示的输出是-
23:02:58I/launcher-运行1个WebDriver实例23:02:58I/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“(这样它就不存在),也会显示相同的输出。不会抛出错误。
请让我们知道我们可能做错了什么。感谢你的帮助。
发布于 2019-07-06 04:35:28
将specs: 'testwithpro.feature'更改为specs: ['./testwithpro.feature']
删除cucumberOpts对象中的tags。
cucumberOpts: {
require: ['./testwithpro.js']
},
specs: ['./testwithpro.feature']https://stackoverflow.com/questions/56826788
复制相似问题