(DEPRECATED) Cucumber.js BDD usage with Javascript

 

 

Behaviour-driven development (BDD) is an agile software development process that encourages collaboration among developers, quality assurance testers, and customer representatives in a software project. It encourages teams to use conversation and concrete examples to formalize a shared understanding of how the application should behave. It emerged from test-driven development (TDD).

 

 

 

 

 

Cucumber is a testing tool that supports Behavior Driven Development (BDD). It offers a way to write tests that anybody can understand, regardless of their technical knowledge. In BDD, users (business analysts, product owners) first write scenarios or acceptance tests that describe the behaviour of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.

 

 

How to use BDD on Momentum Suite?

1. Create your CucumberJS BDD test case on MomentumSuite

  • Create a new project on MomentumSuite.

  • Click the New Section button on Case Management. The section name is “Features” in this example.

  • Click the Add Case button under the Features section.

  • Select the Case Title as “Search“, Language as “Javascript”, Framework as “CucumberJs” and click the Save Changes button.

2. Edit your Gherkin test scenarios on Test Case

  • Expand your TestCase and click your scenario details on the left side of Case Management

  • Write your Cucumber Scenarios

For the first scenario no need to define a “Scenario:” or Scenario Outline. For the next scenarios, you need to define them.

No need to add Feature or Tag. But you should…

Your test case name is also the feature name and is handled automatically on the Momentum Suite.

You can use Momentum Suite TestCase tags and filter by tag when running them.

3. Upload your step definition JS file

  • For this example, you can create a dummy “Search.js” file on your computer

  • Click the Upload Library button

  • Select “Java Script” as your Library Language and check Is Step Definition File checkbox and then select “Search.js” file from your computer.

  • Click Add Library button.

4. Edit your step definition JS file

This is an example code. String expressions must be matched with your gherkin (given-when-then) scenarios.

Given("uygulamaya misafir kullanici ile giris yapilir", async () => { await driver.resetApp(); await driver.sleep(5000); try { let element_1 = await driver.elementByAccessibilityId(""); await element_1.click(); } catch (e) { } await driver.saveScreen(); }); When("arama ekranindan {string} aratilir", async (city) => { let element_1 = await driver.elementByAccessibilityId("Search"); await element_1.click(); let element_2 = await driver.elementByAccessibilityId("Where to?"); await element_2.click(); await element_2.sendKeys(city); await driver.saveScreen(); }); When("bulunan ilk arama sonucu secilir", async () => { await driver.sleep(3000); let element_1 = await driver.elementByAccessibilityId("Antalya, Turkish Mediterranean Coast, Turkey"); await element_1.click(); await driver.saveScreen(); }); When("otele tiklanir", async () => { let element_1 = await driver.elementByAccessibilityId("search"); await element_1.click(); await driver.saveScreen(); }); Then("otellerin listelendigi gorulmelidir", async () => { //asssert });

5. Run your CucumberJS Test

  • Navigate to Test Runs and click Create New Test button

  • Choose your Gherkin scenarios and your target devices.

  • Run your Test.

  • Click the Test Details on the Test Run screen

 

6. Review Your Test Results

  • Review Error log and screenshots

  • Click SHOW BDD DETAIL on the test result screen

  • Review your steps and step results