jeudi 14 janvier 2021

Is there way to run test which have test.meta of TestCafe utilizing runner?

I have a test that I want to execute only, with test.meta. Please find below my code.

This is a test spec .spec.ts

import { takeSnapshot } from 'testcafe-blink-diff';
import { AdminHomePage, LoginPage } from '../../pages';
import { config } from '../../config/tescafe.config';

const loginPage: LoginPage = new LoginPage();
const adminHomePage: AdminHomePage = new AdminHomePage();

fixture(`Practice utilization chart`)
  .page(config.baseUrl)
  .beforeEach(async () => {
    await loginPage.login(config.envCredentials.admin.email, config.envCredentials.admin.password);
  });

test.meta({ type: 'visual' })('Can view utilization chart with default interval ', async (t) => {
  await t.expect(adminHomePage.practicesUtilizationChart.chart.exists).ok();
  await t.expect(adminHomePage.practicesUtilizationChart.weekOption.innerText).eql('Week');
  await takeSnapshot(t, {
    fullPage: false,
    timeout: 2000,
    selector: adminHomePage.practicesUtilizationChart.chart,
  });
});

And this is a runner.js which does the same

// eslint-disable-next-line @typescript-eslint/no-var-requires
const createTestCafe = require('testcafe');

(async () => {
  const testcafe = await createTestCafe('localhost', 1340);

  try {
    const runner = testcafe.createRunner();
    await runner
      .src(['./testcafe/specs/*/*.spec.ts'])
      .browsers(['chrome:headless'])
      .reporter([
        'spec',
        {
          name: 'html',
          output: './testcafe/artifacts/reports/report.html',
        },
      ])
      .screenshots('./testcafe/artifacts/screenshots', true)
      .run({
        selectorTimeout: 2000,
        assertionTimeout: 2000,
        pageLoadTimeout: 5000,
        speed: 0.5,
      });
    // eslint-disable-next-line no-useless-catch
  } catch (error) {
    throw error;
  } finally {
    await testcafe.close();
  }
})();

Is it possible to run tests using this runner and meta from tests?

npx testcafe chrome:headless ./testcafe/specs/*/*.spec.ts --test-meta type=visual runs test

npm run test --test-meta type=visual - does not run test, which runs runner with same parameters

package.json

  "scripts": {
    "test": "node testcafe/runner.js",
    }
    
I know that there is an option to read parameters from cli or if I remove the runner or run using npx it works. 

Aucun commentaire:

Enregistrer un commentaire