Skip to content

Commit e672094

Browse files
Merge pull request #1 from hadis-soleymani/cypress
Cypress
2 parents 563c39a + 7654e53 commit e672094

10 files changed

Lines changed: 980 additions & 1 deletion

File tree

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//Visit store
2+
3+
describe("visit store", () => {
4+
it("visit store", function () {
5+
cy.visit("http://localhost:3000");
6+
});
7+
});
8+
9+
//check out one pruduct
10+
describe("add ,remove ,increase ,decrease, product", () => {
11+
//we have 20 product
12+
it("get all products", function () {
13+
cy.get(".product_product__8NFYa").should("have.length", 20);
14+
});
15+
16+
17+
//increase 4 product
18+
it("increase 4 product", function () {
19+
for (var i = 0; i < 4; i++) {
20+
cy.get(`[data-testid=product-button-${product_count}]`).click();
21+
cy.wait(1000);
22+
}
23+
24+
});
25+
26+
//remove product
27+
it("remove product", function () {
28+
for (var i = 0; i < 4; i++) {
29+
cy.get(`[data-testid=product-button-decrease-${product_count}]`).click();
30+
cy.wait(1000);
31+
}
32+
cy.wait(3000);
33+
});
34+
35+
// add to card multi products
36+
it("add to card multi products", function () {
37+
let product_count = random_number(10);
38+
for (var i = 0; i < product_count; i++) {
39+
cy.get(`[data-testid=product-button-${random_number(20)}]`).click();
40+
cy.wait(1000);
41+
}
42+
});
43+
44+
45+
});
46+
47+
describe("checkout", () => {
48+
49+
it("go to shop card", function () {
50+
cy.get(".navbar_container__kRWCp div a").click();
51+
cy.wait(1000);
52+
});
53+
54+
it("click checkout", function () {
55+
cy.get(".shopCard_check_out__XWR45").click();
56+
cy.wait(2000);
57+
});
58+
59+
//buy more
60+
it("buy more", function () {
61+
cy.get(".shopCard_clear_checkout_div__lKoz0 a").click();
62+
63+
});
64+
65+
});
66+
67+
//this function can create random number between 1 to max_random
68+
function random_number(max_random) {
69+
let rand = 0;
70+
rand = Math.floor(Math.random() * max_random) + 1;
71+
return rand;
72+
}
73+
74+
let product_count = random_number(20);

cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)