我是一名新程序员。我正在设置一个cucumber.io套件。我阅读文档并从https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md开始设置示例。当我运行提供的测试时,示例测试通过,如预期。当他们应该通过或失败时,显示为“正在等待”的Cucumber-js测试
方案:阅读文档
✔鉴于我对Cucumber.js GitHub的仓库
✔当我点击 “CLI”
✔然后我会看到 “运行特定功能”
1情形(1通过)
3个步骤(3通过)
0m03.724s
以示例为起点,当我添加另一个.feature和.js文件并运行测试时,我的新测试的所有操作都显示为“挂起”。另外,第一测试不再通过:
3方案(1暧昧,2未定义)
10步骤(2暧昧,7未定义,1通过)
0m03.743s
能任何人都告诉我我需要做什么才能让我的测试运行?我需要做些什么来消除模糊和未定义的测试?
我检查了我的正则表达式,它匹配。我知道我的缩进不在这里,但我是发布代码的新手!
我.feature文件:
Feature: Sign In
As a returning user of examples
I want to log in the site
So that I can use the site
Scenario: Getting to the Sign in page via "Log In"
Given I am on example.com
When I click the "Sign In" button
Then I am taken to the login screen
Scenario: Entering my information
Given I am on the login and I am the landing tab "Log In"
When I enter my credentials
And click the arrow
Then I am successfully logged in
我的测试:
var seleniumWebdriver = require('selenium-webdriver');
module.exports = function() {
this.Given(/^I am on I am on example.com$/, function() {
return this.driver.get('https://example.com');
});
this.When(/^I click on "([^"]*)"$/, function (text) {
return this.driver.findElement({linkText: text}).then(function(element) {
return element.click();
});
});
this.Then(/^I should see "([^"]*)"$/, function (text) {
var xpath = "//*[contains(text(),'" + text + "')]";
var condition = seleniumWebdriver.until.elementLocated({xpath: xpath});
return this.driver.wait(condition, 5000);
});
};
非常感谢你帮助我理解这一点。 @Grasshopper,当你说“你定义的步骤定义提到'我已经'两次了'你能告诉我在哪里?是否因为该步骤在两个功能文件中?我的许多功能将涉及访问同一网站 - 我如何区分每一步? – Laurie
this.Given(/ ^我在我上example.com $ /,函数() - 这是来自你在问题中共享的文件,你看到'我在'在这个模式中重复两次。将不匹配你已经定义了第二种情况的步骤,只是尝试为每个步骤编写单独的步骤定义,然后看看你是否可以使用模式来减少常见步骤 – Grasshopper
谢谢@grasshopper我甚至没有看到我犯了这个错字。我认为我现在开始了解更多。谢谢! – Laurie