Add test example to scrap a web page.
This commit is contained in:
9
cypress.config.js
Normal file
9
cypress.config.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const { defineConfig } = require("cypress");
|
||||||
|
|
||||||
|
module.exports = defineConfig({
|
||||||
|
e2e: {
|
||||||
|
setupNodeEvents(on, config) {
|
||||||
|
// implement node event listeners here
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
94
cypress/e2e/sandbox.cy.js
Normal file
94
cypress/e2e/sandbox.cy.js
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
// describe('template spec', () => {
|
||||||
|
// it('passes', () => {
|
||||||
|
// cy.visit('https://example.cypress.io')
|
||||||
|
// })
|
||||||
|
// })
|
||||||
|
|
||||||
|
/*
|
||||||
|
function sum(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function minus(a, b) {
|
||||||
|
return a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resultatDeUnEtDeux = sum(1, 2);
|
||||||
|
|
||||||
|
const sum2 = (a, b) => {
|
||||||
|
console.log(a + b);
|
||||||
|
};
|
||||||
|
|
||||||
|
Un lambda s'écrit de la manière suivante :
|
||||||
|
(...) => {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
sum2(10, 20);
|
||||||
|
|
||||||
|
const x = 3;
|
||||||
|
const y = 2;
|
||||||
|
|
||||||
|
const monOperationArithmetique = sum;
|
||||||
|
|
||||||
|
const result = monOperationArithmetique(x, y);
|
||||||
|
|
||||||
|
console.log(result);
|
||||||
|
|
||||||
|
|
||||||
|
const testName = 'mon premier test';
|
||||||
|
const testCode = () => {
|
||||||
|
console.log('Ça fonctionne !');
|
||||||
|
}
|
||||||
|
it(testName, testCode);
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
class MyService(self):
|
||||||
|
def functionA(self, x):
|
||||||
|
# ...
|
||||||
|
pass
|
||||||
|
|
||||||
|
def functionB(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
describe('MyService', () => {
|
||||||
|
describe('functionA', () => {
|
||||||
|
it('should return true when user age is under 18', () => {
|
||||||
|
//...
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false when user age is lower or equals 18', () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
// describe('Le site ouest-france-immo', () => {
|
||||||
|
// it('doit se charger dans cypress', () => {
|
||||||
|
// cy.visit('https://www.ouestfrance-immo.com/louer/appartement--2-pieces/rennes-beaulieu-35-35000/?pieces');
|
||||||
|
|
||||||
|
|
||||||
|
// cy.get('.header')
|
||||||
|
// .should('exist');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// });
|
||||||
|
|
||||||
|
describe('Le site codiki.org', () => {
|
||||||
|
it('doit se charger dans cypress', () => {
|
||||||
|
cy.visit('https://codiki.org');
|
||||||
|
|
||||||
|
cy.get('.publication')
|
||||||
|
.each(($div) => {
|
||||||
|
cy.wrap($div).find('div').find('h1').invoke('text').as('h1Text');
|
||||||
|
|
||||||
|
cy.get('@h1Text').then((text) => {
|
||||||
|
//cy.log(text);
|
||||||
|
console.log(text);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal file
@@ -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"
|
||||||
|
}
|
||||||
25
cypress/support/commands.js
Normal file
25
cypress/support/commands.js
Normal file
@@ -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) => { ... })
|
||||||
17
cypress/support/e2e.js
Normal file
17
cypress/support/e2e.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// ***********************************************************
|
||||||
|
// This example support/e2e.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'
|
||||||
@@ -3,7 +3,8 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"cypress": "npx cypress open"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
Reference in New Issue
Block a user