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

exercicios nivel 1 #4

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

exercicios nivel 1 #4

wants to merge 21 commits into from

Conversation

eduardoeffs
Copy link

No description provided.

Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parabéns pela resolução dos exercícios @eduardoeffs. 👏🏻

Deixei comentários ao longo do seu código, os quais creio que lhe ajudarão a melhorar o design do mesmo.

Aguarde até o próximo encontro antes de implementar as mudanças.

cypress.config.js Outdated Show resolved Hide resolved
cypress.config.js Outdated Show resolved Hide resolved
cypress/e2e/API Tests/getCustomers.spec.js Outdated Show resolved Hide resolved
cypress/e2e/API Tests/getCustomers.spec.js Outdated Show resolved Hide resolved
cypress/e2e/API Tests/getCustomers.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/fixtures/example.json Outdated Show resolved Hide resolved
cypress/support/commands.js Outdated Show resolved Hide resolved
cypress/support/e2e.js Outdated Show resolved Hide resolved
@eduardoeffs
Copy link
Author

Alterações realizadas!

Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mais uma vez ótimo trabalho @eduardoeffs! 💯

Deixei outros comentários para lhe ajudar a melhorar ainda mais o design do código.

Lembre-se se só enviar novas mudanças para revisão após o terceiro encontro da Test Design Masterclass.

cypress.config.js Outdated Show resolved Hide resolved
cypress/e2e/API Tests/getCustomers.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
cypress/e2e/GUI Tests/ui-funcionality-tests.spec.js Outdated Show resolved Hide resolved
it('Should show and hide a success message upon successfully sending the messenger form', () => {
cy.clock();
cy.get('[aria-label="Open messenger"]')
.click();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.click();
.click();

E um dos próximos encontros falaremos sobre o padrão 3A - AAA (Arrange, Act, Assert).

Ao utilizar essa convensão, é recomendado deixar uma linha em branco entre as pré-condições do teste (Arrange), as ações (Act) e as verificações de resultados esperado (Assert).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Olá, não dei Resolve neste pois não ajustei.

cy.get('#message')
.type('Test message');
cy.get('button[type="submit"]')
.click();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Até aqui seriam as ações (Act).

Suggested change
.click();
.click();

E abaixo as verificações (Assert).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recomendo revisitar isso para os outros testes também

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neste também não.

Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eduardoeffs, parabéns pela resolução dos exercícios. 👏🏻

Deixei alguns últimos comentários, os quais acredito que lhe ajudarão a desenvolver testes com um design melhor ainda.

Espero que tenhas gostado da experiência.

cy.request('GET', CUSTOMERS_API_URL)
.then(({status, body}) => {
expect(status).to.eq(200);
expect(body).to.have.property('customers');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que tal também verificar as sub-propriedades de customers?

failOnStatusCode: false,
}).then(({status, body}) => {
expect(status).to.eq(400);
expect(body).to.have.property('error');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que tal verificar a mensagem de erro propriamente dita?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo vale para outros testes de cenários de erro.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A propósito, que tal testar também o cenário onde page=0, visto que a mensagem de erro retornada é Invalid page or limit. Both must be positive numbers.

Perceba o positive numbers.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo vale para limit=0.

@@ -0,0 +1,155 @@
describe('EngageSphere', () => {
beforeEach(() => {
Cypress.on('window:before:load', window => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uma solução ainda mais simples, a qual substituiria 3 linhas por uma, seria a seguinte.

cy.setCookie('cookieConsent', 'accepted')

Que tal?

cy.contains('button', 'View')
.click()
cy.get('[class^="CustomerDetail"] h2')
.should('be.visible');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.should('be.visible');
.should('be.visible');

cy.get('[class^="CustomerDetail"] h2')
.should('be.visible');
cy.contains('button', 'Back')
.click();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.click();
.click();

É uma boa prática separar pré-condições, ações e resultados esperados por uma linha em branco.

Isso facilita identificar cada parte do teste.

Falaremos mais sobre isso no último encontro da Test Design Masterclass quando abordarmos o padrão AAA (Arrange, Act, Assert).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo vale para os demais testes.

it('Should return to the customer list after clicking back', () => {
cy.contains('button', 'View')
.click()
cy.get('[class^="CustomerDetail"] h2')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que tal um seletor mais simples, como o seguinte?

Suggested change
cy.get('[class^="CustomerDetail"] h2')
cy.contains('h2', 'Customer Details')

Dessa forma, garantimos que o texto correto é exibido no h2.


it('Should display the footer with the correct text and links', () => {
cy.contains('p', 'Copyright 2024 - Talking About Testing')
.should('be.visible');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Atenção com a indentação.

Aqui devia ser assim:

Suggested change
.should('be.visible');
.should('be.visible');

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo vale para outros lugares onde a indentação está incorreta.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistência é importante para um bom design.


it('Should displays the greeting "Hi, Joe" when the name Joe is given', () => {
cy.get('input[type="text"]')
.type('Joe');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.type('Joe');
.type('Joe');

Só separando ação de resultado esperado.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aplique o mesmo aos outros testes.

E antes de fazer tal separação, pense bem sobre quais são as pré-condições dos testes, suas ações e seus resultados esperados.

it('Should display title, theme switcher and input field', () => {
cy.contains('h1', 'EngageSphere')
.should('be.visible');
cy.get('[class^="ThemeToggle_button"]')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visto que seletores assim se repetem ao longo do código, que tal criar um comando customizado chamado getByClassThatStartsWith?

O mesmo seria implementado assim:

Cypress.Commands.add('getByClassThatStartsWith', classPart => {
  cy.get(`[class^="${classPart}"]`)
})

E seria usado assim:

cy.getByClassThatStartsWith('ThemeToggle_button')

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acabo de ver mais abaixo que você já criou tal comando, portanto, recomendo usá-lo aqui.

.should('be.visible');
cy.get('[aria-label="Close messenger"]')
.click();
cy.get('[class^="Messenger_header"]')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui também.

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.

2 participants