Skip to content
Snippets Groups Projects
Commit cb3a0e4f authored by Michail Tzanatos's avatar Michail Tzanatos
Browse files

removed hardcoded routes

parent 24648816
No related branches found
No related tags found
1 merge request!22Draft: Resolve "Implement user journey tests"
This commit is part of merge request !22. Comments created here will be created in the context of that merge request.
......@@ -41,6 +41,8 @@ yarn-error.log
testem.log
/typings
.env
cypress/fixtures
cypress/screenshots
# System Files
.DS_Store
......
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_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
describe('user authentication', () => {
beforeEach(() => {
cy.visit(window.location.origin);
})
//edit profile bug
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);
cy.visit(route);
cy.location("pathname").should("equal", "/");
}
});
});
describe("user authentication", () => {
beforeEach(() => {
cy.visit(window.location.origin);
});
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 block unauthenticated user from entering a protected route", () => {
cy.fixture("routes.json").then((data) => {
cy.log(data.routes);
for (let route of data.routes) {
cy.intercept(route);
cy.log(route);
cy.visit(route);
cy.location("pathname").should("equal", "/");
}
});
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 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"));
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;
})
cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
cy.location("pathname").should("equal", "/");
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('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("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;
});
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");
});
})
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
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(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", () => {
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(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");
});
});
});
});
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>
}
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>;
}
}
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('https://portal.openslice.eu', () => {
cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
});
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(Cypress.env("authURL"), () => {
cy.location("pathname").should("equal", Cypress.env("authRealm"));
});
});
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('https://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('https://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(Cypress.env("authURL"), () => {
cy.location("pathname").should("equal", Cypress.env("authRealm"));
});
});
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('https://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(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();
});
//redirect page
cy.location("pathname").should("equal", "/redirect");
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(Cypress.env("authURL"), () => {
cy.location("pathname").should("equal", Cypress.env("authRealm"));
});
});
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) => {
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(button).click();
cy.go('back');
}
})
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", "/");
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();
});
cy.location("pathname").should("equal", "/redirect");
});
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) => {
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(button).click();
cy.go("back");
}
})
\ No newline at end of file
}
);
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", "/");
}
});
Source diff could not be displayed: it is too large. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment