3

I found a lot of introductions to parameterized tests/ test cases for test cafe, but the syntax is completely different to the one I am using. I guess they're for the discontinued paid version. How can I do the same thing with the free version? I'm not looking for user roles specifically, I want to write tests with parameters in general.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Medusa
  • 593
  • 2
  • 5
  • 18

2 Answers2

3

Do you want to do something like this? This works for me perfectly

import { Selector } from 'testcafe';

fixture `Your fixture`
.page `http://some_url.com`

const testCases = [ 
    { name: 'name1', param: 'param1' },
    { name: 'name2', param: 'param2' }
    ...
];

for (const c of testCases) {
    test(`Test ${c.name}`, async t => {
        yourTestMethod(c.param)
    });
}
marshmallow
  • 86
  • 1
  • 8
0

An additional twist can be added by using a combination of JS and YAML

import YamlTableReader, {fixtureData, TestData} from "./YamlTableReader";

    var table = fixtureData `
        | ID                  | N1      | N2      | Equals |
        | Should Be equal     | 1       | 1       | true  |
        | Shouldn't be equal  | 1       | 2       | false  |
        | Shouldn't be equal  | 1       | "hans"  | false  |
        | Should be equal     | hans    | "hans"  | true  |
    `;

    table.forEach(row => {
      test('Should be equal', t => {
          row["Equals"] == (row["N1"] === row["N2"]));
         }
    }); 

Simple Sources for this can be found here https://github.com/deicongmbh/jasmine-param-tests

Dieter
  • 89
  • 1
  • 4