我是java脚本量角器黄瓜框架的新手。
我可以在一年前看到类似的问题,但这也是在一年前的量角器版本中修复的。因此提出了一个新问题。
我正在使用最新版本的黄瓜,量角器,量角器 - 黄瓜 - 框架,chai,chai-as-promise。我使用visual studio代码作为编辑器。 节点版本是6.11.4。有关所有版本的详细信息,请查看下面的package.json。
当我执行我的测试时,它会在不到一秒的时间内完成传递结果,但它只是启动浏览器然后在浏览器中没有做任何事情。
请查看我正在使用的文件,并建议我问题出在哪里。我不确定这是否是最新版本的量角器中的总线。
protractor.conf.js:
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['features/*.feature'],
getPageTimeout: 60000,
allScriptsTimeout: 500000,
baseURL: 'http://www.protractortest.org/testapp/ng1/#/form',
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
capabilities: {
'browserName': 'chrome'
},
cucumberOpts: {
require: [ './features/step_definitions/*.steps.js' ],
tags: false,
profile: false,
'no-source': true
}
};
的package.json:
{
"name": "protractor_test",
"version": "1.0.0",
"description": "",
"main": "protractor.conf.js",
"dependencies": {
"protractor": "^5.2.0",
"cucumber": "^3.1.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"@types/chai-as-promised": "^7.1.0",
"@types/cucumber": "^2.0.4",
"@types/protractor": "^4.0.0"
},
"devDependencies": {
"protractor-cucumber-framework": "^4.1.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
test.feature:
Feature: Running Cucumber with Protractor
As a user of Protractor
I should be able to use Cucumber
In order to run my E2E tests
Scenario: Login to myApp
Given I go to Login page
When I login with "username" and "pwd"
Then "You are logged in as ADMIN" is displayed
test.steps.js:
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function () {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true);
});
When('I login with {string} and {string}', function (username, password) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click();
});
Then('{string} is displayed', function (headerText) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true);
});
});
控制台输出:
Debugging with legacy protocol because Node.js v6.11.4 was detected.
'C:\Program Files\nodejs\node.exe' --debug-brk=38084 --nolazy node_modules\protractor\bin\protractor protractor.conf.js
Debugger listening on [::]:38084
[16:48:02] I/launcher - Running 1 instances of WebDriver
[16:48:02] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
...
1 scenario (1 passed)
3 steps (3 passed)
0m00.015s
[16:48:05] I/launcher - 0 instance(s) of WebDriver still running
[16:48:05] I/launcher - chrome #01 passed
Selenium Chrome节点控制台输出:
Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 11099
Only local connections are allowed.
16:48:04.496 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:04.496 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.496 INFO - To upstream: {"script":500000}
16:48:04.496 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":13,"value":{"message":"unknown error: 'ms' must be a double\n (Session info: chrome=60.0.3112.78)\n (Driver info: chromedriver=2.33.506120 (e3e
53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
16:48:04.512 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:04.512 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/timeouts (handler: ServicedSession)
16:48:04.512 INFO - To upstream: {"type":"script","ms":500000}
16:48:04.527 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.010 INFO - Found handler: org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing DELETE on /session/ed9fb79d586bc77176974953aaf98ef2 (handler: ServicedSession)
16:48:05.010 INFO - Handler thread for session ed9fb79d586bc77176974953aaf98ef2 (chrome): Executing POST on /session/ed9fb79d586bc77176974953aaf98ef2/url (handler: ServicedSession)
16:48:05.026 INFO - To upstream: {"url":"data:text/html,<html></html>"}
16:48:05.088 INFO - To downstream: {"sessionId":"ed9fb79d586bc77176974953aaf98ef2","status":0,"value":null}
16:48:05.088 INFO - Removing session org.openqa.selenium.remote.server.ServicedSession@1418ca00
16:48:05.138 INFO - To downstream: {"sessionId":"","status":0,"value":null}
16:48:05.138 INFO - To downstream: {"sessionId":"","status":6,"value":{"message":"no such session\n (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.3.9600 x86_64)"}}
答案 0 :(得分:7)
您可以尝试使用回调参数而不是依赖承诺。如果有效,那么输入用户名&amp;密码,你可以使用Q包来解决所有的承诺。
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
var {defineSupportCode} = require('cucumber');
var expect = chai.expect;
chai.use(chaiAsPromised);
defineSupportCode(function({Given, When, Then}) {
Given('I go to DSH Login page', function (callback) {
browser.get("http://localhost/myapp");
expect(element(by.buttonText('Login')).isDisplayed()).to.eventually.equal(true).and.notify(callback);
});
When('I login with {string} and {string}', function (username, password, callback) {
element(by.id('username')).sendKeys(username);
element(by.id('password')).sendKeys(password);
element(by.buttonText('Login')).click().then(function() {
callback();
});
});
Then('{string} is displayed', function (headerText, callback) {
expect(element(by.cssContainingText('ng-isolate-scope', headerText)).isDisplayed()).to.eventually.equal(true).notify(callback);
});
});
答案 1 :(得分:0)
由于我已经习惯了Javascript,我想我会发布我目前正在做的事情。
我已停止使用回调。相反,我使用async和await,以便控件等待异步操作完成。
例如:
When('I login with {string} and {string}', async function (username, password) {
await element(by.id('username')).sendKeys(username);
await element(by.id('password')).sendKeys(password);
await element(by.buttonText('Login')).click();
});
希望这有助于某人。