Any suggestions on where to improve within my test scripts?

Hi People,

I’m trying to re-learn my automation skills with cypress as I have eight months remaining in this manual role and I am hoping I can use a repository to demonstrate my skills & use it as a guiding template for future automation projects.

Unfortunately, the company I work with doesn’t have any developers within the org and I don’t have any close contacts who deal with Cypress.

If possible, could someone give me some pointers on whether I am doing things correctly or not?
P.S be harsh if you have to, I need to learn!

Here is my git hub repo: antwan1/MainCypressDemoAntonio: E2E Testing with cypress (github.com)

At the moment I am starting small and basic with SauceDemo, once I add improvements to my next project I will add methods of authentication, API and better containerisation.

5 Likes

Hi Antonio,

I am not an expert but here are a few things I observed.

You would be better creating a .gitignore file and adding node_modules. This can help with reducing repository size and avoid version conflicts etc. There are a couple of other reasons so have a read into it.

Formatting in commands.js could be nicer. Mix of single ’ and " used throughout. Some spacing inconsistency as well. This seems a common theme between the files. Plenty of information online around best practices.

I don’t think you need to call cy.clearCookies() in the tests. Based on the docs this gets reset on each run due to test isolation being true by default.

Personally I would try to make some of the tests a bit more atomic. For example inventory.cy.js:

  1. Login using Cypress Session - this would allow you to stay logged in for all tests saving time. You could also shift all the code to 1 login command.
  2. Click the inventory items
  3. Assert you have navigated to the correct page etc

Then for for the next test navigate directly to the correct inventory url and assert the image and text etc.

I like using Cypress Intercept to stub the API responses if only caring about the UI. Then test the APIs independently using Cypress Request. Adding in both of those would be good. The TAU Advanced Cypress Course covers those topics.

Hopefully that helps a bit.

4 Likes

This helps so much, I will try to implement what you have mentioned and check out the advanced cypress course at TAU.

Hopefully, all of these things will make the test more efficient and better formated!

Thank you for the advice!

2 Likes

Maybe this freely available talk will be helpful?

1 Like

That is a useful video and look into, this will go in hand with the TAU course and hopefully, it will increase my confidence in testing and less flaky tests in general. Thank you so much!

1 Like