我是一名新程序员。我正在尝试建立一个cucumber.io套件。我阅读了文档,并从https://github.com/cucumber/cucumber-js/blob/master/docs/nodejs_example.md设置了示例。当我运行提供的测试时,示例测试将按预期通过。
场景:阅读文档
✔鉴于我在Cucumber.js GitHub存储库
✔当我点击“CLI”
时✔然后我应该看到“运行特定功能”
1个场景(1个通过)
3个步骤(3个过去)
0m03.724s
使用该示例作为起点,当我添加另一个.feature和.js文件并运行测试时,我的新测试的所有操作都显示为“pending”。此外,第一次测试不再通过:
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);
});
};
答案 0 :(得分:0)
原始场景 -
Scenario:
Given I am on the Cucumber.js GitHub repository - PASSED - This is the only step that passes that is present only in the original feature file.
When I click on "CLI" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created.
Then I should see "Running specific features" - AMBIGIOUS - This step is present in original feature file as well as the new feature file you created.
新方案 -
Scenario: Getting to the Sign in page via "Log In"
Given I am on example.com - UNDEFINED - The step definition you have defined mentions 'I am on' twice instead of once.
When I click the "Sign In" button - UNDEFINED - No matching step.
Then I am taken to the login screen - UNDEFINED - No matching step.
Scenario: Entering my information
Given I am on the login and I am the landing tab "Log In" - UNDEFINED - No matching step.
When I enter my credentials - UNDEFINED - No matching step.
And click the arrow - UNDEFINED - No matching step.
Then I am successfully logged in - UNDEFINED - No matching step.
因此你得到7个未定义,2个含糊不清,1个通过步骤。所以第一个原始场景变得模棱两可,另外两个未定义。
您需要从新的test.js中删除重复的步骤,并添加新的步骤定义以匹配新的方案步骤。