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.

Data().Scenario() ends immediately when populating DataTable with async data

See original GitHub issue

What are you trying to achieve?

Data driven scenario that uses randomly generated test data from an asynchronous call to a third party (Mockaroo).

What do you get instead?

Data(…).Scenario(…) ends immediately.

> codeceptjs run --steps

CodeceptJS v1.3.2
Using test root "C:\path\to\repo"


  OK  | 0 passed   // 0ms
{ id: 1,
  FirstName: 'Graig',
  LastName: 'Wellfare',
  Email: 'randomqatester@gmail.com',
  Password: 'P@$$w0rd!',
  PhoneType: 'Work',
  PhoneNumber: '425-555-1212',
  EmailOptedIn: false,
  TextOptedIn: false,
  CreatedIn: 'dev-us',
  AddressLine1: '2 Valley Edge Pass',
  City: 'Long Beach',
  State: 'California',
  PostalCode: '90847',
  PetName: 'Arnoldo',
  Birthday: '01/21/1975',
  AdoptionDay: '09/30/2011',
  Species: 'dog',
  Gender: 'Male',
  SpayedNeutered: false,
  isAdopted: false,
  PrimaryBreed: 'Japanese Chin',
  isMixedBreed: true,
  Weight: 199,
  Color: 'Mahogany' }
PS C:\path\to\repo>

Provide test source code if related

/// <reference path="./steps.d.ts" />

var Mockaroo = require('mockaroo');

var accounts = new DataTable([
    'id',
    'FirstName',
    'LastName',
    'Email',
    'Password',
    'PhoneType',
    'PhoneNumber',
    'EmailOptedIn',
    'TextOptedIn',
    'CreatedIn',
    'AddressLine1',
    'AddressLine2',
    'City',
    'State',
    'PostalCode',
    'PetName',
    'Birthday',
    'AdoptionDay',
    'Species',
    'Gender',
    'SpayedNeutered',
    'isAdopted',
    'PrimaryBreed',
    'isMixedBreed',
    'Weight',
    'Color'
]);

var client = new Mockaroo.Client({
    apiKey: '1a96a8a0'
});

client.generate({
    count: 1,
    schema: 'my-saved-schema'
}).then(function(records) {
    console.log(records);

    for (var i = 0; i < records.length; i++) {
        accounts.add([
            records[i].id,
            records[i].FirstName,
            records[i].LastName,
            records[i].Email,
            records[i].Password,
            records[i].PhoneType,
            records[i].PhoneNumber,
            records[i].EmailOptedIn,
            records[i].TextOptedIn,
            records[i].CreatedIn,
            records[i].AddressLine1,
            records[i].AddressLine2,
            records[i].City,
            records[i].State,
            records[i].PostalCode,
            records[i].PetName,
            records[i].Birthday,
            records[i].AdoptionDay,
            records[i].Species,
            records[i].Gender,
            records[i].SpayedNeutered,
            records[i].isAdopted,
            records[i].PrimaryBreed,
            records[i].isMixedBreed,
            records[i].Weight,
            records[i].Color
        ]);
    }
});

function sleep(ms) {
    return new Promise(resolve => {
        return setTimeout(resolve, ms);
    });
}

Feature('Account');

BeforeSuite(async(I) => {
    await sleep(5000);
});

// This ends immediately...
Data(accounts)
.Scenario('test something', (I,current) => {
// ... but comment out previous 2 lines and uncomment next line and delay works...
// Scenario('test something', (I) => {
    I.amOnPage('https://www.google.com');  // <-- starts after 5 seconds for Scenario() but not for Data().Scenario()
});

Details

  • CodeceptJS version: “^1.3.2”
  • NodeJS Version: v10.6.0
  • Operating System:
Edition         Windows 10 Home
Version         1803
Installed on    5/17/2018
OS build        17134.165
  • Configuration file:
{
  "name": "codeceptjs-mockaroo-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "postinstall": "selenium-standalone install",
    "start": "selenium-standalone start",
    "test": ".\\node_modules\\.bin\\codeceptjs run --steps"
  },
  "keywords": [],
  "author": "Random QA Tester <randomqatester@gmail.com>",
  "license": "MIT",
  "dependencies": {
    "codeceptjs": "^1.3.2",
    "mockaroo": "^0.1.7",
    "selenium-standalone": "^6.15.1"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
guillaume86commented, Apr 3, 2020

It’s a workaround for that specific use case for not a general solution for async data driven tests. Any news on this?

0reactions
Nuxijcommented, Oct 2, 2021

I am trying to do the same thing, I’d love to feed Data() using the DbHelper but I can’t seem to get it to handle async properly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data().Scenario() ends immediately when populating ... - GitHub
Data driven scenario that uses randomly generated test data from an ... Scenario() ends immediately when populating DataTable with async ...
Read more >
Wait until function is complete while Table is generating
data() after the DataTable has initialised (initComplete) to update the data for the cells in the table you need to get async data...
Read more >
Advanced Usage - CodeceptJS
In this case, you need to create a datatable and fill it in with credentials. Then use Data().Scenario to include this data and...
Read more >
Load Async Data in Jquery Datatable - Stack Overflow
I have verified that the getPeople() function does return json data. Am I missing anything? The console.log(jsondata) displays the data 2 or 3 ......
Read more >
Data Driven Gameplay Elements | Unreal Engine 4.27 ...
DataTables, as the name implies, is a table of miscellaneous but related data grouped in a meaningful and useful way, where the data...
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