Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ability to define your own DSL in order to promote BDD (stimulate business and IT cooperation) #197

Closed
EddyBruin opened this issue Aug 9, 2016 · 8 comments

Comments

@EddyBruin
Copy link

Currently it's possible to write scripts using mocha and chai style. However this is not a DSL to write more human friendly specs. Would be nice if Cypress would hve a DSL like cucumber or gauge

@brian-mann
Copy link
Member

brian-mann commented Aug 17, 2016

This has come up a few times before, but integration with cucumber isn't considerably straightforward and will likely end up creating a ton of indirection.

Cypress isn't really a 1:1 replacement for e2e testing - it's able to do things much lower on the pyramid akin to unit tests. Because of that its not necessarily a great fit for cucumber. If you were only writing e2e tests, its possible it could work - but the majority of our users do things like mocking, stubbing, or yielding DOM objects directly and asserting on them.

Can you provide some of your Cypress tests and the cucumber / gauge code you wish you could write? Having some examples would be helpful.

You can also look at some of our example repos. How would those convert?

@jennifer-shehane jennifer-shehane added the stage: needs information Not enough info to reproduce the issue label Aug 22, 2016
@eaustin
Copy link

eaustin commented Oct 12, 2017

My example would be:
In the file, language_selection.feature:

Feature: Language Selection
  We should have the ability to change the language of our application
  +language_selection.feature

  Scenario: User can view the application in French Canadian
    Given I am on the login page
    When I switch language to "French (Canada)"
    Then I should see welcome message as "Se connecter à" in the login page
    And I click the log in button
    And the module title should equal "Panneau de contrôle"

In my spec file (pseduo code):

feature(' Language Selection', function () {
  beforeEach(function () {
    cy.visit('http://myapplication.com')
  })

  scenario('User can view the application in French Canadian', function () {
    given('I am on the login page', function () {
      expect(language).to.be.equal('English')
    })

    when('When I switch language to "(*)"', function (lanuage) {
      cy.get('#langSelector').value(language).click()
    })

    then('I should see welcome message as "(*)" in the login page', function (message) {
      expect(api.langService).to.be.called
      cy.get('#welcomeMessage')
        .and('equal', message)
    })

   then('I click the log in button', function (message) {
      cy.get('#loginButton').click()
    })

  then('the module title should equal "Panneau de contrôle"', function (message) {
       cy.get('#moduleTitle')
        .and('equal', message)
    })
  })

But then my hope, everything else would work just as it is marketed today. For my team, unfortunately, the BDD is a hard requirement.

Also, even in the e2e testing, I'm hoping that there could be a capability of stubbing/mocking server-side code. We are exploring that to increase the speed of our testing at least in certain scenarios such as regression tests after code deployments but then run the exact same tests nightly or weekly without mocking.

@paulpruteanu
Copy link

Is there any update on this issue? I'm really looking forward to bring my feature teams onboard with this solution, but as eaustin mentioned, BDD is part of our definition of done.

@brian-mann
Copy link
Member

This is not something that would go into Cypress core. These functions just appear as aliases around mocha's it. You might also want to look into cucumber-js to see if you could port it into Cypress.

@lgandecki
Copy link

lgandecki commented Dec 23, 2017

@paulpruteanu @eaustin @EddyBruin Hey guys! I made a plugin for this. Please give it a try and let me know what you think.

https://github.com/TheBrainFamily/cypress-cucumber-preprocessor

You can check a working example here:

https://github.com/TheBrainFamily/cypress-cucumber-example

@brian-mann I'd love an input from you, especially around the folder structure (which is hardcoded to support/spec_definitions/ now) Also, I probably abuse the plugin flow, maybe I should be somehow plugin this in your browserify, instead of calling it from my plugin. Anyway , I felt like those changes, even though breaking, would be easy to make, so people can start writing their tests already and adjust they plugin configuration/directory structure when needed

@jennifer-shehane jennifer-shehane added stage: wontfix Cypress does not regard this as an issue or will not implement this feature and removed stage: needs information Not enough info to reproduce the issue labels Dec 26, 2017
@lgandecki
Copy link

@jennifer-shehane could you elaborate a bit more besides changing a label to wontfix? :)

@tmrony
Copy link

tmrony commented Jul 12, 2018

Hey @lgandecki
Do you have any plan to support "Scenario outline with examples in title" in your plugin?

cucumber-js already supports it, may be you need to do little processing in your code.

@jennifer-shehane jennifer-shehane removed the stage: wontfix Cypress does not regard this as an issue or will not implement this feature label Aug 1, 2018
@jennifer-shehane
Copy link
Member

@lgandecki We feel this is best solved through the plugin provided. We provide flexibility to Cypress so that it can be extended to fit users needs that are outside of Cypress' current roadmap.

I'm closing this issue and suggest referring to https://github.com/TheBrainFamily/cypress-cucumber-preprocessor for use.

If there are issues that come from the plugin usage, feel free to open a new issue for more closely integrated support.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants