• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #12632

pending completion
#12632

push

circleci

web-flow
Merge pull request #2854 from mozilla/MNTOR-741

MNTOR-741

282 of 1416 branches covered (19.92%)

Branch coverage included in aggregate %.

107 of 107 new or added lines in 9 files covered. (100.0%)

959 of 3912 relevant lines covered (24.51%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/e2e/utils/helpers.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import { request } from '@playwright/test'
6

7
export const defaultScreenshotOpts = {
×
8
  animations: 'disabled',
9
  maxDiffPixelRatio: 0.04
10
}
11

12
export const ENV_URLS = {
×
13
  local: 'http://localhost:6060',
14
  dev: 'https://fx-breach-alerts.herokuapp.com',
15
  stage: 'https://stage.firefoxmonitor.nonprod.cloudops.mozgcp.net'
16
}
17

18
export const setEnvVariables = async (email) => {
×
19
  process.env.E2E_TEST_ENV = process.env.E2E_TEST_ENV || 'local'
×
20
  process.env.E2E_TEST_ACCOUNT_EMAIL = email
×
21
  process.env.E2E_TEST_BASE_URL = ENV_URLS[process.env.E2E_TEST_ENV] || 'https://stage.firefoxmonitor.nonprod.cloudops.mozgcp.net'
×
22
}
23

24
export const getVerificationCode = async (testEmail, page, attempts = 10) => {
×
25
  if (attempts === 0) {
×
26
    throw new Error('Unable to retrieve restmail data')
×
27
  }
28

29
  const context = await request.newContext()
×
30
  const res = await context.get(
×
31
    `http://restmail.net/mail/${testEmail}`,
32
    {
33
      failOnStatusCode: false
34
    }
35
  )
36
  const resJson = await res.json()
×
37
  if (resJson.length) {
×
38
    const verificationCode = resJson[0].headers['x-verify-short-code']
×
39
    return verificationCode
×
40
  }
41

42
  await page.waitForTimeout(1000)
×
43
  return getVerificationCode(testEmail, page, attempts - 1)
×
44
}
45

46
const enterYourEmail = async (page) => {
×
47
  const maybeEmailInput = 'input[name="email"]'
×
48
  await page.waitForSelector(maybeEmailInput, { timeout: 2000 })
×
49
  const signInButton = page.locator('#submit-btn')
×
50
  await page.locator(maybeEmailInput).fill(process.env.E2E_TEST_ACCOUNT_EMAIL_FREE)
×
51
  await signInButton.click({ force: true })
×
52
  await page.waitForTimeout(500)
×
53
  await checkAuthState(page)
×
54
}
55

56
const enterYourPassword = async (page) => {
×
57
  await page.locator('#password').fill(process.env.E2E_TEST_ACCOUNT_PASSWORD)
×
58

59
  // using force here due to fxa issue with playwright
60
  await page.locator('#submit-btn').click()
×
61
  await page.waitForTimeout(500)
×
62
  await checkAuthState(page)
×
63
}
64

65
export const checkAuthState = async (page) => {
×
66
  try {
×
67
    const authStateTitleString = await page.locator('h1').textContent({ timeout: 4000 })
×
68
    const checkIfTitleContains = (potentialTitle) => {
×
69
      return authStateTitleString?.includes(potentialTitle)
×
70
    }
71

72
    switch (true) {
×
73
      case checkIfTitleContains('Enter your email'):
74
        await enterYourEmail(page)
×
75
        break
×
76
      case checkIfTitleContains('Enter your password'):
77
        await enterYourPassword(page)
×
78
        break
×
79
      // case checkIfTitleContains('Set your password'):
80
      //   await setYourPassword(page)
81
      //   break
82
      // case checkIfTitleContains('Enter confirmation code'):
83
      //   await enterConfirmationCode(page)
84
      //   break
85
      // case checkIfTitleContains('Sign in'):
86
      //   await signIn(page)
87
      //   break
88
      default:
89
        break
×
90
    }
91
  } catch {}
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc