From b679c6237547b6fe187c1e53b04d05b2665862c2 Mon Sep 17 00:00:00 2001 From: tzanmix <tzanmix@gmail.com> Date: Thu, 6 Feb 2025 14:10:20 +0200 Subject: [PATCH] group-by-custom-commands --- cypress.config.ts | 7 ++- cypress/e2e/user-journeys.cy.ts | 97 +++++++++++---------------------- cypress/support/commands.ts | 89 ++++++++++++++++++++++++++---- 3 files changed, 118 insertions(+), 75 deletions(-) diff --git a/cypress.config.ts b/cypress.config.ts index 078d58e..e5f31b4 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -1,11 +1,16 @@ +import { inject } from "@angular/core"; import { defineConfig } from "cypress"; +import { AppService } from "src/app/shared/services/app.service"; + +//let appConfig = inject(AppService); export default defineConfig({ + + e2e: { setupNodeEvents(on, config) { // implement node event listeners here }, baseUrl: "http://localhost:4200/", - pageLoadTimeout: 80000 }, }); diff --git a/cypress/e2e/user-journeys.cy.ts b/cypress/e2e/user-journeys.cy.ts index d939eb5..35721fd 100644 --- a/cypress/e2e/user-journeys.cy.ts +++ b/cypress/e2e/user-journeys.cy.ts @@ -6,80 +6,49 @@ describe('user journey', () => { cy.visit(baseUrl); }) - context.skip('user-not-logged-in', () => { + context('user-not-logged-in', () => { it('checks services portal', () => { - cy.get(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn').click(); - //cy.get(':nth-child(1) > .nav-link').click() - cy.location("pathname").should("equal", "/services"); - cy.get('.btn').should("contain", "Sign In"); - cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist"); - - //service marketplace button should exist and should redirect to /services_marketplace - cy.get('.mr-auto > .nav-item > .nav-link').click(); - cy.get('.jumbotron > h5.ng-tns-c147-1').should("contain", "Browse available services and sign in to order"); - cy.get('.catalog-tree-header').should("exist"); - - //sign in button should exist - cy.get(':nth-child(2) > .nav-item > .nav-link').click(); - - //sign in button should redirect to auth form - cy.origin('http://portal.openslice.eu', () => { - cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); - - }); - + cy.navigateToServices(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn'); + }); + it('checks services portal via image', () => { + cy.navigateToServices(':nth-child(2) > .container > .row > .text-left'); + }); + it('checks services portal via anchor', () => { + cy.navigateToServices(':nth-child(1) > .nav-link'); }); + it('checks resources portal', () => { - cy.get(':nth-child(3) > .container > .row > .order-md-1 > a > .btn').click(); //cy.get(':nth-child(2) > .nav-link').click(); - cy.location("pathname").should("equal", "/resources"); - //sign in button should exist - cy.get('.btn').should('exist').click(); - //cy.get('nav-link').should('exist').click(); - - //sign in button should redirect to auth form - cy.origin('http://portal.openslice.eu', () => { - cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); - - }); + cy.navigateToResources(':nth-child(3) > .container > .row > .order-md-1 > a > .btn'); }); - it('checks testing portal', () => { - cy.get(':nth-child(5) > .container > .row > .order-md-1 > a > .btn').click(); - //cy.get(':nth-child(2) > .nav-link').click(); - cy.location("pathname").should("equal", "/testing"); - //sign in button should exist - cy.get('.btn').should('exist').click(); - //cy.get('nav-link').should('exist').click(); - - //sign in button should redirect to auth form - cy.origin('http://portal.openslice.eu', () => { - cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); - - }); + it('checks resources portal via image', () => { + cy.navigateToResources(':nth-child(3) > .container > .row > .order-md-2 > a > .img-fluid'); + }) + it('checks resources portal via anchor', () => { + cy.navigateToResources(':nth-child(2) > .nav-link'); }); - it('checks products portal', () => { - cy.get(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn').click(); - //cy.get(':nth-child(1) > .nav-link').click() - cy.location("pathname").should("equal", "/products"); - cy.get('.btn').should("contain", "Sign In"); - cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist"); - //marketplace button should exist and should redirect to products/marketplace - cy.get('.mr-auto > .nav-item > .nav-link').click(); - cy.get('.catalog-tree-header').should("exist"); - cy.get('.mb-0').should("contain", "Product Catalog Explorer"); - - //sign in button should exist - cy.get(':nth-child(2) > .nav-item > .nav-link').click(); - - //sign in button should redirect to auth form - cy.origin('http://portal.openslice.eu', () => { - cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); + it('checks testing portal', () => { + cy.navigateToTesting(':nth-child(5) > .container > .row > .order-md-1 > a > .btn'); + }); + it('checks testing via image', () => { + cy.navigateToTesting(':nth-child(5) > .container > .row > .order-md-2 > a > .img-fluid'); + }) + it('checks testing portal via anchor', () => { + cy.navigateToTesting(':nth-child(4) > .nav-link') + }); - }); + it('checks products portal', () => { + cy.navigateToProducts(':nth-child(6) > .container > .row > :nth-child(2) > a > .btn'); }); + it('checks products portal via image', () => { + cy.navigateToProducts(':nth-child(6) > .container > .row > .text-left > a > .img-fluid'); + }) + it('checks products portal via anchor', () => { + cy.navigateToProducts(':nth-child(5) > .nav-link'); + }) }); - context('<who we are> links', () => { + context.only('<who we are> links', () => { it('checks ETSI SDG OpenSlice Link', () => { cy.get('.ng-star-inserted > :nth-child(1) > .text-white').click(); cy.origin('https://osl.etsi.org/', () => { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 698b01a..96d68ef 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -25,13 +25,82 @@ // -- This will overwrite an existing command -- // Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) // -// declare global { -// namespace Cypress { -// interface Chainable { -// login(email: string, password: string): Chainable<void> -// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element> -// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element> -// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element> -// } -// } -// } \ No newline at end of file +declare namespace Cypress { + +interface Chainable { + navigateToServices(selector): Chainable<any>, + navigateToResources(selector): Chainable<any>, + navigateToTesting(selector): Chainable<any>, + navigateToProducts(selector): Chainable<any> + } +} + +Cypress.Commands.add('navigateToServices', (selector) => { + cy.get(selector).click(); + cy.location("pathname").should("equal", "/services"); + cy.get('.btn').should("contain", "Sign In"); + cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist"); + + //service marketplace button should exist and should redirect to /services_marketplace + cy.get('.mr-auto > .nav-item > .nav-link').click(); + cy.get('.jumbotron > h5.ng-tns-c147-1').should("contain", "Browse available services and sign in to order"); + cy.get('.catalog-tree-header').should("exist"); + + //sign in button should exist + cy.get(':nth-child(2) > .nav-item > .nav-link').click(); + + //sign in button should redirect to auth form + cy.origin('http://portal.openslice.eu', () => { + cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); + + }); +}); + +Cypress.Commands.add('navigateToResources', (selector) => { + cy.get(selector).click(); + cy.location("pathname").should("equal", "/resources"); + //sign in button should exist + cy.get('.btn').should('exist').click(); + //cy.get('nav-link').should('exist').click(); + + //sign in button should redirect to auth form + cy.origin('http://portal.openslice.eu', () => { + cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); + + }); +}) + +Cypress.Commands.add('navigateToTesting', (selector) => { + cy.get(selector).click(); + cy.location("pathname").should("equal", "/testing"); + //sign in button should exist + cy.get('.btn').should('exist').click(); + //cy.get('nav-link').should('exist').click(); + + //sign in button should redirect to auth form + cy.origin('http://portal.openslice.eu', () => { + cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); + + }); +}); + +Cypress.Commands.add('navigateToProducts', (selector) => { + cy.get(selector).click(); + cy.location("pathname").should("equal", "/products"); + cy.get('.btn').should("contain", "Sign In"); + cy.get(':nth-child(2) > .nav-item > .nav-link').should("exist"); + + //marketplace button should exist and should redirect to products/marketplace + cy.get('.mr-auto > .nav-item > .nav-link').click(); + cy.get('.catalog-tree-header').should("exist"); + cy.get('.mb-0').should("contain", "Product Catalog Explorer"); + + //sign in button should exist + cy.get(':nth-child(2) > .nav-item > .nav-link').click(); + + //sign in button should redirect to auth form + cy.origin('http://portal.openslice.eu', () => { + cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth"); + + }); +}) \ No newline at end of file -- GitLab