Skip to content

Commit

Permalink
feat(cypress): my-playground
Browse files Browse the repository at this point in the history
  • Loading branch information
seognil committed Jan 29, 2020
1 parent 6243556 commit 614bd2c
Show file tree
Hide file tree
Showing 12 changed files with 1,447 additions and 0 deletions.
1 change: 1 addition & 0 deletions testing/cypress/my-playground/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions testing/cypress/my-playground/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference types="cypress" />

describe('描述', () => {
before(() => console.log('---- Test Start! ----'));
beforeEach(() => cy.visit('https://witch.url'));
afterEach(() => cy.clearCookies());

it('测试用户交互', () => {
cy.get('#app')
.children('.intro')
.click();
cy.contains('Welcome').should('be.exist');
});

it('测试显示文本', () => {
cy.get('div').should('have.text', 'Hello');
// * 另一种风格
cy.get('div').should(($div) => {
const text = $div.text();
expect(text).to.match(/hello/i);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="cypress" />

describe('Window', () => {
beforeEach(() => cy.visit('https://fe.rualc.com/'));

it('document is in utf8 ', () => {
cy.document()
.should('have.property', 'charset')
.and('eq', 'UTF-8');
});

it('content', () => {
cy.contains('前端指南');
cy.contains('锟斤拷烫烫烫').should('not.exist');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// <reference types="cypress" />

// describe('Window', () => {
// beforeEach(() => {
// cy.visit('https://fe.rualc.com/');
// });

// it('document, utf8 ', () => {
// cy.document()
// .should('have.property', 'charset')
// .and('eq', 'UTF-8');
// });

// it('content', () => {
// cy.title().should('include', '前端指南');
// });
// });

const fnName = 'changeWorld';
const HELLO_CYPRESS = 'Hello Cypress!';

describe('Test', () => {
beforeEach(() => {
cy.visit('src/tick-vs-wait/index.html');
});

it(`has ${fnName} function`, () => {
// * from index.html
cy.window().should('have.prop', fnName);
});

it('clock + tick is super fast', () => {
cy.clock();

// @ts-ignore
cy.window().invoke(fnName);

cy.tick(2000);

cy.get('#app').should('have.text', HELLO_CYPRESS);
});

it('wait', () => {
// @ts-ignore
cy.window().invoke(fnName);

cy.wait(2000);

cy.get('#app').should('have.text', HELLO_CYPRESS);
});

it('auto retry', () => {
// @ts-ignore
cy.window().invoke(fnName);

cy.get('#app').should('have.text', HELLO_CYPRESS);
});
});
17 changes: 17 additions & 0 deletions testing/cypress/my-playground/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions testing/cypress/my-playground/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions testing/cypress/my-playground/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
12 changes: 12 additions & 0 deletions testing/cypress/my-playground/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "simple-visit",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"cypress": "cypress"
},
"devDependencies": {
"cypress": "^3.8.3"
}
}
15 changes: 15 additions & 0 deletions testing/cypress/my-playground/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Learn Cypress

## Try your self

```bash
git clone # or download

# cd _here_

npm install

npx cypress open
```

Check [Cypress Doc](https://docs.cypress.io/guides/overview/why-cypress.html)
20 changes: 20 additions & 0 deletions testing/cypress/my-playground/src/tick-vs-wait/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
</head>
<body>
<div id="app">Hello World</div>
<script>
window.changeWorld = () => {
setTimeout(() => {
console.log(document.getElementById('header'));
document.querySelector('#app').textContent = 'Hello Cypress!';
}, 2000);
};
</script>
</body>
</html>
Loading

0 comments on commit 614bd2c

Please sign in to comment.