cfa-cypress

1.0.3 • Public • Published

CFA Cypress Helpers

API

CFA Cypress provides several useful helper methods to make writing Cypress tests easier and more efficient.

Menu Helpers

getMenu(String:locationNumber, Boolean:catering = false, String:destination = 'pickup')

Fetches the menu for a given location and destination. Returns a Promise that resolves with the menu API response.

getMenu('01668', true, 'pickup')
.then(menuResponse => console.log(menuResponse.body))

getMenuMap(String:locationNumber, Boolean:catering = false, String:destination = 'pickup')

Similar to getMenu, but returns a Promise that resolves with an object representing an easier to use map of the menu.

getMenuMap('01668', true, 'pickup')
.then(({ parentTagsByTag, itemsByItemGroupIdAndTag, categories }) => console.log(parentTagsByTag, itemsByItemGroupIdAndTag, categories))
/* {
    8OZ_BARBEQUE_SAUCE: 500011,
    8OZ_BUFFALO_SAUCE: 500011,
    8OZ_CFA_SAUCE: 500011,
    8OZ_HONEY_MUSTARD: 500011,
    8OZ_POLYNESIAN: 500011,
    8OZ_RANCH: 500011,
    8OZ_SAUCES: 500058,
    8OZ_SAUCES_PAID: 500058,
    8OZ_SRIRACHA: 500011,
    ...
},
{
    500001: {CHICK_N_MINIS_TRAY_SMALL: {…}, CHICK_N_MINIS_TRAY_LARGE: {…}},
    500002: {YOGURT_GREEK_PARFAIT_COOKIE: {…}, YOGURT_GREEK_PARFAIT_GRANOLA: {…}},
    500003: {FRUIT_CUP_SMALL: {…}, FRUIT_CUP_MEDIUM: {…}, FRUIT_CUP_LARGE: {…}},
    ...
},
[
    {items: Array(8), desktopImage: "https://www.cfacdn.com/img/order/Catering/Breakfast/Chicken_biscuit.png", mobileImage: "", ...},
    ...
]*/

lookupPriceOfItem(Object:menuMap, String:parentTag, String:childTag)

Returns the itemPrice attribute of the item with the given childTag in Number format.

it('Looks up the price of an item', () => {
    getMenuMap('01668', true, 'pickup').then((menuMap) => {
      const price = lookupPriceOfItem(menuMap, 'CHICK_N_STRIPS_TRAY_HOT_SMALL', 'CHICK_N_STRIPS_TRAY_HOT_SMALL');
      expect(price).to.equal(27.5)
    })
  })

Okta

oktaLogin(String:username, String:password)

Logs into Okta with the given credentials and sets the relevant cookies. This should be called in the before hook or in the first step definition if using Cucumber.

IMPORTANT: DO NOT STORE PASSWORDS IN GIT. Create a cypress.env.json file, and add it to your .gitignore. Then add key-value pairs for username and password. Pass them to the function like this: Cypress.env('username'). You have been warned.

describe('My App', () => {
  before(() => {
    oktaLogin(Cypress.env('username'), Cypress.env('password'));
  })
  
  it('does stuff', () => {
    // Test here...
  })
})
// cypress/support/step_definitions.js
given('I launch the app', () => {
  oktaLogin(Cypress.env('username'), Cypress.env('password'));
  cy.visit('/')
})

Profile

createNewProfile(String:token, String:sessionId)

Create a new CFAOne profile for use in automation testing. This is necessary because having an excessive number of orders for one particular account (i.e. if one account is continually used for automation testing), lookup times in Dynamo can slow to a crawl.

Returns a Promise that resolves with token, sessionId, and username, password of the new account.

createNewProfile(Cypress.env('TOKEN'), Cypress.env('sessionId'))
.then((email, password, token, sessionId) => console.log(email, password, token, sessionId))

login(String:email, String:password, String:token, String:sessionId)

Logs into an account via the API.

Returns a Promise that resolves with the API response.

login(Cypress.env('username'), Cypress.env('password'), Cypress.env('TOKEN'), Cypress.env('sessionId'))
.then(apiResponse => console.log(apiResponse))

Or, when used with createNewProfile:

createNewProfile(Cypress.env('TOKEN'), Cypress.env('sessionId')).then(login);

Readme

Keywords

none

Package Sidebar

Install

npm i cfa-cypress

Weekly Downloads

0

Version

1.0.3

License

ISC

Unpacked Size

170 kB

Total Files

19

Last publish

Collaborators

  • paulmoliva