From 67cdb74c395b52351a5b72953998009dd3cf780d Mon Sep 17 00:00:00 2001 From: 1549469775 <1549469775@qq.com> Date: Sat, 4 Sep 2021 12:04:35 +0800 Subject: [PATCH] init --- .gitignore | 1 + cypress.json | 5 + cypress/fixtures/example.json | 5 + cypress/fixtures/profile.json | 5 + cypress/fixtures/users.json | 232 ++++ cypress/integration/1-getting-started/todo.spec.js | 143 ++ .../2-advanced-examples/actions.spec.js | 299 +++++ .../2-advanced-examples/aliasing.spec.js | 39 + .../2-advanced-examples/assertions.spec.js | 177 +++ .../2-advanced-examples/connectors.spec.js | 97 ++ .../2-advanced-examples/cookies.spec.js | 77 ++ .../2-advanced-examples/cypress_api.spec.js | 202 +++ .../integration/2-advanced-examples/files.spec.js | 88 ++ .../2-advanced-examples/local_storage.spec.js | 52 + .../2-advanced-examples/location.spec.js | 32 + .../integration/2-advanced-examples/misc.spec.js | 104 ++ .../2-advanced-examples/navigation.spec.js | 56 + .../2-advanced-examples/network_requests.spec.js | 163 +++ .../2-advanced-examples/querying.spec.js | 114 ++ .../2-advanced-examples/spies_stubs_clocks.spec.js | 205 +++ .../2-advanced-examples/traversal.spec.js | 121 ++ .../2-advanced-examples/utilities.spec.js | 110 ++ .../2-advanced-examples/viewport.spec.js | 59 + .../2-advanced-examples/waiting.spec.js | 31 + .../integration/2-advanced-examples/window.spec.js | 22 + cypress/integration/home_page_spec.js | 11 + cypress/plugins/index.js | 22 + cypress/support/commands.js | 25 + cypress/support/index.js | 20 + package-lock.json | 1401 ++++++++++++++++++++ package.json | 15 + 31 files changed, 3933 insertions(+) create mode 100644 .gitignore create mode 100644 cypress.json create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/fixtures/profile.json create mode 100644 cypress/fixtures/users.json create mode 100644 cypress/integration/1-getting-started/todo.spec.js create mode 100644 cypress/integration/2-advanced-examples/actions.spec.js create mode 100644 cypress/integration/2-advanced-examples/aliasing.spec.js create mode 100644 cypress/integration/2-advanced-examples/assertions.spec.js create mode 100644 cypress/integration/2-advanced-examples/connectors.spec.js create mode 100644 cypress/integration/2-advanced-examples/cookies.spec.js create mode 100644 cypress/integration/2-advanced-examples/cypress_api.spec.js create mode 100644 cypress/integration/2-advanced-examples/files.spec.js create mode 100644 cypress/integration/2-advanced-examples/local_storage.spec.js create mode 100644 cypress/integration/2-advanced-examples/location.spec.js create mode 100644 cypress/integration/2-advanced-examples/misc.spec.js create mode 100644 cypress/integration/2-advanced-examples/navigation.spec.js create mode 100644 cypress/integration/2-advanced-examples/network_requests.spec.js create mode 100644 cypress/integration/2-advanced-examples/querying.spec.js create mode 100644 cypress/integration/2-advanced-examples/spies_stubs_clocks.spec.js create mode 100644 cypress/integration/2-advanced-examples/traversal.spec.js create mode 100644 cypress/integration/2-advanced-examples/utilities.spec.js create mode 100644 cypress/integration/2-advanced-examples/viewport.spec.js create mode 100644 cypress/integration/2-advanced-examples/waiting.spec.js create mode 100644 cypress/integration/2-advanced-examples/window.spec.js create mode 100644 cypress/integration/home_page_spec.js create mode 100644 cypress/plugins/index.js create mode 100644 cypress/support/commands.js create mode 100644 cypress/support/index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/cypress.json b/cypress.json new file mode 100644 index 0000000..d04a786 --- /dev/null +++ b/cypress.json @@ -0,0 +1,5 @@ +{ + "baseUrl": "http://localhost:8080/", + "viewportWidth": 375, + "viewportHeight": 812 +} diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 0000000..02e4254 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/fixtures/profile.json b/cypress/fixtures/profile.json new file mode 100644 index 0000000..b6c355c --- /dev/null +++ b/cypress/fixtures/profile.json @@ -0,0 +1,5 @@ +{ + "id": 8739, + "name": "Jane", + "email": "jane@example.com" +} \ No newline at end of file diff --git a/cypress/fixtures/users.json b/cypress/fixtures/users.json new file mode 100644 index 0000000..79b699a --- /dev/null +++ b/cypress/fixtures/users.json @@ -0,0 +1,232 @@ +[ + { + "id": 1, + "name": "Leanne Graham", + "username": "Bret", + "email": "Sincere@april.biz", + "address": { + "street": "Kulas Light", + "suite": "Apt. 556", + "city": "Gwenborough", + "zipcode": "92998-3874", + "geo": { + "lat": "-37.3159", + "lng": "81.1496" + } + }, + "phone": "1-770-736-8031 x56442", + "website": "hildegard.org", + "company": { + "name": "Romaguera-Crona", + "catchPhrase": "Multi-layered client-server neural-net", + "bs": "harness real-time e-markets" + } + }, + { + "id": 2, + "name": "Ervin Howell", + "username": "Antonette", + "email": "Shanna@melissa.tv", + "address": { + "street": "Victor Plains", + "suite": "Suite 879", + "city": "Wisokyburgh", + "zipcode": "90566-7771", + "geo": { + "lat": "-43.9509", + "lng": "-34.4618" + } + }, + "phone": "010-692-6593 x09125", + "website": "anastasia.net", + "company": { + "name": "Deckow-Crist", + "catchPhrase": "Proactive didactic contingency", + "bs": "synergize scalable supply-chains" + } + }, + { + "id": 3, + "name": "Clementine Bauch", + "username": "Samantha", + "email": "Nathan@yesenia.net", + "address": { + "street": "Douglas Extension", + "suite": "Suite 847", + "city": "McKenziehaven", + "zipcode": "59590-4157", + "geo": { + "lat": "-68.6102", + "lng": "-47.0653" + } + }, + "phone": "1-463-123-4447", + "website": "ramiro.info", + "company": { + "name": "Romaguera-Jacobson", + "catchPhrase": "Face to face bifurcated interface", + "bs": "e-enable strategic applications" + } + }, + { + "id": 4, + "name": "Patricia Lebsack", + "username": "Karianne", + "email": "Julianne.OConner@kory.org", + "address": { + "street": "Hoeger Mall", + "suite": "Apt. 692", + "city": "South Elvis", + "zipcode": "53919-4257", + "geo": { + "lat": "29.4572", + "lng": "-164.2990" + } + }, + "phone": "493-170-9623 x156", + "website": "kale.biz", + "company": { + "name": "Robel-Corkery", + "catchPhrase": "Multi-tiered zero tolerance productivity", + "bs": "transition cutting-edge web services" + } + }, + { + "id": 5, + "name": "Chelsey Dietrich", + "username": "Kamren", + "email": "Lucio_Hettinger@annie.ca", + "address": { + "street": "Skiles Walks", + "suite": "Suite 351", + "city": "Roscoeview", + "zipcode": "33263", + "geo": { + "lat": "-31.8129", + "lng": "62.5342" + } + }, + "phone": "(254)954-1289", + "website": "demarco.info", + "company": { + "name": "Keebler LLC", + "catchPhrase": "User-centric fault-tolerant solution", + "bs": "revolutionize end-to-end systems" + } + }, + { + "id": 6, + "name": "Mrs. Dennis Schulist", + "username": "Leopoldo_Corkery", + "email": "Karley_Dach@jasper.info", + "address": { + "street": "Norberto Crossing", + "suite": "Apt. 950", + "city": "South Christy", + "zipcode": "23505-1337", + "geo": { + "lat": "-71.4197", + "lng": "71.7478" + } + }, + "phone": "1-477-935-8478 x6430", + "website": "ola.org", + "company": { + "name": "Considine-Lockman", + "catchPhrase": "Synchronised bottom-line interface", + "bs": "e-enable innovative applications" + } + }, + { + "id": 7, + "name": "Kurtis Weissnat", + "username": "Elwyn.Skiles", + "email": "Telly.Hoeger@billy.biz", + "address": { + "street": "Rex Trail", + "suite": "Suite 280", + "city": "Howemouth", + "zipcode": "58804-1099", + "geo": { + "lat": "24.8918", + "lng": "21.8984" + } + }, + "phone": "210.067.6132", + "website": "elvis.io", + "company": { + "name": "Johns Group", + "catchPhrase": "Configurable multimedia task-force", + "bs": "generate enterprise e-tailers" + } + }, + { + "id": 8, + "name": "Nicholas Runolfsdottir V", + "username": "Maxime_Nienow", + "email": "Sherwood@rosamond.me", + "address": { + "street": "Ellsworth Summit", + "suite": "Suite 729", + "city": "Aliyaview", + "zipcode": "45169", + "geo": { + "lat": "-14.3990", + "lng": "-120.7677" + } + }, + "phone": "586.493.6943 x140", + "website": "jacynthe.com", + "company": { + "name": "Abernathy Group", + "catchPhrase": "Implemented secondary concept", + "bs": "e-enable extensible e-tailers" + } + }, + { + "id": 9, + "name": "Glenna Reichert", + "username": "Delphine", + "email": "Chaim_McDermott@dana.io", + "address": { + "street": "Dayna Park", + "suite": "Suite 449", + "city": "Bartholomebury", + "zipcode": "76495-3109", + "geo": { + "lat": "24.6463", + "lng": "-168.8889" + } + }, + "phone": "(775)976-6794 x41206", + "website": "conrad.com", + "company": { + "name": "Yost and Sons", + "catchPhrase": "Switchable contextually-based project", + "bs": "aggregate real-time technologies" + } + }, + { + "id": 10, + "name": "Clementina DuBuque", + "username": "Moriah.Stanton", + "email": "Rey.Padberg@karina.biz", + "address": { + "street": "Kattie Turnpike", + "suite": "Suite 198", + "city": "Lebsackbury", + "zipcode": "31428-2261", + "geo": { + "lat": "-38.2386", + "lng": "57.2232" + } + }, + "phone": "024-648-3804", + "website": "ambrose.net", + "company": { + "name": "Hoeger LLC", + "catchPhrase": "Centralized empowering task-force", + "bs": "target end-to-end models" + } + } +] \ No newline at end of file diff --git a/cypress/integration/1-getting-started/todo.spec.js b/cypress/integration/1-getting-started/todo.spec.js new file mode 100644 index 0000000..4768ff9 --- /dev/null +++ b/cypress/integration/1-getting-started/todo.spec.js @@ -0,0 +1,143 @@ +/// + +// Welcome to Cypress! +// +// This spec file contains a variety of sample tests +// for a todo list app that are designed to demonstrate +// the power of writing tests in Cypress. +// +// To learn more about how Cypress works and +// what makes it such an awesome testing tool, +// please read our getting started guide: +// https://on.cypress.io/introduction-to-cypress + +describe('example to-do app', () => { + beforeEach(() => { + // Cypress starts out with a blank slate for each test + // so we must tell it to visit our website with the `cy.visit()` command. + // Since we want to visit the same URL at the start of all our tests, + // we include it in our beforeEach function so that it runs before each test + cy.visit('https://example.cypress.io/todo') + }) + + it('displays two todo items by default', () => { + // We use the `cy.get()` command to get all elements that match the selector. + // Then, we use `should` to assert that there are two matched items, + // which are the two default items. + cy.get('.todo-list li').should('have.length', 2) + + // We can go even further and check that the default todos each contain + // the correct text. We use the `first` and `last` functions + // to get just the first and last matched elements individually, + // and then perform an assertion with `should`. + cy.get('.todo-list li').first().should('have.text', 'Pay electric bill') + cy.get('.todo-list li').last().should('have.text', 'Walk the dog') + }) + + it('can add new todo items', () => { + // We'll store our item text in a variable so we can reuse it + const newItem = 'Feed the cat' + + // Let's get the input element and use the `type` command to + // input our new list item. After typing the content of our item, + // we need to type the enter key as well in order to submit the input. + // This input has a data-test attribute so we'll use that to select the + // element in accordance with best practices: + // https://on.cypress.io/selecting-elements + cy.get('[data-test=new-todo]').type(`${newItem}{enter}`) + + // Now that we've typed our new item, let's check that it actually was added to the list. + // Since it's the newest item, it should exist as the last element in the list. + // In addition, with the two default items, we should have a total of 3 elements in the list. + // Since assertions yield the element that was asserted on, + // we can chain both of these assertions together into a single statement. + cy.get('.todo-list li') + .should('have.length', 3) + .last() + .should('have.text', newItem) + }) + + it('can check off an item as completed', () => { + // In addition to using the `get` command to get an element by selector, + // we can also use the `contains` command to get an element by its contents. + // However, this will yield the