lundi 22 juin 2020

How to override standard testcafe errors?

I need to override standard testcafe error messages by adding there Selector's input locator - this way I will know more about failure and can debug that manually at least by manually checking ability for selector to be found.

When I try just to catch error by this code:

  try {
    const selector = Selector('basdf')
    await t.click(selector);
  }
  catch (e) {
    console.log(e);
  }

I'm getting this object:

{
  code: 'E24',
  isTestCafeError: true,
  callsite: CallsiteRecord {
    filename: '/Users/myPath/helper_test.ts',
    lineNum: 37,
    callsiteFrameIdx: 6,
    stackFrames: [
      [CallSite], [CallSite],
      [CallSite], [CallSite],
      [CallSite], [CallSite],
      [CallSite], CallSite {},
      [CallSite], [CallSite],
      [CallSite]
    ],
    isV8Frames: true
  },
  apiFnChain: [ "Selector('basdf')" ],
  apiFnIndex: 0
}

And if I'll just leave code like this:

const selector = Selector('basdf')
await t.click(selector);

I will get just what I need -

 ✖ Edits auto on propositions

   1) The specified selector does not match any element in the DOM tree.
      
       > | Selector('basdf')

      Browser: Chrome 83.0.4103.106 / macOS 10.15.5

         33 |
         34 |  // const someVar = 1;
         35 |
         36 |  // try {
         37 |    const selector = Selector('basdf')
       > 38 |    await t.click(selector);
         39 |  // }
         40 |  // catch (e) {
         41 |  //   console.log(e);
         42 |  // }
         43 |});

         at <anonymous> (/Users/orkhan.mamedov/WebstormProjects/osago/tests/e2e/helper_test.ts:38:13)
         at fulfilled (/Users/orkhan.mamedov/WebstormProjects/osago/tests/e2e/helper_test.ts:5:58)



 1/1 failed (18s)

Is there any option to add custom info to that line:

The specified selector does not match any element in the DOM tree.

So it would be like that:

The specified selector with locator: 'locator of a selector' does not match any element in the DOM tree.

Aucun commentaire:

Enregistrer un commentaire