Skip to content

Commit

Permalink
fix(e2e): using latest tracetest libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Jan 11, 2024
1 parent 8c80be9 commit a3925a0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 83 deletions.
8 changes: 8 additions & 0 deletions collector.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ exporters:
endpoint: ${JAEGER_ENDPOINT}
tls:
insecure: true
otlp/trace:
endpoint: tracetest-agent:4317
tls:
insecure: true

service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [logging, jaeger]
traces/1:
receivers: [otlp]
processors: [batch]
exporters: [otlp/trace]
66 changes: 35 additions & 31 deletions cypress/e2e/1-getting-started/home.cy.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,43 @@
import Tracetest from '@tracetest/cypress';
import Tracetest, { Types } from '@tracetest/cypress';

const TRACETEST_API_TOKEN = Cypress.env('TRACETEST_API_TOKEN') || '';

const tracetest = Tracetest();
let tracetest: Types.TracetestCypress | undefined = undefined;

const definition = `
type: Test
spec:
id: aW1wb3J0cyBhIHBva2Vtb24=
name: imports a pokemon
trigger:
type: cypress
specs:
- selector: span[tracetest.span.type="http"] span[tracetest.span.type="http"]
name: "All HTTP Spans: Status code is 200"
assertions:
- attr:http.status_code = 200
- selector: span[tracetest.span.type="database"]
name: "All Database Spans: Processing time is less than 100ms"
assertions:
- attr:tracetest.span.duration < 2s
outputs:
- name: MY_OUTPUT
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
value: attr:name
`;

describe('Home', { defaultCommandTimeout: 60000 }, () => {
before(done => {
tracetest.configure(TRACETEST_API_TOKEN).then(() => done());
Tracetest({ apiToken: TRACETEST_API_TOKEN }).then(instance => {
tracetest = instance;
tracetest
.setOptions({
'imports a pokemon': {
definition,
},
})
.then(() => done());
});
});

beforeEach(() => {
Expand All @@ -15,11 +46,6 @@ describe('Home', { defaultCommandTimeout: 60000 }, () => {
});
});

afterEach(done => {
const definition = Cypress.env('definition') || '';
tracetest.runTest(definition).then(() => done());
});

// uncomment to wait for trace tests to be done
after(done => {
tracetest.summary().then(() => done());
Expand All @@ -35,29 +61,7 @@ describe('Home', { defaultCommandTimeout: 60000 }, () => {
cy.get('button').contains('OK').click();
});

const definition = `
type: Test
spec:
id: aW1wb3J0cyBhIHBva2Vtb24=
name: imports a pokemon
trigger:
type: cypress
specs:
- selector: span[tracetest.span.type="http"] span[tracetest.span.type="http"]
name: "All HTTP Spans: Status code is 200"
assertions:
- attr:http.status_code = 200
- selector: span[tracetest.span.type="database"]
name: "All Database Spans: Processing time is less than 100ms"
assertions:
- attr:tracetest.span.duration < 2s
outputs:
- name: MY_OUTPUT
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
value: attr:name
`;

it('imports a pokemon', { env: { definition } }, () => {
it('imports a pokemon', () => {
cy.get('[data-cy="import-pokemon-button"]').click();
cy.get('[data-cy="import-pokemon-form"]').should('be.visible');

Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"cy:open": "cypress open",
"cy:run": "cypress run",
"pr:run": "playwright test",
"pr:open": "playwright test --ui",
"pw:run": "playwright test",
"pw:open": "playwright test --ui",
"generate-diagram": "mmdc"
},
"author": "",
Expand All @@ -30,7 +30,7 @@
},
"dependencies": {
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@tracetest/cypress": "^0.0.21",
"@tracetest/playwright": "0.0.21"
"@tracetest/cypress": "^0.0.22",
"@tracetest/playwright": "0.0.22"
}
}
68 changes: 33 additions & 35 deletions playwright/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,52 @@
import { test, expect } from '@playwright/test';
import Tracetest from '@tracetest/playwright';
import Tracetest, { Types } from '@tracetest/playwright';

const { TRACETEST_API_TOKEN = '' } = process.env;

const tracetest = Tracetest();
let tracetest: Types.TracetestPlaywright | undefined = undefined;

test.describe.configure({ mode: 'serial' });

const definition = `
type: Test
spec:
id: UGxheXdyaWdodDogaW1wb3J0cyBhIHBva2Vtb24=
name: "Playwright: imports a pokemon"
trigger:
type: playwright
specs:
- selector: span[tracetest.span.type="http"] span[tracetest.span.type="http"]
name: "All HTTP Spans: Status code is 200"
assertions:
- attr:http.status_code = 200
- selector: span[tracetest.span.type="database"]
name: "All Database Spans: Processing time is less than 100ms"
assertions:
- attr:tracetest.span.duration < 2s
outputs:
- name: MY_OUTPUT
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
value: attr:name
`;

test.beforeAll(async () => {
await tracetest.configure(TRACETEST_API_TOKEN);
tracetest = await Tracetest({ apiToken: TRACETEST_API_TOKEN });
tracetest.setOptions({
'Playwright: imports a pokemon': {
definition,
},
});
});

test.beforeEach(async ({ page }, { title }) => {
await page.goto('/');
await tracetest.capture(title, page);
});

test.afterEach(async ({}, { title, config }) => {
await tracetest.runTest(title, config.metadata.definition ?? '');
config.metadata.definition = '';
await tracetest?.capture(title, page);
});

// optional step to break the playwright script in case a Tracetest test fails
test.afterAll(async ({}, testInfo) => {
testInfo.setTimeout(60000);
await tracetest.summary();
await tracetest?.summary();
});

test('Playwright: creates a pokemon', async ({ page }) => {
Expand All @@ -40,31 +62,7 @@ test('Playwright: creates a pokemon', async ({ page }) => {
await page.getByRole('button', { name: 'OK', exact: true }).click();
});

const definition = `
type: Test
spec:
id: UGxheXdyaWdodDogaW1wb3J0cyBhIHBva2Vtb24=
name: "Playwright: imports a pokemon"
trigger:
type: playwright
specs:
- selector: span[tracetest.span.type="http"] span[tracetest.span.type="http"]
name: "All HTTP Spans: Status code is 200"
assertions:
- attr:http.status_code = 200
- selector: span[tracetest.span.type="database"]
name: "All Database Spans: Processing time is less than 100ms"
assertions:
- attr:tracetest.span.duration < 2s
outputs:
- name: MY_OUTPUT
selector: span[tracetest.span.type="general" name="Tracetest trigger"]
value: attr:name
`;

test('Playwright: imports a pokemon', async ({ page }, { config: { metadata } }) => {
// set the definition for the tracetest test
metadata.definition = definition;
test('Playwright: imports a pokemon', async ({ page }) => {
expect(await page.getByText('Pokeshop')).toBeTruthy();

await page.click('text=Import');
Expand Down

0 comments on commit a3925a0

Please sign in to comment.