CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Custom step isnt working synchronously

Open andreluizbnu opened this issue 9 years ago • 2 comments

What are you trying to achieve?

Im trying to attach synchronous method to a Test Scenario.

What do you get instead?

The custom method was executed before the steps.

Provide test source code if related

I created a method called baseline that simply query something from the database but i want to retrieve the values after the whole scenario. I think the baseline doesnt see the recorder. I couldnt manage to make it work using the recorder. Anyone seen this before?

Scenario('Example', (I) => {
    I.click('Férias');
    I.click('Em aberto');
    I.click('input[ng-click="vm.selectedEmployee(vacation)"]');
    I.click('button[ng-click="vm.goToVacationTeamRequest()"]');
    I.fillField('input[name="vacation-team-request.startDate"', '10/05/2017');
    I.fillField('input[name="vacation-team-request.vacationDays"', '15');
    I.click('Salvar e enviar');
    I.click('Colaborador_1');
    I.click('Sair');
   I.baseline();
});

baseline method:

baseline: function () {
  exec('psql -h pcbnu00121 -p 5432 -U postgres -d HCM121 -c "SELECT * FROM logs.automatizados"', { silent: false });
}

Details

  • CodeceptJS version: 0.6.3-pre
  • NodeJS Version: 4.5.0
  • Operating System: Windows 10
  • Protractor || WebDriverIO || Nightmare version (if related): Nightmare
  • Configuration file:
{
  "tests": "tests/*_test.js",
  "timeout": 10000,
  "output": "./output",
  "helpers": {
    "Nightmare": {
      "restart": false,
      "show": true,
      "keepCookies": true,
      "switches": {
        "ignore-certificate-errors": true
      },
      "webPreferences": {
        "webSecurity": false
      }
    }
  },
  "include": {
    "I": "./steps_file.js"
  },
  "bootstrap": false,
  "mocha": {},
  "name": "Automação"
}

andreluizbnu avatar May 09 '17 20:05 andreluizbnu

I managed to make it work.

I had to instantiate the recorder on my steps_file and call the recorder.add() passing the function i would like to execute in order to add in queue.

Its working now.

andreluizbnu avatar May 11 '17 16:05 andreluizbnu

Cool. Could you share your solutions as a blogpost or maybe gist? Custom step should combine other steps. For your purpose you should have created a custom helper, their methods are synchronized in a Promise chain

DavertMik avatar May 23 '17 23:05 DavertMik