Commit cb3a0e4f authored by Michail Tzanatos's avatar Michail Tzanatos
Browse files

removed hardcoded routes

parent 24648816
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ yarn-error.log
testem.log
/typings
.env
cypress/fixtures
cypress/screenshots

# System Files
.DS_Store
+7 −2
Original line number Diff line number Diff line
import { defineConfig } from "cypress";
import * as dotenv from "dotenv";

dotenv.config();
dotenv.config( { path: 'cypress/.env'});

export default defineConfig({
  
@@ -20,7 +20,12 @@ export default defineConfig({
    viewportHeight: 900,
    env: {
      username: process.env.CYPRESS_username,
      password: process.env.CYPRESS_password
      password: process.env.CYPRESS_password,
      authURL: process.env.CYPRESS_AUTH_URL,
      authRealm: process.env.CYPRESS_AUTH_REALM,
      resetCredentials: process.env.CYPRESS_RESET_CREDENTIALS,
      registration: process.env.CYPRESS_REGISTRATION

      
    }
  },

cypress/default.env

0 → 100644
+7 −0
Original line number Diff line number Diff line
CYPRESS_username=admin
CYPRESS_password=openslice
CYPRESS_BASE_URL=http://localhost:4200/
CYPRESS_AUTH_URL=https://portal.openslice.eu/
CYPRESS_AUTH_REALM=/auth/realms/openslice/protocol/openid-connect/auth
CYPRESS_RESET_CREDENTIALS=/auth/realms/openslice/login-actions/reset-credentials
CYPRESS_REGISTRATION=/auth/realms/openslice/login-actions/registration
 No newline at end of file
+124 −126
Original line number Diff line number Diff line
describe('user authentication', () => {
describe("user authentication", () => {
  beforeEach(() => {
    cy.visit(window.location.origin);
  });

    })
    //edit profile bug
    it('should block unauthenticated user from entering a protected route', () => {
  it("should block unauthenticated user from entering a protected route", () => {
    cy.fixture("routes.json").then((data) => {
      cy.log(data.routes);
            // cy.wrap(data.routes).as("protectedRoutes");
      for (let route of data.routes) {
        cy.intercept(route);
        cy.log(route);
@@ -15,119 +13,119 @@ describe('user authentication', () => {
        cy.location("pathname").should("equal", "/");
      }
    });
        
    });

    it('should display login errors when nothing is typed', () => {
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            cy.get('#kc-login').click();
            cy.get('#input-error').should('be.visible').and('contain','Invalid username or password.');
            cy.get('[aria-invalid="true"]').should('have.length', 2); //the 2 input fields should have selector aria-invalid = 'true'
            
  });
        
    });

    it('should display login errors when credentials are wrong', () => {
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            
            cy.get('#username').type('test').blur();
            cy.get('#password').type('test').blur();
            cy.get('#kc-login').click();
            cy.get('#input-error').should('be.visible').and('contain','Invalid username or password.');
            cy.get('[aria-invalid="true"]').should('have.length', 2); //the 2 input fields should have selector aria-invalid = 'true'
            
        });
    });

    it('should login, logout', () => {
        
        cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services');
        cy.get('#navbarDropdown2').click();
  it("should display login errors when nothing is typed", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));
      cy.get("#kc-login").click();
      cy.get("#input-error")
        .should("be.visible")
        .and("contain", "Invalid username or password.");
      cy.get('[aria-invalid="true"]').should("have.length", 2); //the 2 input fields should have selector aria-invalid = 'true'
    });
  });
  it("should display login errors when credentials are wrong", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));

      cy.get("#username").type("test").blur();
      cy.get("#password").type("test").blur();
      cy.get("#kc-login").click();
      cy.get("#input-error")
        .should("be.visible")
        .and("contain", "Invalid username or password.");
      cy.get('[aria-invalid="true"]').should("have.length", 2); //the 2 input fields should have selector aria-invalid = 'true'
    });
  });
  it("should login, logout", () => {
    cy.loginPath(
      ":nth-child(2) > .container > .row > :nth-child(2) > a > .btn",
      "/services"
    );
    cy.get("#navbarDropdown2").click();
    cy.window().then((win) => {
            expect(win.localStorage.getItem('access_token')).to.exist;
        })
      expect(win.localStorage.getItem("access_token")).to.exist;
    });

        cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
    cy.get(
      ":nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)"
    ).click();
    cy.location("pathname").should("equal", "/");
  });

    it('forget password should work', () => {
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            cy.get(':nth-child(2) > span > a').click();
            cy.location("pathname").should("equal", "/auth/realms/openslice/login-actions/reset-credentials");
            cy.get('#username').should('exist');
            
  it("forget password should work", () => {
    cy.get(":nth-child(1) > .nav-link").click();
    cy.location("pathname").should("equal", "/services");
    cy.get(".btn").should("contain", "Sign In").click();
    cy.origin(Cypress.env("authURL"), () => {
      cy.location("pathname").should("equal", Cypress.env("authRealm"));
      cy.get(":nth-child(2) > span > a").click();
      cy.log(Cypress.env("resetCredentials"));
      cy.location("pathname").should("equal", Cypress.env("resetCredentials"));
      cy.get("#username").should("exist");
    });
  });

    context('register form', () => {
  context("register form", () => {
    beforeEach(() => {
            cy.get(':nth-child(1) > .nav-link').click();
            cy.location("pathname").should("equal", '/services');
            cy.get('.btn').should("contain", "Sign In").click();
            cy.origin('https://portal.openslice.eu', () => {
                
                cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
                cy.get('#kc-registration > span > a').click();
                cy.location("pathname").should("equal", "/auth/realms/openslice/login-actions/registration");
                
      cy.get(":nth-child(1) > .nav-link").click();
      cy.location("pathname").should("equal", "/services");
      cy.get(".btn").should("contain", "Sign In").click();
      cy.origin(Cypress.env("authURL"), () => {
        cy.location("pathname").should("equal", Cypress.env("authRealm"));
        cy.get("#kc-registration > span > a").click();
        cy.location("pathname").should("equal", Cypress.env("registration"));
      });
    });
    it("register form should not be empty when submitted", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get(".pf-c-button").click();
        cy.get("#input-error-firstname")
          .should("exist")
          .and("contain", "Please specify first name.");
        cy.get("#input-error-lastname")
          .should("exist")
          .and("contain", "Please specify last name.");
        cy.get("#input-error-email")
          .should("exist")
          .and("contain", "Please specify email.");
        cy.get("#input-error-username")
          .should("exist")
          .and("contain", "Please specify username.");
        cy.get("#input-error-password")
          .should("exist")
          .and("contain", "Please specify password.");
      });
    });
    it("invalid email", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get("#email").type("email");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-email")
          .should("exist")
          .and("contain", "Invalid email address.");
        cy.get("#email").type("@example.com");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-email").should("not.exist");
      });
    });
    it("confirm password field should be the same with password", () => {
      cy.origin(Cypress.env("authURL") + Cypress.env("registration"), () => {
        cy.get("#password").type("123");
        cy.get("#password-confirm").type("1234");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-password-confirm")
          .should("exist")
          .and("contain", "Password confirmation doesn't match.");
        cy.get("#password").type("123");
        cy.get("#password-confirm").type("123");
        cy.get(".pf-c-button").click();
        cy.get("#input-error-password-confirm").should("not.exist");
      });
        })
        it('register form should not be empty when submitted', () => {
            
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
    
                cy.get('.pf-c-button').click();
                cy.get('#input-error-firstname').should('exist').and('contain', 'Please specify first name.');
                cy.get('#input-error-lastname').should('exist').and('contain', 'Please specify last name.');
                cy.get('#input-error-email').should('exist').and('contain', 'Please specify email.');
                cy.get('#input-error-username').should('exist').and('contain', 'Please specify username.');
                cy.get('#input-error-password').should('exist').and('contain', 'Please specify password.');
    });
            
  });

        it('invalid email', () => {
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
                
                cy.get('#email').type('email');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-email').should('exist').and('contain','Invalid email address.');
                cy.get('#email').type('@example.com');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-email').should('not.exist');
            });
        });

        it('confirm password field should be the same with password', () => {
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
                cy.get('#password').type('123');
                cy.get('#password-confirm').type('1234');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-password-confirm').should('exist').and('contain',"Password confirmation doesn't match.");
                cy.get('#password').type('123');
                cy.get('#password-confirm').type('123');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-password-confirm').should('not.exist');
});
        });


    })
    
})
 No newline at end of file
+106 −122
Original line number Diff line number Diff line
declare namespace Cypress {
   
  interface Chainable {
        navigateToServices(selector): Chainable<any>,
        navigateToResources(selector): Chainable<any>,
        navigateToTesting(selector): Chainable<any>,
        navigateToProducts(selector): Chainable<any>,
        authUser(): Chainable<any>,
        loginPath(selector, path): Chainable<any>,
        manageEntities(selector, button, scndIndx, numOfItems): Chainable<any>,
        checkProtectedRoutes(): Chainable<any>
    navigateToServices(selector): Chainable<any>;
    navigateToResources(selector): Chainable<any>;
    navigateToTesting(selector): Chainable<any>;
    navigateToProducts(selector): Chainable<any>;
    authUser(): Chainable<any>;
    loginPath(selector, path): Chainable<any>;
    manageEntities(selector, button, scndIndx, numOfItems): Chainable<any>;
    checkProtectedRoutes(): Chainable<any>;
  }
}

Cypress.Commands.add('navigateToServices', (selector) => {
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");

  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");

  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();

  cy.get(":nth-child(2) > .nav-item > .nav-link").click();
  //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

  cy.origin(Cypress.env("authURL"), () => {
    cy.location("pathname").should("equal", Cypress.env("authRealm"));
  });
});

Cypress.Commands.add('navigateToResources', (selector) => {
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(".btn").should("exist").click();
  //cy.get('nav-link').should('exist').click();

  //sign in button should redirect to auth form
      cy.origin('https://portal.openslice.eu/', () => {
        cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

  cy.origin(Cypress.env("authURL"), () => {
    cy.location("pathname").should("equal", Cypress.env("authRealm"));
  });
})

Cypress.Commands.add('navigateToTesting', (selector) => {
});
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(".btn").should("exist").click();
  //cy.get('nav-link').should('exist').click();

  //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

  cy.origin(Cypress.env("authURL"), () => {
    cy.location("pathname").should("equal", Cypress.env("authRealm"));
  });
});

Cypress.Commands.add('navigateToProducts', (selector) => {
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");

  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");

  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();

  cy.get(":nth-child(2) > .nav-item > .nav-link").click();
  //sign in button should redirect to auth form
    cy.origin('https://portal.openslice.eu', () => {
    cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");

  cy.origin(Cypress.env("authURL"), () => {
    cy.location("pathname").should("equal", Cypress.env("authRealm"));
  });
});

Cypress.Commands.add('authUser', () => {
    cy.get('.btn').should("contain", "Sign In").click();

    cy.origin('https://portal.openslice.eu', () => {
        cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
        cy.get('#username').type(Cypress.env('username'));
        cy.get('#password').type(Cypress.env('password'));
        cy.get('#kc-login').click();
Cypress.Commands.add("authUser", () => {
  cy.get(".btn").should("contain", "Sign In").click();
  cy.origin(Cypress.env("authURL"), () => {
    cy.location("pathname").should("equal", Cypress.env("authRealm"));
    cy.get("#username").type(Cypress.env("username"));
    cy.get("#password").type(Cypress.env("password"));
    cy.get("#kc-login").click();
  });
    //redirect page
  cy.location("pathname").should("equal", "/redirect");
});

Cypress.Commands.add('loginPath', (selector, path) => {
Cypress.Commands.add("loginPath", (selector, path) => {
  cy.get(selector).click();
  cy.intercept(path);
  cy.location("pathname").should("equal", path);
  cy.authUser();
})

Cypress.Commands.add('manageEntities', (selector, button, scndIndx, numOfItems) => {
    
});
Cypress.Commands.add(
  "manageEntities",
  (selector, button, scndIndx, numOfItems) => {
    for (let i = 1; i <= numOfItems; i++) {
      cy.get(selector).click();
      if (i == 2 && scndIndx == 3) {
            cy.get(`.nav-item.show > .dropdown-menu > :nth-child(3) > .dropdown-item`).click();
            cy.go('back');
        }
            
        else
            cy.get(`.nav-item.show > .dropdown-menu > :nth-child(${i}) > .dropdown-item`).click();
        cy.get(
          `.nav-item.show > .dropdown-menu > :nth-child(3) > .dropdown-item`
        ).click();
        cy.go("back");
      } else
        cy.get(
          `.nav-item.show > .dropdown-menu > :nth-child(${i}) > .dropdown-item`
        ).click();
      cy.get(button).click();
        cy.go('back');
      cy.go("back");
    }
})

Cypress.Commands.add('checkProtectedRoutes', () => {
    for(let route of Cypress.env('protectedRoutes')) {
  } 
);
Cypress.Commands.add("checkProtectedRoutes", () => {
  for (let route of Cypress.env("protectedRoutes")) {
    cy.intercept(route);
    cy.log(route);
    cy.visit(route);
    cy.location("pathname").should("equal", "/");
  }
})
 No newline at end of file
});
Loading