@@ -2,6 +2,17 @@ import { launchStudio, loadProjectAndRunSpec, assertClosingPanelWithoutChanges }
22
33const urlPrompt = '// Visit a page by entering a url in the address bar or typing a cy.visit command here'
44
5+ const inputNewTestName = ( name : string = 'new-test' ) => {
6+ cy . findByTestId ( 'new-test-button' ) . click ( )
7+ cy . findByTestId ( 'test-name-input' ) . type ( name )
8+ cy . findByTestId ( 'create-test-button' ) . click ( )
9+
10+ // verify recording is enabled to ensure the panel is fully ready
11+ cy . findByTestId ( 'record-button-recording' ) . should ( 'have.text' , 'Recording...' )
12+
13+ cy . get ( '.studio-single-test-container' ) . should ( 'be.visible' )
14+ }
15+
516describe ( 'Cypress Studio' , ( ) => {
617 function incrementCounter ( initialCount : number ) {
718 cy . getAutIframe ( ) . within ( ( ) => {
@@ -165,7 +176,7 @@ describe('studio functionality', () => {
165176 } )
166177
167178 it ( 'does not enter single test mode when creating a new test' , ( ) => {
168- launchStudio ( { specName : 'spec-w-multiple-tests.cy.js' , createNewTest : true } )
179+ launchStudio ( { specName : 'spec-w-multiple-tests.cy.js' , createNewTestFromSuite : true } )
169180
170181 // verify we are not in single test mode
171182 cy . get ( '.runnable-title' ) . should ( 'have.length' , 4 )
@@ -175,26 +186,22 @@ describe('studio functionality', () => {
175186 cy . get ( '.runnable-title' ) . its ( 3 ) . should ( 'contain.text' , 'visits a basic html page 3' )
176187 } )
177188
178- it ( 'creates a new test from an empty spec with url already defined ' , ( ) => {
179- launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTest : true } )
189+ it ( 'creates a new test from spec header ' , ( ) => {
190+ launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSpecHeader : true } )
180191
181- cy . findByTestId ( 'new-test-button' ) . click ( )
182- cy . findByTestId ( 'test-name-input' ) . type ( 'new-test' )
183- cy . findByTestId ( 'create-test-button' ) . click ( )
192+ inputNewTestName ( )
184193
185194 cy . contains ( 'new-test' ) . click ( )
186195
187- // verify recording is enabled to ensure the panel is fully ready
188- cy . findByTestId ( 'record-button-recording' ) . should ( 'have.text' , 'Recording...' )
189-
190- cy . get ( '.studio-single-test-container' ) . should ( 'be.visible' )
191-
192196 cy . percySnapshot ( )
193197
194- incrementCounter ( 0 )
198+ cy . get ( '.cm-content' ) . invoke ( 'text' , 'cy.visit("cypress/e2e/index.html")' )
195199
196200 cy . findByTestId ( 'studio-save-button' ) . click ( )
197201
202+ // verify recording is enabled to ensure the panel is fully ready
203+ cy . findByTestId ( 'record-button-recording' ) . should ( 'have.text' , 'Recording...' )
204+
198205 // we should have the commands we executed after we save
199206 cy . withCtx ( async ( ctx ) => {
200207 const spec = await ctx . actions . file . readFileInProject ( 'cypress/e2e/spec-w-visit.cy.js' )
@@ -208,19 +215,18 @@ describe('studio functionality', () => {
208215 it('visits a basic html page', () => {
209216 cy.get('h1').should('have.text', 'Hello, Studio!')
210217 })
218+ })
211219
212- it('new-test', function() {
213-
214- cy.get('#increment').click();
215- });
216- })` . trim ( ) )
220+ it('new-test', function() {
221+ cy.visit("cypress/e2e/index.html")
222+ });` . trim ( ) )
217223 } )
218224 } )
219225
220226 // TODO: this test fails in CI but passes locally
221227 // http://github.com/cypress-io/cypress/issues/31248
222228 it . skip ( 'creates a new test with a url that changes top' , function ( ) {
223- launchStudio ( { specName : 'spec-w-foobar.cy.js' , createNewTest : true } )
229+ launchStudio ( { specName : 'spec-w-foobar.cy.js' , createNewTestFromSuite : true } )
224230
225231 cy . origin ( 'http://foobar.com:4455' , ( ) => {
226232 Cypress . require ( '../support/execute-spec' )
@@ -294,21 +300,12 @@ describe('studio functionality', () => {
294300 } )
295301
296302 it ( 'creates a new test for a specific suite with the url already defined' , ( ) => {
297- launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTest : true } )
303+ launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSuite : true } )
298304
299305 // create a new test from a specific suite
300- cy . findByTestId ( 'create-new-test-button' ) . click ( )
301-
302- cy . findByTestId ( 'new-test-button' ) . click ( )
303- cy . findByTestId ( 'test-name-input' ) . type ( 'new-test' )
304- cy . findByTestId ( 'create-test-button' ) . click ( )
306+ cy . findByTestId ( 'create-new-test-from-suite' ) . click ( )
305307
306- cy . contains ( 'new-test' ) . click ( )
307-
308- // verify recording is enabled to ensure the panel is fully ready
309- cy . findByTestId ( 'record-button-recording' ) . should ( 'have.text' , 'Recording...' )
310-
311- cy . get ( '.studio-single-test-container' ) . should ( 'be.visible' )
308+ inputNewTestName ( )
312309
313310 cy . percySnapshot ( )
314311
@@ -618,11 +615,9 @@ describe('studio functionality', () => {
618615 } )
619616
620617 it ( 'updates the AUT url when creating a new test' , ( ) => {
621- launchStudio ( { specName : 'navigation.cy.js' , createNewTest : true } )
618+ launchStudio ( { specName : 'navigation.cy.js' , createNewTestFromSuite : true } )
622619
623- cy . findByTestId ( 'new-test-button' ) . click ( )
624- cy . findByTestId ( 'test-name-input' ) . type ( 'new-test' )
625- cy . findByTestId ( 'create-test-button' ) . click ( )
620+ inputNewTestName ( )
626621
627622 cy . findByTestId ( 'aut-url-input' ) . should ( 'have.focus' ) . type ( 'cypress/e2e/navigation.html{enter}' )
628623
@@ -650,7 +645,7 @@ describe('studio functionality', () => {
650645 } )
651646
652647 it ( 'update the url with the suiteId and studio parameters when entering studio with a suite' , ( ) => {
653- launchStudio ( { createNewTest : true } )
648+ launchStudio ( { createNewTestFromSuite : true } )
654649
655650 cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r2' ) . and ( 'contain' , 'studio=' )
656651 } )
@@ -663,9 +658,7 @@ describe('studio functionality', () => {
663658 cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r1' ) . and ( 'contain' , 'studio=' )
664659
665660 // create a new test in the root suite
666- cy . findByTestId ( 'new-test-button' ) . click ( )
667- cy . findByTestId ( 'test-name-input' ) . type ( 'new-test' )
668- cy . findByTestId ( 'create-test-button' ) . click ( )
661+ inputNewTestName ( )
669662
670663 // the studio url parameters should be removed
671664 cy . location ( ) . its ( 'hash' ) . and ( 'not.contain' , 'suiteId=' ) . and ( 'contain' , 'studio=' ) . and ( 'contain' , 'testId=r2' )
@@ -745,7 +738,7 @@ describe('studio functionality', () => {
745738 } )
746739
747740 it ( 'removes the studio url parameters when closing studio new test' , ( ) => {
748- launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTest : true } )
741+ launchStudio ( { specName : 'spec-w-visit.cy.js' , createNewTestFromSuite : true } )
749742
750743 cy . location ( ) . its ( 'hash' ) . should ( 'contain' , 'suiteId=r2' ) . and ( 'contain' , 'studio=' )
751744
0 commit comments