Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/accept objects and paths to files #89

Conversation

MatteoMolinari93
Copy link
Contributor

#71

@dreilly-icf
Copy link

Is there a reason why this PR isn't being merged? The changes are pretty sensible.

Using a non-file method of authentication makes sense for CI/CD implementations (like ours) which manage them via environment variables.

@levz0r
Copy link
Owner

levz0r commented Jun 1, 2022

Even though the PR looks great, I didn't have a chance to test it in a CI/CD environment. @dreilly-icf can you confirm it works for you?

@dreilly-icf
Copy link

Hi @levz0r - first off-- thanks for the question and this fantastic package. It's enabled our automation project in ways we've just begun to comprehend.

I can presently confirm this PR works with the credentials/token passed as a string. I'm currently working on implementing the pipelines, but the first piece is done.

There's a couple more steps I need to take on the devops side, but as long as we set up the resources correctly, Cypress won't know the difference between a pipeline execution and a local one. Here's our general flow:

  1. we store our credential/token within a secret manager (for us, AWS Secrets Manager).
  2. retrieve the secret in the provisioning phase and store as a b64-encoded environment variable.
  3. Run the container and pass the b64 encoded json to Cypress via the --env flag.
  4. We marshall the b64 to json and passed to your app.

Since we haven't committed our cypress.env.json, we can test as-if we were in the pipeline.

All this is to say, if it works locally, it should work in our pipelines. Either way, I can provide positive confirmation when our pipelines are implemented in case anything sneaks up.

@dreilly-icf
Copy link

dreilly-icf commented Jun 3, 2022

@levz0r -

I've set up the secrets and all necessary resources within our pipeline. I can, indeed, confirm it works.

output:

50 | docker run  \
51 | -v $PWD/e2e_testing/cypress:/e2e_testing/cypress \
52 | -w /e2e_testing \
53 | $CYPRESS_DOCKER_IMAGE \
54 | --config baseUrl=$(echo "$CYPRESS_BASE_URL") \
55 | --env PIPELINE=true,E2E_USER_LIST=$CYPRESS_E2E_USER_LIST,GMAIL_CREDENTIAL=$GMAIL_CREDENTIAL,GMAIL_TOKEN=$GMAIL_TOKEN,AWS_REGION=$AWS_REGION,REACT_APP_USER_POOL_ID=$REACT_APP_USER_POOL_ID,REACT_APP_USER_POOL_WEB_CLIENT_ID=$REACT_APP_USER_POOL_WEB_CLIENT_ID,REACT_APP_COGNITO_REDIRECT_URL=$REACT_APP_COGNITO_REDIRECT_URL 2>&1 \
56 | --headless  \
57 | --browser chrome \
58 | --spec "cypress/**/*/email.spec.js" \
59 | \|\| exit 0
60 |
61 | Unable to find image 'XXXXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/automation-image:latest' locally
62 | latest: Pulling from automation-image

As you can see, our docker container has spun up successfully. This was part of our build pipeline which retrieves the docker container. After downloading, the run begins:

(Run Starting)
--
230 |  
231 | ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
232 | │ Cypress:        9.4.1                                                                          │
233 | │ Browser:        Chrome 97 (headless)                                                           │
234 | │ Node Version:   v16.5.0 (/usr/local/bin/node)                                                  │
235 | │ Specs:          1 found (general/email.spec.js)                                                │
236 | │ Searched:       cypress/**/*/email.spec.js                                                     │
237 | └────────────────────────────────────────────────────────────────────────────────────────────────┘
238 |  
239 | Remove output folder cypress/reports/mocha
240 |  
241 | ────────────────────────────────────────────────────────────────────────────────────────────────────
242 |  
243 | Running:  general/email.spec.js                                                           (1 of 1)
244 |  
245 |  
246 | test the gmail task
247 | emails found
248 | ✓ attempt new auth
249 |  
250 |  
251 | 1 passing (966ms)
252 |  
253 | [mochawesome] Report JSON saved to /e2e_testing/cypress/reports/mocha/.jsons/mochawesome.json
254 |  
255 |  
256 | (Results)
257 |  
258 | ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
259 | │ Tests:        1                                                                                │
260 | │ Passing:      1                                                                                │
261 | │ Failing:      0                                                                                │
262 | │ Pending:      0                                                                                │
263 | │ Skipped:      0                                                                                │
264 | │ Screenshots:  0                                                                                │
265 | │ Video:        false                                                                            │
266 | │ Duration:     0 seconds                                                                        │
267 | │ Spec Ran:     general/email.spec.js                                                            │
268 | └────────────────────────────────────────────────────────────────────────────────────────────────┘
269 |  
270 | Start generate report process
271 | Read and merge jsons from "cypress/reports/mocha/.jsons"
272 | Enhance report
273 | Create HTML report
274 | HTML report successfully created!
275 | /e2e_testing/cypress/reports/mocha/index.html
276 |  
277 | ====================================================================================================
278 |  
279 | (Run Finished)
280 |  
281 |  
282 | Spec                                              Tests  Passing  Failing  Pending  Skipped
283 | ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
284 | │ ✔  general/email.spec.js                    957ms        1        1        -        -        - │
285 | └────────────────────────────────────────────────────────────────────────────────────────────────┘
286 | ✔  All specs passed!                        957ms        1        1        -        -        -

The test itself:

describe('test the gmail task', () => {
  it.only('verify a specific email body', () => {
    debugger;
    cy.task('gmail:refresh-access-token').then((token) => {
      cy.log(token);
    });
    const options = {
      include_body: true,
      include_attachments: true,
      wait_time_sec: 20,
      label: 'gimme'
    };
    cy.task('gmail:get-messages', { options }).then((emails) => {
      cy.wrap(emails[0].body).should('exist');
    });
  });
});

So.. there you have it. We did have to make some tweaks, namely, downloading @MatteoMolinari93 feature branch to a local repo and modifying our package.json to point to this local directory.

After all is said and done, though, I hope we've demonstrated the validity of this PR.

@levz0r
Copy link
Owner

levz0r commented Jun 3, 2022

Thank you for the detailed information David, and thank you @MatteoMolinari93 for the PR. Merging it now.
P.S It could be really awesome if you could write something about using gmail-tester in a CI/CD environment.

@levz0r levz0r merged commit ca5de7c into levz0r:master Jun 3, 2022
@dreilly-icf
Copy link

I'd be glad to! If the write-up above is good, I'll work it into a .md file and open a PR for it. It seems most have figured out that they could take the "workaround" approach by retrieving the string and writing to a file, but if my example helps anyone better understand how this is accomplished, I'd be glad to help.

Thanks for your quick response and, again, for making something that provided real value to my team.

@MatteoMolinari93 MatteoMolinari93 deleted the feature/accept_objects_and_paths_to_files branch June 4, 2022 20:01
@dreilly-icf
Copy link

Hi @levz0r - Sorry to be a bother.. is there a plan to release this change on NPM as a new package version? Not sure what the process entails.

Thanks!

@levz0r
Copy link
Owner

levz0r commented Jun 8, 2022

Just released a new version on NPM. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants