Search⌘ K
AI Features

Testing Asking a Question

Explore how to implement comprehensive automated end-to-end tests using Cypress in a React and ASP.NET Core web app. This lesson guides you through writing tests for signing in, asking questions, form validation, page navigation, and verifying UI elements. Understand Cypress commands that handle asynchronous operations and their integration into development workflows to ensure robust app functionality.

We are going to implement a test on our app using Cypress; the test signs in and then asks a question.

Testing with Cypress: Step-by-step guide

Carry out the following steps to do so:

  1. Let’s create a new file called qanda.js in the integration folder, which can be found in the cypress folder, with the following content:

C#
describe('Ask question', () => {
beforeEach(() => {
cy.visit('/');
});
it('When signed in and ask a valid question, the
question should successfully save', () => {
});
});

The describe function allows us to group a collection of tests on a feature. The first parameter is the title for the group, while the second parameter is a function that contains the tests in the group.

The it function allows us to define the actual test. The first parameter is the title for the test, while the second parameter is a function that contains the steps in the test.

The beforeEach function allows us to define steps to be executed before each test runs. In our case, we are using the visit command to navigate to the root of the app. Remember that the root URL for the app is defined in the baseUrl setting in the cypress.json file.

  1. Let's add the following step to our test:

C#
it('When signed in and ask a valid question, the
question should successfully save', () => {
cy.contains('Q & A');
});

Here, ...