### Project Structure for Reusable Setup
Source: https://docs.cypress.io/llm/json/full/app/component-testing/styling-components.json
This example illustrates a recommended project structure that allows for a shared setup file between your application's entry point and Cypress tests.
```bash
> /cypress> /support> /component.js> /src> /main.js> /main.css> /setup.js
```
--------------------------------
### Example Project Structure for Styles
Source: https://docs.cypress.io/llm/json/chunked/app/component-testing/styling-components.json
Illustrates a recommended project structure for managing styles and setup files, which can be reused in both your application's main entry point and Cypress test setup.
```bash
> /cypress>
> /support>
> /component.js>
> /src>
> /main.js>
> /main.css>
> /setup.js
```
--------------------------------
### Cypress Configuration with baseUrl
Source: https://docs.cypress.io/llm/json/chunked/api/commands/visit.json
Example Cypress configuration files demonstrating the setup of `baseUrl`.
```javascript
const { defineConfig } = require('cypress')
module.exports = defineConfig({
e2e: {
baseUrl: 'https://example.cypress.io',
},
})
```
```typescript
import { defineConfig } from 'cypress'
export default defineConfig({
e2e: {
baseUrl: 'https://example.cypress.io',
},
})
```
--------------------------------
### Basic CircleCI Setup with Cypress Orb
Source: https://docs.cypress.io/app/continuous-integration/circleci
This configuration installs and caches dependencies, then runs Cypress tests using the Cypress Orb. It's a starting point for integrating Cypress into your CI pipeline.
```yaml
version: 2.1
orbs:
cypress: cypress-io/cypress@6
workflows:
build:
jobs:
- cypress/run:
start-command: 'npm run start'
```
--------------------------------
### Basic Session Setup and Usage
Source: https://docs.cypress.io/llm/json/chunked/api/commands/session.json
This example demonstrates how to set up a session for a user and then use it in a test to perform actions like visiting a page and checking account balance.
```javascript
const login = (name) => {
cy.session(name, () => {
cy.request({
method: 'POST',
url: '/login',
body: { name, password: 's3cr3t' },
}).then(({ body }) => {
window.localStorage.setItem('authToken', body.token)
})
})
}
it('should transfer money between users', () => {
login('user')
cy.visit('/transfer')
cy.get('#amount').type('100.00')
cy.get('#send-money').click()
login('other-user')
cy.visit('/account_balance')
cy.get('#balance').should('eq', '100.00')
})
```
--------------------------------
### Getting the last matched request with cy.get()
Source: https://docs.cypress.io/llm/markdown/app/references/changelog.md
When `cy.get()` is used with a routing alias, it yields the last matched request by default. Special alias properties can be used to return different requests or arrays of requests.
```javascript
cy.get('@users');
```
--------------------------------
### Using `setup.js` in `main.js`
Source: https://docs.cypress.io/app/component-testing/styling-components
Shows how to import and use the `createApp` function from `setup.js` in the application's main entry point (`main.js`).
```javascript
import { createApp } from './setup.js'
ReactDOM.render(createApp())
```
--------------------------------
### Basic GitLab CI Configuration for Cypress
Source: https://docs.cypress.io/app/continuous-integration/gitlab-ci
This basic CI setup uses GitLab CI/CD to run Cypress tests in the Electron browser. It installs dependencies, starts the server, and executes end-to-end tests.
```yaml
stages:
- test
test:
image: node:latest
stage: test
script:
# install dependencies
- npm ci
# start the server in the background
- npm start &
# run Cypress tests
- npm run e2e
```
--------------------------------
### Install start-server-and-test with bun
Source: https://docs.cypress.io/app/continuous-integration/overview
Install the start-server-and-test module as a development dependency using bun.
```bash
bun add --dev start-server-and-test
```
--------------------------------
### Get Cookies After Logging In - Cypress Example
Source: https://docs.cypress.io/llm/json/chunked/api/commands/getallcookies.json
This example demonstrates how to get all cookies after a user logs in. It assumes prior steps have set up the login process.
```javascript
cy.getCookies().then((cookies) => {
// do something with the cookies
cy.log(cookies)
})
```
--------------------------------
### Get siblings of each li
Source: https://docs.cypress.io/llm/json/chunked/api/commands/siblings.json
This example demonstrates how to get all sibling elements of each 'li' element.
```javascript
cy.get('li').siblings()
```
--------------------------------
### Get Document and Perform Actions
Source: https://docs.cypress.io/llm/json/full/api/commands/document.json
Example of retrieving the document object and performing actions on it, such as getting the title.
```javascript
cy.document().then((doc) => {
// do something with doc
expect(doc.title).to.equal('Cypress.io: Kitchen Sink')
})
```
--------------------------------
### Get siblings of element with class active
Source: https://docs.cypress.io/llm/json/chunked/api/commands/siblings.json
This example shows how to get only the sibling elements that have the class 'active'.
```javascript
cy.get('li').siblings('.active')
```
--------------------------------
### Install start-server-and-test with npm
Source: https://docs.cypress.io/app/continuous-integration/overview
Install the start-server-and-test module as a development dependency using npm.
```bash
npm install start-server-and-test --save-dev
```
--------------------------------
### Get function as property
Source: https://docs.cypress.io/llm/json/chunked/api/commands/its.json
This example demonstrates how to get a function as a property using .its() and then assert its type.
```APIDOC
## Get function as property
```javascript
const fn = () => { return 42}
cy.wrap({ getNum: fn }).its('getNum').should('be.a', 'function')
```
```
--------------------------------
### Example package.json
Source: https://docs.cypress.io/llm/json/full/api/node-events/overview.json
This is an example of a package.json file that includes dependencies which can be required within the `setupNodeEvents` function.
```json
{ "name": "My Project", "dependencies": { "debug": "x.x.x" }, "devDependencies": { "lodash": "x.x.x" }}
```
--------------------------------
### Install start-server-and-test with yarn
Source: https://docs.cypress.io/app/continuous-integration/overview
Install the start-server-and-test module as a development dependency using yarn.
```bash
yarn add start-server-and-test --dev
```
--------------------------------
### Get a specific location property
Source: https://docs.cypress.io/api/commands/location
This example demonstrates how to get a specific property of the location object, such as the `pathname`.
```APIDOC
## Get a specific location property
### Description
Get a specific property of the location object by passing its key as an argument.
### Method
`cy.location(key)
### Endpoint
`cy.location(key)`
### Parameters
#### Path Parameters
- **key** (String) - Required - A key on the location object. Returns this value instead of the full location object.
### Yields
`cy.location(key)` yields the value of the location property as a string.
### Request Example
```javascript
cy.visit('http://localhost:3000/admin')
cy.location('pathname').should('eq', '/login')
```
```
--------------------------------
### Install start-server-and-test Module
Source: https://docs.cypress.io/llm/json/chunked/app/continuous-integration/overview.json
Install the `start-server-and-test` module as a development dependency for npm, yarn, pnpm, or bun.
```bash
npm install start-server-and-test --save-dev
```
```bash
yarn add start-server-and-test --dev
```
```bash
pnpm add --save-dev start-server-and-test
```
```bash
bun add --dev start-server-and-test
```
--------------------------------
### Get the location object
Source: https://docs.cypress.io/api/commands/location
This example demonstrates how to get the entire location object and make assertions about its properties.
```APIDOC
## Get the location object
### Description
Get the global `window.location` object of the page that is currently active.
### Method
`cy.location()
### Endpoint
`cy.location()`
### Yields
`cy.location()` yields the location object with the following properties: `hash`, `host`, `hostname`, `href`, `origin`, `pathname`, `port`, `protocol`, `search`, `toString`
### Request Example
```javascript
cy.visit('http://localhost:8000/app/index.html?q=dan#/users/123/edit')
cy.location().should((loc) => {
expect(loc.hash).to.eq('#/users/123/edit')
expect(loc.host).to.eq('localhost:8000')
expect(loc.hostname).to.eq('localhost')
expect(loc.href).to.eq('http://localhost:8000/app/index.html?q=dan#/users/123/edit')
expect(loc.origin).to.eq('http://localhost:8000')
expect(loc.pathname).to.eq('/app/index.html')
expect(loc.port).to.eq('8000')
expect(loc.protocol).to.eq('http:')
expect(loc.search).to.eq('?q=dan')
expect(loc.toString()).to.eq('http://localhost:8000/app/index.html?q=brian#/users/123/edit')
})
```
```
--------------------------------
### Basic Bitbucket Pipelines Setup with Cypress Docker Image
Source: https://docs.cypress.io/app/continuous-integration/bitbucket-pipelines
This configuration sets up Bitbucket Pipelines to run Cypress tests using a pre-built Cypress Docker image. It installs dependencies, starts the application server in the background, waits for the server to be ready, and then executes Cypress tests in Firefox.
```yaml
image: cypress/browsers:22.15.0
pipelines:
default:
- step:
script:
# install dependencies
- npm ci
# start the server in the background
- npm run start &
# wait for the server to respond (replace with your server's URL)
- npx wait-on http://localhost:3000
# run Cypress tests in Firefox
- npx cypress run --browser firefox
```
--------------------------------
### get Command
Source: https://docs.cypress.io/llm/json/chunked/index.json
The `get` command is used to select DOM elements. It includes syntax, arguments, yields, and examples.
```APIDOC
## get Command
### Description
This command is used to select DOM elements. It covers syntax, arguments, yields, and provides examples.
### Method
Not specified (likely a programmatic call within a testing framework)
### Endpoint
Not applicable (this appears to be an SDK/library command, not an HTTP endpoint)
### Parameters
#### Arguments
Details on arguments are provided, but specific arguments are not listed in the source text.
### Request Example
Not applicable
### Response
Not specified
```
--------------------------------
### Install start-server-and-test with pnpm
Source: https://docs.cypress.io/app/continuous-integration/overview
Install the start-server-and-test module as a development dependency using pnpm.
```bash
pnpm add --save-dev start-server-and-test
```
--------------------------------
### Basic Session Setup with Visit
Source: https://docs.cypress.io/llm/markdown/api/commands/session.md
Demonstrates a basic `cy.session()` setup where `cy.visit()` is called immediately after the session is established. This approach is suitable when the subsequent test directly follows the login process on the same page.
```javascript
const login = (name) => {
cy.session(name, () => {
cy.visit('/login')
cy.get('[data-test=name]').type(name)
cy.get('[data-test=password]').type('s3cr3t')
cy.get('#submit').click()
cy.url().should('contain', '/home')
})
cy.visit('/home')
}
beforeEach(() => {
login('user')
})
it('should test something on the /home page', () => {
// assertions
})
it('should test something else on the /home page', () => {
// assertions
})
```
--------------------------------
### cy.location(key)
Source: https://docs.cypress.io/llm/json/chunked/api/commands/location.json
Gets a specific property (key) from the location object of the window. For example, you can get the 'host' or 'port'.
```APIDOC
## cy.location(key)
### Description
Gets a specific property (key) from the location object of the window. For example, you can get the 'host' or 'port'.
### Arguments
* **key _(String)_**: A key on the location object. Returns this value instead of the full location object.
### Usage
```javascript
cy.location('host')
cy.location('port')
```
### Yields
`cy.location()` yields the value of the specified location property as a string.
```
--------------------------------
### Get the element that is focused
Source: https://docs.cypress.io/llm/json/chunked/api/commands/focused.json
This example shows how to get the currently focused element and then use `.then()` to perform an action with it.
```APIDOC
## cy.focused()
### Description
Get the element that is currently focused.
### Usage
```
cy.focused()
```
### Examples
#### Get the element that is focused
```javascript
cy.focused().then(($el) => {
// do something with $el
})
```
#### Blur the element with focus
```javascript
cy.focused().blur()
```
#### Make an assertion on the focused element
```javascript
cy.focused().should('have.attr', 'name', 'username')
```
### Rules
* `cy.focused()` requires being chained off a command that yields DOM element(s).
### Assertions
* `cy.focused()` will automatically retry until the element(s) exist in the DOM.
* `cy.focused()` will automatically retry until all chained assertions have passed.
### Timeouts
* `cy.focused()` can time out waiting for the element(s) to exist in the DOM.
* `cy.focused()` can time out waiting for assertions you've added to pass.
```
--------------------------------
### Start server and wait for it to be ready
Source: https://docs.cypress.io/llm/json/chunked/app/continuous-integration/overview.json
Start your server in the background and use wait-on to pause execution until the specified URL is available.
```bash
npm start & wait-on http://localhost:8080
```
--------------------------------
### Get the root DOM element
Source: https://docs.cypress.io/api/commands/root
This example demonstrates how to get the root DOM element, which is typically the element.
```javascript
cy.root() // Yield root element
```
--------------------------------
### Staging Configuration Example
Source: https://docs.cypress.io/api/node-events/configuration-api
Example of a `staging.json` configuration file, setting the `baseUrl` and an environment-specific variable.
```json
// cypress/config/staging.json
{
"baseUrl": "https://staging.acme.com",
"env": {
"something": "staging"
}
}
```
--------------------------------
### Install extract-cloud-results Module
Source: https://docs.cypress.io/accessibility/guides/results-api
Install the module in your CI environment's install step. Use `--force` to ensure you get the latest version. Do not check this module in as a dependency.
```bash
npm install --force https://cdn.cypress.io/extract-cloud-results/v1/extract-cloud-results.tgz
```
--------------------------------
### Centralized Setup File for Styles and App Creation
Source: https://docs.cypress.io/llm/json/chunked/app/component-testing/styling-components.json
Demonstrates a `setup.js` file that centralizes imports for CSS, fonts, and application setup logic, making it reusable for both the main application and Cypress tests.
```javascript
import '~normalize/normalize.css'
import 'font-awesome'
import './main.css'
export const createStore = () => {
return /* store */
}
export const createRouter = () => {
return /* router */
}
export const createApp = () => {
return