Hi there!
I am trying to use Snowplow’s Javascript Tracker to track the execution of end-to-end tests using Cypress and I am having a lot of trouble configuring the tracker. I’m kind of new to JS and Cypress, but I have worked a lot with Snowplow Python and Ruby trackers.
Basically, what I want to do is to trigger an event after my tests finish running so that I can get information on the execution status and duration. The code I created using the setup guide is the following:
describe('Form validations - incorrect values', () => {
beforeEach(() => {
cy.setCookie('e2e_test', 'test');
Cypress.Commands.add('track_focus_form', () => {
var snowplow = require('@snowplow/node-tracker');
var gotEmitter = snowplow.gotEmitter;
var tracker = snowplow.tracker;
const e = gotEmitter(
'collector.mydomain.net', // Collector endpoint
snowplow.HttpProtocol.HTTPS, // Optionally specify a method - http is the default
8080, // Optionally specify a port
snowplow.HttpMethod.POST, // Method - defaults to GET
5 // Only send events once n are buffered. Defaults to 1 for GET requests and 10 for POST requests.
);
const t = tracker([e], 'selfDescribingEvent', 'stifler',);
t.trackUnstructEvent({
"schema": "iglu:com.snowplowanalytics.snowplow/focus_form/jsonschema/1-0-0",
"data": {
"formId": "4321",
"elementId": "23",
"nodeName": "INPUT",
"value": "teste"
}
});
});
});
it('required fields display messages with incorrect input values', () => {
cy.visit('mock-url.com/cadastro');
cy.get('#email').type('xpto@gmail');
cy.get('#phone').type('(11) 1111-9999');
cy.get('#email~span').should('contain', 'E-mail válido requerido');
cy.get('#phone~span').should('contain', 'Celular válido requerido');
cy.track_focus_form()
});
});
The error I am getting is:
TypeError: Cannot read property 'HTTPS' of undefined
I don’t understand why this is happening. Even when I add ‘https’ and ‘post’ manually to the function call, I still get the same error, but with a slightly different message
TypeError: Cannot read property 'GET' of undefined
I am using @snowplow/node-tracker version 3.1.0
Has anyone ever seen this issue?
Thanks for the help!