Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Possible of generate empty tests with a "Pending" warning? #75

Closed
victorheid opened this issue Jul 17, 2018 · 17 comments
Closed

Possible of generate empty tests with a "Pending" warning? #75

victorheid opened this issue Jul 17, 2018 · 17 comments

Comments

@victorheid
Copy link

I have to leave all tests empty, which gives a false status of passing and fails on guiding the development process.

Is there any way to do it? Or am I missing it? #

@lgandecki
Copy link
Collaborator

I think this is more of a cypress / mocha thing - what happens if you put this.skip() inside your step definition?

@victorheid
Copy link
Author

It just skips it, and the test itself marks as passing (if only skipped steps are left)

I've tried to throw an error saying "Step pending" or just not write the step until I get to it, but both cases, it seems to override the entire test ,Cypress doesn't show the other steps that were executed before. i.e. I have a step that is pending, where I just do an 'assert.isTrue(false)'. The error emerges, but it does not show the previous steps

@haleagar
Copy link

return this.pending();
would be how to to it in mocha, but how to get this to be the right context from a step definition.
this.skip() does not work for me

@flowt-au
Copy link

I would love to have a way to write specs that are 'Pending' in the sense of a 'TODO: Write this step'. The following is what Cypress does with Mocha tests:

describe('My First Test', function () {

            // Runs and passes
    it('Does something at least!', function () {
        expect(true).to.equal(true)
    })
            // Runs and passes
    it('Does nothing', function () {
        
    })

            // Is skipped, using Mocha function
    it('Skips', function () {
        this.skip()
    })

            // Is also skipped, by having no function
    it('Some other step for later')

            // Runs despite the skip() above
    it('Does the last step', function () {
        expect(true).to.equal(true)
    })

})

The 2 skipped steps are reported in the pale blue highlight in the log panel and the final step runs.

So, given this feature:

Feature: My First Test

    As a user I want test the Cypress syntax

    Scenario: Start first app
        Given I start the app
        Then Does something at least!
        Then Some other step for later
        Then Skips
        Then Does the last step

And this step def:

Given('I start the app', () => {
    
    Then(`Does something at least!`, () => {
        expect(true).to.equal(true);
    })

    Then(`Some other step for later`)
    
    Then(`Skips`, function () {
        this.skip()
    })

    Then(`Does the last step`, () => {
        expect(true).to.equal(true);
    })

})

Then('Some other step for later') (no function) throws an error Error: Step implementation missing for: Some other step for later. Removed it and ran again.

This does tell Cypress to skip:

    Then('Skips', function () {
        this.skip()
    })

ie it displays the pale blue "skipped" style, but it also prevents any further steps from running (unlike the Mocha test above which executed the remaining step).

If I change it to this:

    Then('Skips', function () {
        //this.skip()
    })

all steps run (and the Log entries are after 2 Passing assertions). The 'Skips' step is just logged.

If I remove that Then('Skips'... step altogether the 2 passing assertions run (and the Log entries are after 2 Passing assertions).

So, in Mocha / Cypress, the this.skip() can be used inside the step definition as a "To do later". In this cypress-cucumber-preprocessor we can use this.skip() but the outcome is any steps following are not run.

Are my assumptions correct here and is there any way we can have this.step() behave here as it does in Mocha / Cypress?

Thanks. It is just a small thing but would be great to have it work so we can visually see which feature steps are not yet implemented.

Cheers,
Murray

@lgandecki
Copy link
Collaborator

I see what you are saying and I would love to have that as well, but at this moment I don't see a way to achieve that, as Cypress forces us to treat all steps as one test. you can try to introduce a warning instead of the this.skip but that will be easy to miss for example in the CI (which is the point of pending tests as far as I understand).
I think we would need some changes in the cypress runner here, possibly around the way they deal with loging.
This is something I was hoping to look at in November.

@flowt-au
Copy link

OK. All good. Just as long as it is on the radar!

Thanks,
Murray

@miteshpatel1
Copy link

Hello - any updates on the development of this feature?

@servandoprime
Copy link

This feature would be awesome... right now, not being able to set a scenario as "pending" with cucumber is what's hindering me from using cypress...

@pascalbe-dev
Copy link

pascalbe-dev commented Oct 15, 2019

Any update here?

My use case is the following:
I want to mark tests, which are not implemented yet, so that they do not break the CI build.
The idea was to give a custom tag and then, in the before hook, skip the whole scenario.
Of course, I would be possible to ignore the scenarios with those tags, but it would be nice to still have the steps in the cucumber report. That's why I would prefer to have them skipped.

Is there a way to do that? I came up with an approach like that, but I can not seem to get it running:
Before({ tags: '@manual' }, function() { console.log('In before hook'); this.skip(); // return 'skipped'; });
Is there a way to achieve that right now?

@ncko
Copy link

ncko commented May 13, 2020

Any update on this?

@AlphaWong
Copy link

It is a good feature to have. As right now, the result table of the test show pending

@gtsop
Copy link

gtsop commented Nov 9, 2020

Anyone here found a way to achieve the desired behaviour?

@andyg101
Copy link

I have used cucumber with Java and to acheive this you throw a PendingException() is there a similar concept that can be used here?

@flowt-au
Copy link

flowt-au commented May 16, 2021

While this doesn't address the bigger issue, this is helpful: https://github.com/cypress-io/cypress-skip-test
eg:
Then('Skip this test', () => { cy.skipOn(true) });

@mkefd
Copy link

mkefd commented Nov 27, 2021

hi! when using this.skip() I get empty.cucumber.json generated instead of some meaningful data, does anyone experiences the same?

versions

"cypress": "^9.0.0",
"cypress-cucumber-preprocessor": "^4.3.0",

config

  "cypress-cucumber-preprocessor": {
    "nonGlobalStepDefinitions": true,
    "cucumberJson": {
      "generate": true,
      "outputFolder": "cypress/cucumber-json",
      "filePrefix": "",
      "fileSuffix": ".cucumber"
    }
  }

@Finaldrace
Copy link

While this doesn't address the bigger issue, this is helpful: https://github.com/cypress-io/cypress-skip-test eg: Then('Skip this test', () => { cy.skipOn(true) });

Yeah i use the skip-test plugin too.
And in CLI the testcases with the cy.skipOn("true") are marked as pending.

image
As you can see 5 are pending.

but in my json file is every expected "status": "pending" testcase missing.

@badeball
Copy link
Owner

Due to personal reasons, the previous maintainers of this package are stepping down and handing the reigns over to me, a long-time contributor to the project and a user of it myself. This is a responsibility I'm very excited about. Furthermore, I'd like to thank @lgandecki ++ for all the work that they've done so far.

Read more about the transfer of ownership here.

The repository has however moved and all outstanding issues are being closed. This is not a reflection of the perceived importance of your reported issue. However, if after upgrading to the new version, you still find there to be an issue, feel free to open up another ticket or comment below. Please make sure to read CONTRIBUTING.md before doing so.

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

No branches or pull requests