---
id: app/end-to-end-testing/writing-your-first-end-to-end-test
title: 'End-to-End Testing: Your First Test with Cypress'
description: >-
  Dive into Cypress end-to-end testing with a guide on writing your first test.
  Learn step-by-step, best practices, and tips for efficient test creation
section: app
source_path: docs/app/end-to-end-testing/writing-your-first-end-to-end-test.mdx
version: ce02913654e2655ee63448bdc92bb92c7b46a619
updated_at: '2026-04-22T19:37:51.587Z'
---
# Your First Test

##### &#x20;What you'll learn

- How to write your first end-to-end test in Cypress using an example app
- How to use Cypress commands to interact with elements on a page
- How to make assertions about the state of the application
  :::

## Add a test file

Assuming you've successfully
[installed Cypress](/llm/markdown/app/get-started/install-cypress.md) and
[opened Cypress](/llm/markdown/app/get-started/open-the-app.md), now it's time to add
your first test. We're going to do this with the **Create new empty
spec** button.

On clicking it, you should see a dialog where you can enter the name of your new
spec. Just accept the default name for now.

The newly-generated spec is displayed in a confirmation dialog. Just go ahead
and close it with the ✕ button.

Once we've created that file, you should see it immediately displayed in the
list of end-to-end specs. Cypress monitors your spec files for any changes and
automatically displays any changes.

Even though we haven't written any code yet - that's okay - let's click on your
new spec and watch Cypress launch it. Cypress will visit `https://example.cypress.io` and the test passes.

## Write your first test

Now it's time to write your first test. We're going to:

1. Write your first passing test.
2. Update it so it fails.
3. Watch Cypress reload in real time.

Open up your favorite IDE and replace the contents of your spec with the code
below.

```js
describe('My First Test', () => {
  it('Does not do much!', () => {
    expect(true).to.equal(true)
  })
})
```

Once you save this change you should see the browser reload.

Although it doesn't do anything useful, this is our first passing test! ✅

Over in the [Command Log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) you'll
see Cypress display the suite, the test and your first assertion (which should
be passing in green).

Notice Cypress displays a message about this being the default page
[on the righthand side](/llm/markdown/app/core-concepts/open-mode.md#Application-Under-Test).
Cypress assumes you'll want to go out and [visit](/llm/markdown/api/commands/visit.md) a URL on
the internet - but it can also work just fine without that.

Now let's write our first failing test.

```js
describe('My First Test', () => {
  it('Does not do much!', () => {
    expect(true).to.equal(false)
  })
})
```

Once you save again, you'll see Cypress display the failing test in red since
`true` does not equal `false`.

Cypress displays a detailed error view that includes the stack trace and the exact code frame where the assertion failed. This helps you quickly identify and fix the issue.

If you don't see the code frame or stack trace, you may need to [enable sourcemaps](/llm/markdown/app/guides/debugging.md#Source-maps) for better debugging information.

You can click on the blue file link to open the file
where the error occurred in
[your preferred file opener](/llm/markdown/app/tooling/IDE-integration.md#File-Opener-Preference).
To read more about the error's display, read about
[Debugging Errors](/llm/markdown/app/guides/debugging.md#Errors).

[Cypress](/llm/markdown/app/core-concepts/open-mode.md) gives you a visual structure of
suites, tests, and assertions. Soon you'll also see commands, page events,
network requests, and more.

**What are *describe*, *it*, and *expect* ?**

All of these functions come from
[Bundled Libraries](/llm/markdown/app/references/bundled-libraries.md) that Cypress bakes in.

- `describe` and `it` come from [Mocha](https://mochajs.org)
- `expect` comes from [Chai](http://www.chaijs.com)

Cypress builds on these popular tools and frameworks that you *hopefully*
already have some familiarity and knowledge of. If not, that's okay too.

## Write a real test

**A solid test generally covers 3 phases:**

1. Set up the application state.
2. Take an action.
3. Make an assertion about the resulting application state.

You might also see this phrased as "Given, When, Then", or "Arrange, Act,
Assert". But the idea is: First you put the application into a specific state,
then you take some action in the application that causes it to change, and
finally you check the resulting application state.

Today, we'll take a narrow view of these steps and map them cleanly to Cypress
commands:

1. Visit a web page.
2. Query for an element.
3. Interact with that element.
4. Assert about the content on the page.

### &#x20;Step 1: Visit a page

First, let's visit a web page. We will visit our
[Kitchen Sink](https://github.com/cypress-io/cypress-example-kitchensink) application in this example
so that you can try Cypress out without needing to worry about finding a page to
test.

We can pass the URL we want to visit to [`cy.visit()`](/llm/markdown/api/commands/visit.md).
Let's replace our previous test with the one below that actually visits a page:

```js
describe('My First Test', () => {
  it('Visits the Kitchen Sink', () => {
    cy.visit('https://example.cypress.io')
  })
})
```

Save the file and switch back over to the Cypress Test Runner. You might notice
a few things:

1. The [Command Log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) now shows
   the new `VISIT` action.
2. The Kitchen Sink application has been loaded into the
   [App](/llm/markdown/app/core-concepts/open-mode.md).
3. The test is green, even though we made no assertions.
4. The `VISIT` displays a **blue pending state** until the page finishes
   loading.

Had this request come back with a non `2xx` status code such as `404` or `500`,
or if there was a JavaScript error in the application's code, the test would
have failed.

### &#x20;Step 2: Query for an element

Now that we've got a page loaded, we need to take some action on it. Why don't
we click a link on the page? Sounds easy enough, let's go look for one we
like... how about `type`?

To find this element by its contents, we'll use
[cy.contains()](/llm/markdown/api/commands/contains.md).

Let's add it to our test and see what happens:

```js
describe('My First Test', () => {
  it('finds the content "type"', () => {
    cy.visit('https://example.cypress.io')
    cy.contains('type')
  })
})
```

Our test should now display `CONTAINS` in the
[Command Log](/llm/markdown/app/core-concepts/open-mode.md#Command-Log) and still be green.

Even without adding an assertion, we know that everything is okay! This is
because many of Cypress' commands are built to fail if they don't find what
they're expecting to find. This is known as an
[Implicit Assertion](/llm/markdown/app/core-concepts/introduction-to-cypress.md#Implicit-Assertions).

To verify this, replace `type` with something not on the page, like `hype`.
You'll notice the test goes red, but only after about 4 seconds!

Can you see what Cypress is doing under the hood? It's automatically waiting and
retrying because it expects the content to **eventually** be found in the DOM.
It doesn't immediately fail!

Error Messages

Cypress provides detailed, human-readable error messages that explain exactly what went wrong. In this case, Cypress **timed out retrying** to find the content `hype` within the entire page. These descriptive error messages help you quickly understand and fix issues in your tests. For more information about how Cypress displays errors, see [Debugging Errors](/llm/markdown/app/guides/debugging.md#Errors).

Before we add another command - let's get this test back to passing. Replace
`hype` with `type`.

### &#x20;Step 3: Click an element

Ok, now we want to click on the link we found. How do we do that? Add a
[.click()](/llm/markdown/api/commands/click.md) command to the end of the previous command, like
so:

```js
describe('My First Test', () => {
  it('clicks the link "type"', () => {
    cy.visit('https://example.cypress.io')

    cy.contains('type').click()
  })
})
```

You can almost read it like a little story! Cypress calls this "chaining" and we
chain together commands to build tests that really express what the app does in
a declarative way.

Also note that the [App](/llm/markdown/app/core-concepts/open-mode.md)
has updated further after the click, following the link and showing the
destination page:

Now we can assert something about this new page!

✨ IntelliSense is available in your Cypress spec files by adding a special
triple slash comment line. Read about
[Intelligent Code Completion](/llm/markdown/app/tooling/IDE-integration.md#Triple-slash-directives).

### &#x20;Step 4: Make an assertion

Let's make an assertion about something on the new page we clicked into. Perhaps
we'd like to make sure the new URL is the expected URL. We can do that by
looking up the URL and chaining an assertion to it with
[.should()](/llm/markdown/api/commands/should.md).

Here's what that looks like:

```js
describe('My First Test', () => {
  it('clicking "type" navigates to a new url', () => {
    cy.visit('https://example.cypress.io')

    cy.contains('type').click()

    // Should be on a new URL which
    // includes '/commands/actions'
    cy.url().should('include', '/commands/actions')
  })
})
```

#### Adding more commands and assertions

We are not limited to a single interaction and assertion in a given test. In
fact, many interactions in an application may require multiple steps and are
likely to change your application state in more than one way.

We can continue the interactions and assertions in this test by adding another
chain to interact with and verify the behavior of elements on this new page.

We can use [cy.get()](/llm/markdown/api/commands/get.md) to select an element based on its
class. Then we can use the [.type()](/llm/markdown/api/commands/type.md) command to enter text
into the selected input. Finally, we can verify that the value of the input
reflects the text that was typed with another [.should()](/llm/markdown/api/commands/should.md).

In general, the structure of your test should flow query -> query -> command or
assertion(s). It's best practice not to chain anything after an action command;
for more details on why this is, see our guide on
[retry-ability](/llm/markdown/app/core-concepts/retry-ability.md).

```js
describe('My First Test', () => {
  it('Gets, types and asserts', () => {
    cy.visit('https://example.cypress.io')

    cy.contains('type').click()

    // Should be on a new URL which
    // includes '/commands/actions'
    cy.url().should('include', '/commands/actions')

    // Get an input, type into it
    cy.get('.action-email').type('fake@email.com')

    //  Verify that the value has been updated
    cy.get('.action-email').should('have.value', 'fake@email.com')
  })
})
```

And there you have it: a short test in Cypress that visits a page, finds and
clicks a link, verifies the URL and then verifies the behavior of an element on
the new page. If we read it out loud, it might sound like:

1. *Visit: `https://example.cypress.io`*
2. *Find the element with content: `type`*
3. *Click on it*
4. *Get the URL*
5. *Assert it includes: `/commands/actions`*
6. *Get the input with the `action-email` class*
7. *Type `fake@email.com` into the input*
8. *Assert the input reflects the new value*

Or in the *Given*, *When*, *Then* syntax:

1. ***Given** a user visits `https://example.cypress.io`*
2. ***When** they click the link labeled `type`*
3. *And they type "<fake@email.com>" into the input that has a class of `action-email`
   input*
4. ***Then** the URL should include `/commands/actions`*
5. *And the `[class="action-email"]` input has "<fake@email.com>" as its
   value*

And hey, this is a very clean test! We didn't have to say anything about *how*
things work, just that we'd like to verify a particular series of events and
outcomes.

Page Transitions

Worth noting is that this test transitioned across two different pages.

1. The initial [cy.visit()](/llm/markdown/api/commands/visit.md)
2. The [.click()](/llm/markdown/api/commands/click.md) to a new page

Cypress automatically detects things like a `page transition event` and will
automatically **halt** running commands until the next page has **finished**
loading.

Had the **next page** not finished its loading phase, Cypress would have ended
the test and presented an error.

Under the hood - this means you don't have to worry about commands accidentally
running against a stale page, nor do you have to worry about running commands
against a partially loaded page.

We mentioned previously that Cypress waited **4 seconds** before timing out
finding a DOM element - but in this case, when Cypress detects a
`page transition event` it automatically increases the timeout to **60 seconds**
for the single `PAGE LOAD` event.

In other words, based on the commands and the events happening, Cypress
automatically alters its expected timeouts to match web application behavior.

These various timeouts are defined in the
[Configuration](/llm/markdown/app/references/configuration.md#Timeouts) document.

## Record Tests with Cypress Studio

If you want a minimal code approach to creating tests, you can use
[Cypress Studio](/llm/markdown/app/guides/cypress-studio.md) to record your browser
interactions and generate tests. With a [Cypress Cloud](/llm/markdown/cloud/get-started/introduction.md) account, you also get **Studio AI**—assertion recommendations as you record. Visit our
[guide](/llm/markdown/app/guides/cypress-studio.md) for more information.

## Next steps

- [Test your own app](/llm/markdown/app/end-to-end-testing/testing-your-app.md) — apply what you learned here to a real project.
- [Introduction to Cypress](/llm/markdown/app/core-concepts/introduction-to-cypress.md) — understand how Cypress really works under the hood.
- [Best Practices](/llm/markdown/app/core-concepts/best-practices.md) — learn selector strategies, state management, and patterns for maintainable tests.
- [Cypress AI Skills](/llm/markdown/app/tooling/ai-skills.md) — use your AI coding tool to write, fix, and review Cypress tests with best practices built in.
