I'm trying to create a basic login command in Cypress, which was working when I used cy.visit().
After reading up on Cypress, I found out that logging in using the UI is an anti-pattern, so I'm attempting to switch over to calling cy.request() to post to the login route.
However, when I try this, I get an error that does not make sense to me:
TypeError: _locale.cy.request is not a function
This is my code in commands.js:
Cypress.Commands.add("login", () => {
cy.request('POST', `${Cypress.config().baseUrl}/login`, {username: 'sysadmin', password: 'test'});
});
And this is where it gets called in the test:
it('Logs in successfully', () => {
cy.login();
});
From my understanding, cy.request is a function that comes with Cypress, that can take in a method, url and body: .html#Syntax.
Can anyone please explain why Cypress isn't recognizing its own native function?
Thanks
I'm trying to create a basic login command in Cypress, which was working when I used cy.visit().
After reading up on Cypress, I found out that logging in using the UI is an anti-pattern, so I'm attempting to switch over to calling cy.request() to post to the login route.
However, when I try this, I get an error that does not make sense to me:
TypeError: _locale.cy.request is not a function
This is my code in commands.js:
Cypress.Commands.add("login", () => {
cy.request('POST', `${Cypress.config().baseUrl}/login`, {username: 'sysadmin', password: 'test'});
});
And this is where it gets called in the test:
it('Logs in successfully', () => {
cy.login();
});
From my understanding, cy.request is a function that comes with Cypress, that can take in a method, url and body: https://docs.cypress.io/api/commands/request.html#Syntax.
Can anyone please explain why Cypress isn't recognizing its own native function?
Thanks
Share Improve this question asked Feb 18, 2020 at 16:33 PepPep 3892 gold badges8 silver badges17 bronze badges1 Answer
Reset to default 23Old question, i had the same problem, but my solution was to simply ensure that there was no import { cy } from 'date-fns/locale';
at the top of your page.