Skip to content

Commit 2d10c5d

Browse files
authored
Merge branch 'develop' into electron-34
2 parents a84b9c9 + 53f7aae commit 2d10c5d

24 files changed

+772
-200
lines changed

cli/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ _Released 5/6/2025 (PENDING)_
1010
**Bugfixes:**
1111

1212
- Fixed an issue where the configuration setting `trashAssetsBeforeRuns=false` was ignored for assets in the `videosFolder`. These assets were incorrectly deleted before running tests with `cypress run`. Addresses [#8280](https://github.com/cypress-io/cypress/issues/8280).
13+
- Fixed a potential hang condition when navigating to `about:blank`. Addressed in [#31634](https://github.com/cypress-io/cypress/pull/31634).
1314

1415
**Misc:**
1516

17+
- The Assertions menu when you right click in `experimentalStudio` tests now displays in dark mode. Addresses [#10621](https://github.com/cypress-io/cypress-services/issues/10621). Addressed in [#31598](https://github.com/cypress-io/cypress/pull/31598).
1618
- The URL in the Cypress App no longer displays a white background when the URL is loading. Fixes [#31556](https://github.com/cypress-io/cypress/issues/31556).
1719

1820
**Dependency Updates:**

guides/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ For general contributor information, check out [`CONTRIBUTING.md`](../CONTRIBUTI
1919
* [Error handling](./error-handling.md)
2020
* [GraphQL Subscriptions - Overview and Test Guide](./graphql-subscriptions.md)
2121
* [Patching packages](./patch-package.md)
22+
* [Protocol development](./protocol-development.md)
2223
* [Release process](./release-process.md)
24+
* [Studio development](./studio-development.md)
2325
* [Testing other projects](./testing-other-projects.md)
2426
* [Testing strategy and style guide (draft)](./testing-strategy-and-styleguide.md)
2527
* [Writing cross-platform JavaScript](./writing-cross-platform-javascript.md)

guides/studio-development.md

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
# Studio Development
22

3-
In production, the code used to facilitate Studio functionality will be retrieved from the Cloud. While Studio is still in its early stages it is hidden behind an environment variable: `CYPRESS_ENABLE_CLOUD_STUDIO`. Set this environment variable to `true` if you want to run Cypress against the deployed version of studio code:
3+
In production, the code used to facilitate Studio functionality will be retrieved from the Cloud. While Studio is still in its early stages it is hidden behind an environment variable: `CYPRESS_ENABLE_CLOUD_STUDIO` but can also be run against local cloud Studio code via the environment variable: `CYPRESS_LOCAL_STUDIO_PATH`.
44

5-
```sh
6-
CYPRESS_ENABLE_CLOUD_STUDIO=true yarn cypress:open
7-
```
8-
9-
If you want to run against locally developed Studio code:
5+
To run against locally developed Studio:
106

117
- Clone the `cypress-services` repo (this requires that you be a member of the Cypress organization)
128
- Run `yarn`
13-
- Run `yarn watch` in `app/studio`
14-
- Set `CYPRESS_LOCAL_STUDIO_PATH` to the path to the `cypress-services/app/studio/dist/development` directory
9+
- Run `yarn watch` in `app/packages/studio`
10+
- Set:
11+
- `CYPRESS_INTERNAL_ENV=<environment>` (e.g. `staging` or `production` if you want to hit those deployments of `cypress-services` or `development` if you want to hit a locally running version of `cypress-services`)
12+
- `CYPRESS_LOCAL_STUDIO_PATH` to the path to the `cypress-services/app/packages/studio/dist/development` directory
13+
14+
To run against a deployed version of studio:
15+
16+
- Set:
17+
- `CYPRESS_INTERNAL_ENV=<environment>` (e.g. `staging` or `production` if you want to hit those deployments of `cypress-services` or `development` if you want to hit a locally running version of `cypress-services`)
18+
- `CYPRESS_ENABLE_CLOUD_STUDIO=true`
19+
20+
Regardless of running against local or deployed studio:
21+
1522
- Clone the `cypress` repo
1623
- Run `yarn`
1724
- Run `yarn cypress:open`
18-
19-
Note: When using the `CYPRESS_LOCAL_STUDIO_PATH` environment variable, we bypass our error reporting and instead throw the exception immediately. The purpose of this is to try and surface issues immediately during local development.
25+
- Log In to the Cloud via the App
26+
- Ensure the project has been setup in the `Cypress (staging)` if in staging environment or `Cypress Internal Org` if in production environment and has a `projectId` that represents that. If developing against locally running `cypress-services`, ensure that the project has the feature `studio-ai` enabled for it.
27+
- Open a project that has `experimentalStudio: true` set in the `e2e` config of the `cypress.config.js|ts` file.
28+
- Click to 'Add Commands to Test' after hovering over a test command.
29+
30+
Note: When using the `CYPRESS_LOCAL_STUDIO_PATH` environment variable or when running the Cypress app via the locally cloned repository, we bypass our error reporting and instead log errors to the browser or node console.
2031

2132
## Types
2233

@@ -31,3 +42,59 @@ or to reference a local `cypress_services` repo:
3142
```sh
3243
CYPRESS_LOCAL_STUDIO_PATH=<path-to-cypress-services/app/studio/dist/development-directory> yarn gulp downloadStudioTypes
3344
```
45+
46+
## Testing
47+
48+
### Unit/Component Testing
49+
50+
The code that supports cloud Studio and lives in the `cypress` monorepo is unit and component tested in a similar fashion to the rest of the code in the repo. See the [contributing guide](https://github.com/cypress-io/cypress/blob/ad353fcc0f7fdc51b8e624a2a1ef4e76ef9400a0/CONTRIBUTING.md?plain=1#L366) for more specifics.
51+
52+
The code that supports cloud Studio and lives in the `cypress-services` monorepo has unit and component tests that live alongside the code in that monorepo.
53+
54+
### Cypress in Cypress Testing
55+
56+
Several helpers are provided to facilitate testing cloud Studio using Cypress in Cypress tests. The [helper file](https://github.com/cypress-io/cypress/blob/ad353fcc0f7fdc51b8e624a2a1ef4e76ef9400a0/packages/app/cypress/e2e/studio/helper.ts) provides a method, `launchStudio` that:
57+
58+
1. Loads a project (by default [`experimental-studio`](https://github.com/cypress-io/cypress/tree/develop/system-tests/projects/experimental-studio)).
59+
2. Navigates to the appropriate spec (by default `specName.cy.js`).
60+
3. Enters Studio either by creating a new test or entering from an existing test via the `createNewTest` parameter
61+
4. Waits for the test to finish executing again in Studio mode.
62+
63+
The above steps actually download the studio code from the cloud and use it for the test. Note that `experimental-studio` is set up to be a `canary` project so it will always get the latest and greatest of the cloud Studio code, whether or not it has been fully promoted to production. Note that this means that if you are writing Cypress in Cypress tests that depend on new functionality delivered from the cloud, the Cypress in Cypress tests cannot be merged until the code lands and is built in the cloud. Local development is still possible however by setting `process.env.CYPRESS_LOCAL_STUDIO_PATH` to your local studio path where we enable studio [here](https://github.com/cypress-io/cypress/blob/develop/packages/frontend-shared/cypress/e2e/e2ePluginSetup.ts#L424).
64+
65+
In order to properly engage with Studio AI, we choose to simulate the cloud interactions that enable it via something like:
66+
67+
```js
68+
cy.mockNodeCloudRequest({
69+
url: '/studio/testgen/n69px6/enabled',
70+
method: 'get',
71+
body: { enabled: true },
72+
})
73+
```
74+
75+
To ensure that we get the same results from our Studio AI calls every time, we simulate them via something like:
76+
77+
```js
78+
const aiOutput = 'cy.get(\'button\').should(\'have.text\', \'Increment\')'
79+
cy.mockNodeCloudStreamingRequest({
80+
url: '/studio/testgen/n69px6/generate',
81+
method: 'post',
82+
body: { recommendations: [{ content: aiOutput }] },
83+
})
84+
```
85+
86+
The above two helpers actually mock out the Node requests so we still test the interface between the browser and node with these tests.
87+
88+
Also, since protocol does not work properly on the inner Cypress of Cypress in Cypress tests, we choose to create a dummy protocol which means we need to provide a simulated CDP full snapshot that will be sent to AI via something like:
89+
90+
```js
91+
cy.mockStudioFullSnapshot({
92+
id: 1,
93+
nodeType: 1,
94+
nodeName: 'div',
95+
localName: 'div',
96+
nodeValue: 'div',
97+
children: [],
98+
shadowRoots: [],
99+
})
100+
```

packages/app/cypress/e2e/studio/studio.cy.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,74 @@ describe('studio functionality', () => {
167167

168168
cy.percySnapshot()
169169
})
170+
171+
it('opens a cloud studio session with AI enabled', () => {
172+
cy.mockNodeCloudRequest({
173+
url: '/studio/testgen/n69px6/enabled',
174+
method: 'get',
175+
body: { enabled: true },
176+
})
177+
178+
const aiOutput = 'cy.get(\'button\').should(\'have.text\', \'Increment\')'
179+
180+
cy.mockNodeCloudStreamingRequest({
181+
url: '/studio/testgen/n69px6/generate',
182+
method: 'post',
183+
body: { recommendations: [{ content: aiOutput }] },
184+
})
185+
186+
cy.mockStudioFullSnapshot({
187+
id: 1,
188+
nodeType: 1,
189+
nodeName: 'div',
190+
localName: 'div',
191+
nodeValue: 'div',
192+
children: [],
193+
shadowRoots: [],
194+
})
195+
196+
const deferred = pDefer()
197+
198+
loadProjectAndRunSpec({ enableCloudStudio: true })
199+
200+
cy.findByTestId('studio-panel').should('not.exist')
201+
202+
cy.intercept('/cypress/e2e/index.html', () => {
203+
// wait for the promise to resolve before responding
204+
// this will ensure the studio panel is loaded before the test finishes
205+
return deferred.promise
206+
}).as('indexHtml')
207+
208+
cy.contains('visits a basic html page')
209+
.closest('.runnable-wrapper')
210+
.findByTestId('launch-studio')
211+
.click()
212+
213+
// regular studio is not loaded until after the test finishes
214+
cy.get('[data-cy="hook-name-studio commands"]').should('not.exist')
215+
// cloud studio is loaded immediately
216+
cy.findByTestId('studio-panel').then(() => {
217+
// check for the loading panel from the app first
218+
cy.get('[data-cy="loading-studio-panel"]').should('be.visible')
219+
// we've verified the studio panel is loaded, now resolve the promise so the test can finish
220+
deferred.resolve()
221+
})
222+
223+
cy.wait('@indexHtml')
224+
225+
// Studio re-executes spec before waiting for commands - wait for the spec to finish executing.
226+
cy.waitForSpecToFinish()
227+
228+
// Verify the studio panel is still open
229+
cy.findByTestId('studio-panel')
230+
cy.get('[data-cy="hook-name-studio commands"]')
231+
232+
// Verify that AI is enabled
233+
cy.get('[data-cy="ai-status-text"]').should('contain.text', 'Enabled')
234+
235+
// Verify that the AI output is correct
236+
cy.get('[data-cy="studio-ai-output-textarea"]').should('contain.text', aiOutput)
237+
})
170238
})
171239

172240
it('updates an existing test with an action', () => {

packages/app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"devDependencies": {
2525
"@cypress-design/icon-registry": "^1.5.1",
2626
"@cypress-design/vue-button": "^1.6.0",
27-
"@cypress-design/vue-icon": "^1.6.0",
27+
"@cypress-design/vue-icon": "^1.18.0",
2828
"@cypress-design/vue-spinner": "^1.0.0",
2929
"@cypress-design/vue-statusicon": "^1.0.0",
3030
"@cypress-design/vue-tabs": "^1.2.2",

packages/app/src/runner/aut-iframe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ export class AutIframe {
129129
return
130130
}
131131

132-
this.$iframe[0].src = 'about:blank'
133-
134132
this.$iframe.one('load', () => {
135133
if (testIsolation) {
136134
this._showTestIsolationBlankPage()
@@ -140,6 +138,8 @@ export class AutIframe {
140138

141139
resolve()
142140
})
141+
142+
this.$iframe[0].src = 'about:blank'
143143
})
144144
}
145145

packages/app/src/runner/dom.cy.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { getOrCreateHelperDom } from './dom'
2+
3+
describe('dom utilities', () => {
4+
describe('getOrCreateHelperDom', () => {
5+
let body: HTMLBodyElement
6+
const className = 'test-helper'
7+
const css = 'test-css'
8+
9+
beforeEach(() => {
10+
// Create a fresh body element for each test
11+
body = document.createElement('body')
12+
document.body = body
13+
})
14+
15+
afterEach(() => {
16+
// Clean up after each test
17+
const containers = body.querySelectorAll(`.${className}`)
18+
19+
containers.forEach((container) => container.remove())
20+
})
21+
22+
it('should create new helper DOM elements when none exist', () => {
23+
const result = getOrCreateHelperDom({ body, className, css })
24+
25+
// Verify container was created
26+
expect(result.container).to.exist
27+
expect(result.container.classList.contains(className)).to.be.true
28+
expect(result.container.style.all).to.equal('initial')
29+
expect(result.container.style.position).to.equal('static')
30+
31+
// Verify shadow root was created
32+
expect(result.shadowRoot).to.exist
33+
expect(result.shadowRoot!.mode).to.equal('open')
34+
35+
// Verify vue container was created
36+
expect(result.vueContainer).to.exist
37+
expect(result.vueContainer.classList.contains('vue-container')).to.be.true
38+
39+
// Verify style was added
40+
const style = result.shadowRoot!.querySelector('style')
41+
42+
expect(style).to.exist
43+
expect(style!.innerHTML).to.equal(css)
44+
})
45+
46+
it('should return existing helper DOM elements when they exist', () => {
47+
// First call to create elements
48+
const firstResult = getOrCreateHelperDom({ body, className, css })
49+
50+
// Second call to get existing elements
51+
const secondResult = getOrCreateHelperDom({ body, className, css })
52+
53+
// Verify we got the same elements back
54+
expect(secondResult.container).to.equal(firstResult.container)
55+
expect(secondResult.vueContainer).to.equal(firstResult.vueContainer)
56+
})
57+
})
58+
})

packages/app/src/runner/dom.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export function getOrCreateHelperDom ({ body, className, css }) {
3030

3131
container.classList.add(className)
3232

33+
// NOTE: This is needed to prevent the container from inheriting styles from the body of the AUT
34+
container.style.all = 'initial'
3335
container.style.position = 'static'
3436

3537
body.appendChild(container)

0 commit comments

Comments
 (0)