Skip to content

Nested test structures? #20

Closed
Closed

Description

@markerikson

Trying to play around with CodeceptJS, having never actually used Mocha or anything similar before. Mocha's docs seem to indicate that you can set up nested tests using describe() and it(). It looks like Codecept's Feature() and Scenario() are an alternative method to setting up Mocha's Suites. Is there a similar way to set up nested tests using CodeceptJS? For example, something vaguely like:

Feature('Test1');

Before((I) => { // or Background
  I.amOnPage('/');
});

Scenario('Interact with the login page ', (I) => {
  Feature("Test 1 - Part 1");

  Scenario("Filling in login form shows consent banner", () => {
    I.see('Username');
    I.dontSee("You are accessing");
    I.fillField("httpd_username", "user1");
    I.fillField("httpd_password", "pw1");
    I.see("You are accessing");
  });

  Feature("Test 1 - Part 2");

  Scenario('Can log in successfully', () => {
    I.see('Username');
    I.fillField("httpd_username", "user1");
    I.fillField("httpd_password", "pw1");
    I.click('Agree and Log In');
    I.wait(1);
    I.dontSee("Username");
  });
});

Activity

  1. DavertMik commented on Dec 10, 2015

    @DavertMik
    Contributor

    Right now we don't provide any kind of nesting.
    And there is no something like that in nearest plans. One feature per file for now.

  2. markerikson commented on Dec 10, 2015

    @markerikson
    Author

    Hmm. That's kind of disappointing, particularly since Mocha does support nesting suites.

    Here's my use case. Right now, with that I.amOnPage('/'); in Before(), Codecept appears to be bringing up a separate browser instance for every test. That's taking around 15s or so to execute a test.

    I'd really like to be able to use a single Webdriver / browser instance for a series of tests. Beyond that, I'd like to be able to, say, run an initial test verifying that logging in works, then run additional tests after that that require having successfully logged in.

    Again, I'm very new to actual automated testing and to Codecept, but that seems like a pretty useful scenario to support.

  3. DavertMik commented on Dec 15, 2015

    @DavertMik
    Contributor

    Here's my use case. Right now, with that I.amOnPage('/'); in Before(), Codecept appears to be bringing up a separate browser instance for every test. That's taking around 15s or so to execute a test.

    Thanks for the idea. We will add option to reuse instance of a browser.

    Beyond that, I'd like to be able to, say, run an initial test verifying that logging in works, then run additional tests after that that require having successfully logged in.

    This concept is somehow harder to implement. As you will probably have LOTS of tests where user is logged in (and probably in different files) and one test for a login. Probably this will require something like dependency tree for tests.

    But in the end, I think that you don't need nested structures for this kind of tests. Yes, mocha support them, but CodeceptJS is about scenario-driven testing so it's better to keep it linear.

  4. arsa666 commented on Jan 8, 2016

    @arsa666

    Hello markerikson

    I had the same issue, I hate waiting for the browser to open and close. What I did was that I created a script that concatenates many files into one and puts all my different file test into a single test all contained in the same Scenario(), this way I can test memory leaks in my app on the browser.

    So far it works great. I can share you my script if you want.

  5. adrianblynch commented on Jan 11, 2016

    @adrianblynch

    Would be nice to see your script. I wonder how much time you're saving doing it this way?

  6. Nighthawk14 commented on Jul 22, 2016

    @Nighthawk14
    Contributor

    @markerikson That may interest you #167

  7. DavertMik commented on Jan 23, 2017

    @DavertMik
    Contributor

    I think this can be closed as all helpers have restart: false option which can be used to reuse browser session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions