量角器-黄瓜未从示例中选择值

时间:2020-07-18 10:46:37

标签: protractor cucumber

量角器-黄瓜未从示例中选择值。我在第一个文本框中使用站点“ http://juliemr.github.io/protractor-demo/”,它输入<key1><key2>

功能文件在下面

功能:导航到计算器站点并添加两个数字

方案:使用计算器网站添加两个数字

给出导航到计算器站点网址“ http://juliemr.github.io/protractor-demo/”

当提供两个数字以添加第一个数字“ < key1 >”和“ < key2 >

然后点击计算器网站上的添加按钮

方案概述:提供参数

示例:

| key1 | key2 |
|  2   |  3   |
|  2   | 60   |

步骤定义文件

import { Given, When, Then } from "cucumber";
import { browser } from "protractor";
import { calculator } from "../pageObjects/calculator";

let cal = new calculator();
Given('Navigate to calculator site url {string}', async (string)=> {
    // Write code here that turns the phrase above into concrete actions
    await browser.get(string);
});

When('Provide two numbers to add first number {string} and {string}', async (firstValue:string, 
secondvalue:string)=> {
    // Write code here that turns the phrase above into concrete actions
    await cal.firstEditBox.sendKeys(firstValue);
    await cal.secondEditBox.sendKeys(secondvalue);
});

Then('Click on add button on calculator site', async ()=> {
    // Write code here that turns the phrase above into concrete actions
    await cal.goButton.click;
    cal.getResult.getText().then(function(text) {
      console.log(text);
    })
});

错误 Screen shot of calculator site

2 个答案:

答案 0 :(得分:0)

功能文件

Feature: To search keywords in google

@OutlineScenario
Scenario Outline: Searching on google
  
  Given I am on "<search>" search page
  When I type "<search keyword>"
  Then I click on search button
  Then I clear the search text

  Examples:
    | search | search keyword | 
    |  google   | cucumber |
    |  cucumber | protractor |
    |  protractor | typescript | 

步骤定义

 Given(/^I am on "(.*?)" search page$/, async (text) => {
     if (text === "google") {
         await expect(browser.getTitle()).to.eventually.equal("Google");
     } else if (text === "cucumber") {
         await expect(browser.getTitle()).to.eventually.equal(text + " - Google Search");
     } else if (text === "protractor") {
         await expect(browser.getTitle()).to.eventually.equal(text + " - Google Search");
     } 
 });

When(/^I type "(.*?)"$/, async (text) => {
    await search.searchTextBox.sendKeys(text);
});

答案 1 :(得分:0)

请在功能文件第一行中提及“方案概述:”,而不是“方案:”。然后它将解决。否则,您的代码中的一切都将正常。如下所示:

 Scenario Outline: Add two number using calculator site

“方案概述:提供参数”-请从功能文件中删除此行。