0
votes

Protractor - Cucumber not picking values from Examples. I am using site "http://juliemr.github.io/protractor-demo/" in first text box it enters <key1> and <key2>.

Feature file is below

Feature: Navigate to calculator site and add two number

Scenario: Add two number using calculator site

Given Navigate to calculator site url "http://juliemr.github.io/protractor-demo/"

When Provide two numbers to add first number "< key1 >" and "< key2 >"

Then Click on add button on calculator site

Scenario Outline: Provide parameters

Examples:

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

Step definition file

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);
    })
});

Error Screen shot of calculator site

2
Not able to understand I am using Protractor with Typescript, trying to use cucumber with it. - Abhishek Sharma
Please refer the answer below - Bharath Kumar S

2 Answers

0
votes

Feature file

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 | 

Step def

 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);
});
0
votes

Please mention "Scenario Outline:" instead of "Scenario:" in the first line of your Feature file. Then it will be resolved. Otherwise everything is alright in your code. It should be like below:

 Scenario Outline: Add two number using calculator site

"Scenario Outline: Provide parameters"- Please remove this line from your feature file.