question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to dynamically create tests while inside of a test - cannot create tests while tests are running

See original GitHub issue

I am loading these based on some data, but to get it I need to run cy.task to grab that data. For now let’s assume it’s a MySQL query via a plugin. I cannot use cy.task outside of a test, so I am trying to add tests from within a test.

Another use case is that I am running a test, but I see a button. I have another set of tests that only run based on the existence of that button. I still want them in another separate context, so a separate dropdown.

Also, I cannot use it inside of a cy.task callback e.g. inside of myFunction like with cy.task('readCSV', 'test.csv').then(myFunction);

Current behavior:

Parent task results waits forever. Perhaps related (https://github.com/webdriverio/webdriverio/issues/4963)

Desired behavior:

I would like to see “Another Test” in a separate row as per the code below. FYI: Doing this will work in puppeteer correctly.

Test code to reproduce

context('Set up',  () => {
  it('add tests',  () => {

    context('Another test', () => {

      it('this title', () => {
        expect(true).to.equal(true)
      })
    })
    
  });
})

Versions

Debian 10, Cypress 4.8.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
intelcentrecommented, Jul 2, 2020

Mocha has a command line option called “–delay”. This would be great to implement in cypress for those of us who have async operations they need to perform which inform the list of actual tests.

From their docs:

DELAYED ROOT SUITE

https://mochajs.org/#asynchronous-code If you need to perform asynchronous operations before any of your suites are run, you may delay the root suite. Run mocha with the --delay flag. This will attach a special callback function, run(), to the global context:

setTimeout(function () {
  // do some setup

  describe('my suite', function () {
    // ...
  });

  run();
}, 5000);
0reactions
stevenlaflcommented, Jun 23, 2020

Cypress needs all tests registered to run them. Can you wrap the expects in the if conditions?

Something like:

    describe('Dyanamic 1',  () => {
      it('test tests',  () => {
        if (results.length > 0) {
          expect(true).to.equal(true)
        }
      });
    })

I can and I do, but that isn’t quite what I am looking for.

The issue is that I want the flexibility to add these tests at runtime. For example, I would like a test to

  1. Grab site URLs that exist in a CSV
  2. For each URL, run a set of browser tests them
  3. For each test, add more tests depending on the result.

Depending on what is on a certain page, I may need to run additional tests, since the structure could be entirely arbitrary or user defined. Even structures such as content types and their fields are not known to me ahead of time.

The idea is achieve a write-once set of tests, and transport them for use across multiple site installations with a wide variety of scenarios as to their configuration.

These tests are entirely decoupled from the site installation and need to be run remotely. Multiple people are changing the structures all at the same time, so when these run, I need to be able to report back to them continuously.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic test cases - nunit - Stack Overflow
Unfortunately, we cannot use [TestCase] attribute, because our test cases are stored in an external storage. We have dynamic test cases which ...
Read more >
What is Dynamic Testing? Types, Techniques & Example
Dynamic Testing is defined as a software testing type, which checks the dynamic behaviour of the code is analysed.
Read more >
Guide to Dynamic Tests in Junit 5 - Baeldung
A DynamicTest is a test generated during runtime. These tests are generated by a factory method annotated with the @TestFactory annotation.
Read more >
Dynamic Data - Rainforest QA
Automation Test Runs · Tests: The number of tests in a single run. · Browsers or Platforms: The number of browsers or platforms...
Read more >
Testing - Spring
The POJOs that make up your application should be testable in JUnit or TestNG tests, with objects instantiated by using the new operator, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found