cypress run
seems to silently pass test without running it.
#14391
-
Hi there, I'm trying to use Cypress to test an account signup page. When developing the test, I have the interactive window open (using A bit about my setup:
This is the spec I am trying to run describe('Sign Up Flow', () => {
it('Should visit /signup and create account, receive email verification link and login', async () => {
cy.createDummyAccount().then(account => {
// Write dummy account info to file for followup tests to use
cy.writeFile(`./signup-flow.account`, JSON.stringify(account))
const { name, organization, email, password, id } = account;
// Visit the signup page and create an account
cy.visit('/signup')
cy.get('#fullName').type(name)
cy.get('#organization').type(organization)
cy.get('#email').type(email)
cy.get('#password').type(password)
// Click "Sign Up" button
cy.contains("Sign Up").click()
cy.url().should('contain', 'accountCreated')
// Get the link from the verification email
cy.checkVerificationEmail(id, 30000).then((link) => {
// Follow the verification link and go to redirected page
cy.request(link).then((response) => {
const redirect = response.redirects[0].replace('302: ', '');
cy.visit(redirect)
// Follow the "Login" button on the "email verified" page
cy.contains('Login').click()
// Complete and submit login form
cy.url().should('contain', 'login')
cy.get('#email').type(email)
cy.get('#password').type(password)
cy.get('button').contains('Login').click()
})
})
})
})
}) I also have the following support code (this is in const HtmlParser = require('node-html-parser');
const axios = require('axios');
const { v4: uuidv4 } = require('uuid');
var faker = require('faker');
// TESTMAIL NAMESPACE
const NAMESPACE = Cypress.env("TEST_MAIL_NAMESPACE");
const API_KEY = Cypress.env("TEST_MAIL_API_KEY");
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const getEmailVerificationLink = async (id, timeout = 10000, cycles = 20) => {
const url = `https://api.testmail.app/api/json?apikey=${API_KEY}&namespace=${NAMESPACE}&tag=${id}`;
for (let i = 0; i < cycles; i++) {
console.log("Checking email " + i);
const response = await axios.get(url)
const emails = response.data.emails;
if (!emails.length) {
await sleep(timeout / cycles);
continue;
}
const html = emails[0].html;
const link = HtmlParser
.parse(html)
.querySelector('.inner-td')
.childNodes[1]
.getAttribute('href');
return link;
}
throw new Error("Failed to retrieve email verification link");
}
Cypress.Commands.add("checkVerificationEmail", async (id) => {
return await getEmailVerificationLink(id)
})
Cypress.Commands.add("createDummyAccount", async () => {
try {
// Create a New Inbox for the new test user;
// email will be created below;
const id = uuidv4();
const email = `${NAMESPACE}.${id}@inbox.testmail.app`;
const name = faker.name.findName();
const organization = faker.company.companyName()
const description = "Fluvio Cloud Test User"
const password = faker.fake("{{internet.password}}{{random.number}}");
return {
id,
email,
name,
description,
organization,
password
}
} catch (error) {
console.log('error', error);
alert(error.message)
}
}) The output I get from the Cypress command is
Here is a screen recording of the test when I run it as Screen.Recording.2021-01-04.at.11.53.47.AM.movI've been trying to figure this out for a few days now, nothing that I've read in the documentation has mentioned anything about the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You cannot use the See https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous and https://glebbahmutov.com/blog/writing-custom-cypress-command/ |
Beta Was this translation helpful? Give feedback.
You cannot use the
async
keyword in your custom command definitions likeCypress.Commands.add("createDummyAccount", async () => {
, it will NOT work. Cypress commands are already asynchronous and I bet thisasync
causes unpredictable behavior.See https://docs.cypress.io/guides/core-concepts/introduction-to-cypress.html#Commands-Are-Asynchronous and https://glebbahmutov.com/blog/writing-custom-cypress-command/