-1

I am currently using intern with karma, TDD style. I want to switch to cucumber but it has been pretty difficult, as my project is extremely large and is already configured a certain way. I began thinking about using BDD with intern instead as it would be much easier, and I was wondering about how similar I can make BDD to Gherkin syntax?

Particularly, I like how you can specify {int} or {word} in cucumber step files. Is there anyway to do something similar in intern?

Any feedback on how close intern-bdd is to Gherkin/Cucumber would be very helpful.

user3611
  • 151
  • 2
  • 9

2 Answers2

1

Intern’s built-in bdd interface is similar to that of other JS testing systems, and is essentially just a different syntax for its tdd interface (describe and it vs suite and test). There’s no relation to Cucumber syntax.

There is an intern-cucumber plug-in that supports cucumber syntax, if you’d like to try that.

jason0x43
  • 3,363
  • 1
  • 16
  • 15
  • I have had a tremendous amount of issues trying to use this plugin. the plugin does not load because within the actual plugin file, i get an error saying that 'intern' is undefined (the global variable). I have no idea how to solve something like this – user3611 Oct 30 '19 at 14:09
  • I believe you mentioned in another question that you're not using Intern as the test runner? That may be the issue; Intern installs a global as part of its execution process, so if it's not starting up normally, the environment won't be setup for plugins. – jason0x43 Oct 30 '19 at 14:13
  • `'intern' is not defined -- plugin.js (2943,1)` – user3611 Oct 30 '19 at 14:15
  • Okay, I understand, its just that everything else with intern works. I can use the TDD and BDD or other interfaces normally, I wonder why loading a plugin is such a disaster. – user3611 Oct 30 '19 at 14:16
  • I just wish cucumber could be one of the interface options so I can avoid this mess - is there anyway I can manipulate [https://github.com/rhpijnacker/intern-cucumber] to work as an interface? – user3611 Oct 30 '19 at 14:19
  • any insight would help! – user3611 Oct 30 '19 at 15:09
  • Do you have a sample project somewhere? The difference between loading a plugin vs using one of Intern's interfaces is that Intern's interfaces are just library code you can import and use, while a plugin is a separate piece of code that expects to be able to communicate with a running instance of Intern. If Intern isn't the test runner, there won't be anything for the plugin to interact with. – jason0x43 Nov 08 '19 at 03:11
  • Hi again. My example project is too large and private to share, but I will share with you how i configured cucumber into intern, as an interface instead of a plugin, in hopes to get it working. So i'll show you how my intern library looks so far - and all show you the whole file architecture. please note that everything works fine, until I try to write a test with the cucumber interface .. then that test does not work. only the tdd or bdd tests work. – user3611 Nov 15 '19 at 15:34
  • the code probably wont run but you can get an idea of how the files look like and maybe please help out with how to actuallly make my own cucumber interface work... I got my ideas from this: https://github.com/rhpijnacker/intern3-cucumber and tried to incorporate it into the current version of intern that we are using at my work – user3611 Nov 15 '19 at 15:38
  • https://github.com/smokbel1/karma-intern-cucumber-interface/tree/master – user3611 Nov 15 '19 at 21:08
0

For Integer you can do something like:

@When("^When user is on the error \"(\\d+)\" page$")
public void When_user_is_on_the_error_page(int errorNum) throws Throwable {

...

}

OR

Feature:

Scenario: Some cukes
Given I have 48 cukes in my belly

   @Given("I have {int} cukes in my belly")
    public void i_have_n_cukes_in_my_belly(int cukes) {
        System.out.format("Cukes: %n\n", cukes);
    }
}

Source:

https://cucumber.io/docs/cucumber/step-definitions/

How to write numbers in cucumber scenarios

For String

Feature:

When search for one-way flights between "Bengaluru" and "Mumbai"

@When("^search for one-way flights between \"([^\"]*)\" and \"([^\"]*)\"$")
public void search_for_one_way_flights_between_source_and_destination(String source, String destination) throws Throwable {

 .......
}
Shubham Jain
  • 16,610
  • 15
  • 78
  • 125