Skip to content

Instantly share code, notes, and snippets.

View alfredlucero's full-sized avatar

Alfred Lucero alfredlucero

View GitHub Profile
@alfredlucero
alfredlucero / pipeline.yml
Last active August 5, 2020 16:50
Cypress Tips/Tricks - Select Cypress tests to run in Buildkite pipeline.yml
# Our main pipeline.yml CICD flow
steps:
# We do other steps on every push to a PR and merge to master such as building a Docker image,
# building our JS/HTML/CSS assets, running unit tests, deploying to environments, etc.
# We have the option to trigger selected Cypress tests against our testing/feature branch environment
# for all nonmaster branches before deploying to staging
# We will later parse out the Yes/glob file path values vs. No values when forming the Cypress --spec option
- block: ':cypress: Choose Cypress specs to run in testing environment :cypress:'
branches: '!master'
@alfredlucero
alfredlucero / emailLinkRedirectCypress.ts
Last active July 9, 2022 15:45
Cypress Tips/Tricks - Using cheerio to parse email body contents, make cy.request() to links, follow redirect back to web app
// In some page_object.ts
// For this scenario, we have a Cypress test that triggers a download email to be sent to the user's inbox after performing
// some UI steps on the page i.e. clicking a button on the page to export data to a CSV for us to download
// We need to follow the download link in the email back to the web app we own and control to continue the test
redirectToCSVDownloadPageFromEmail({
user,
pass,
searchString,
}: {
user: string;
@alfredlucero
alfredlucero / searchBySubject.ts
Created August 1, 2020 19:12
Cypress Tips/Tricks - Searching for emails with matching subject and returning body contents cy.task()
// in an emailjs-imap-client.d.ts so we can type the imap client functions ourselves
declare module 'emailjs-imap-client';
// squirrelmail.ts (where we define all of our email related task functions
import ImapClient, { LOG_LEVEL_NONE as none } from 'emailjs-imap-client';
const Squirrelmail = () => {
const squirrelmailServer = "somesquirrelmailserver.net"
const port = 993;
@alfredlucero
alfredlucero / awaitEmailInSquirrelmailInbox.ts
Last active August 1, 2020 18:57
Cypress Tips/Tricks - Waiting for email to arrive in inbox cy.task()
// in an emailjs-imap-client.d.ts so we can type the imap client functions ourselves
declare module 'emailjs-imap-client';
// squirrelmail.ts (where we define all of our email related task functions
import ImapClient, { LOG_LEVEL_NONE as none } from 'emailjs-imap-client';
const Squirrelmail = () => {
const squirrelmailServer = "somesquirrelmailserver.net"
const port = 993;
@alfredlucero
alfredlucero / awaitEmailInSquirrelmailInbox.ts
Created August 1, 2020 18:54
Cypress Tips/Tricks - Waiting for email to arrive in inbox cy.task()
// in an emailjs-imap-client.d.ts so we can type the imap client functions ourselves
declare module 'emailjs-imap-client';
// squirrelmail.ts (where we define all of our email related task functions
import ImapClient, { LOG_LEVEL_NONE as none } from 'emailjs-imap-client';
const Squirrelmail = () => {
const squirrelmailServer = "somesquirrelmailserver.net"
const port = 993;
@alfredlucero
alfredlucero / teardownMatchingEmails.ts
Last active August 5, 2020 16:49
Cypress Tips/Tricks - Tearing doing matching emails cy.task()
// in an emailjs-imap-client.d.ts so we can type the imap client functions ourselves
declare module 'emailjs-imap-client';
// squirrelmail.ts (where we define all of our email related task functions)
import ImapClient, { LOG_LEVEL_NONE as none } from 'emailjs-imap-client';
const Squirrelmail = () => {
const squirrelmailServer = "somesquirrelmailserver.net"
const port = 993;
@alfredlucero
alfredlucero / cypress.json
Created July 30, 2020 22:32
Cypress Tips/Tricks - Sample cypress.json
{
"baseUrl": "http://localhost:9001",
"chromeWebSecurity": false,
"projectId": "projectidhash",
"blacklistHosts": [
"*googletagmanager.com",
"*google-analytics.com",
"*moreanalytics.com",
"*moreblockedscripts.com"
],
@alfredlucero
alfredlucero / window_cypress_checks.js
Created July 30, 2020 22:27
Cypress Tips/Tricks - Choosing not to run client-side code with window.Cypress checks
// As an extra escape hatch, you can choose to run or not run certain client-side code during Cypress tests by checking
// for the window.Cypress value. We highlight some example use cases for why you'd need to do this below
// If we're running an A/B experiment where different views may show up for a user,
// we need to make sure it doesn't lead to Cypress test flakiness by choosing not to run A/B tests during Cypress tests
if (!window.Cypress) {
runABExperiment();
}
// If one of our flows deals with an auto-downloading link which may lead to breaking/pausing Cypress tests
@alfredlucero
alfredlucero / selectors.ts
Last active July 30, 2020 22:17
Cypress Tips/Tricks - Write/Read Selectors Usage in a selectors.ts
// selectors.ts at the base of each page's component folder
import { writeSelectorGenerator, readSelectorGenerator } from ‘../path/to/selectorGenerator’;
const selectors = {
addButton: null,
submitButton: “superSubmitButton”
};
export const Selectors = {
...readSelectorGenerator(selectors),
@alfredlucero
alfredlucero / write_selector_generator.ts
Created July 30, 2020 21:14
Cypress Tips/Tricks - Write Selector Generator
interface WriteHook {
'data-hook': string;
}
const writeHook = (hook: string): WriteHook => ({ 'data-hook': hook });
type WriteSelectors<T> = { [P in keyof T]: WriteHook };
/*
This takes in a general object like