Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove Commands folder from the common test base" #49

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions src/ui/commands/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/// <reference types="cypress" />

import { LoginPageDomConstants } from "../constants";
import { LoginPage } from "../page-objects";
import { CommonUtils } from "../utils";

/**
* Custom command to log users to portals.
* @example cy.login("admin", "admin", "https://localhost:9443/", "console/")
*
* @param {string} username - User's Username.
* @param {string} password - User's Password.
* @param {string} serverURL - Identity Server URL.
* @param {string} portal - Relative path of the portal to login.
* @param {string} tenantDomain - Tenant domain.
* @param {number} waitTime - Configure wait time.
* @returns {Cypress.CanReturnChainable}
*/
Cypress.Commands.add("login", (username: string,
password: string,
serverURL: string,
portal: string,
tenantDomain: string,
waitTime: number = 3000): Cypress.CanReturnChainable => {

cy.window()
.then((win: Cypress.AUTWindow) => {
win.onbeforeunload = null;
});

// Visit the portal. ex: `https://localhost:9443/carbon.super/console`
let url: URL = new URL(serverURL);

if (tenantDomain) {
url = new URL(tenantDomain, url);
}

if (portal) {
url = new URL(portal, url);
}

cy.log("URL", url);

cy.visit(url.toString(), {
onBeforeLoad: (win) => {
win.sessionStorage.clear();
}
});

const loginPage = new LoginPage();

loginPage.getLoginUsernameInputField().type(username);

// Auto-detect login flow i.e Identifier first or Normal login flow.
cy.get("body")
.then(($body: JQuery<HTMLBodyElement>) => {
// Check if a password field exists. If not, identify the form as part of an identifier first flow.
if ($body.find(CommonUtils.resolveDataTestId(LoginPageDomConstants.PASSWORD_INPUT_DATA_ATTR)).length > 0) {
loginPage.getLoginPasswordInputField().type(password, { log: false });
loginPage.getLoginFormSubmitButton().click();
} else {
cy.log("Identifier first flow detected...");

loginPage.getLoginFormContinueButton().click();
loginPage.getLoginPasswordInputField().type(password, { log: false });
loginPage.getLoginFormSubmitButton().click();
}

cy.wait(waitTime);
});
});

/**
* Custom command to log users out from portals.
* @example cy.logout()
*
* @param {string} tenantDomain - Override tenant domain. If not provided, will be taken from env.
* @param {number} waitTime - Configure wait time.
* @returns {Cypress.CanReturnChainable}
*/
Cypress.Commands.add("logout", (waitTime: number = 3000): Cypress.CanReturnChainable => {

const loginPage = new LoginPage();

loginPage.clickOnLogoutButton();

// Test fails due to this. Check if this is needed.
// cy.url().should("include", BASE_URL + TENANT_DOMAIN + AUTH_ENDPOINT_URL + LOGOUT_URL_QUERY);

cy.wait(waitTime);
});
56 changes: 56 additions & 0 deletions src/ui/commands/dom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

import { CommonUtils } from "../utils";

/// <reference types="cypress" />

/**
* Custom command to select DOM element by `data-testid` attribute.
*
* @deprecated Deprecated since version 0.2.5. Use `cy.dataComponentId()` instead.
*
* @example
* cy.dataTestId("<RAW_TEST_ID>") -> [data-testid=<RAW_TEST_ID>]
*
* @param {string} value - Attribute value.
* @param {string} options - Query options. i.e timeout etc.
* @returns {Cypress.CanReturnChainable}
*/
Cypress.Commands.add("dataTestId", (value: string, options?: Partial<Cypress.Loggable & Cypress.Timeoutable
& Cypress.Withinable & Cypress.Shadow>): Cypress.CanReturnChainable => {

return cy.get(CommonUtils.resolveDataTestId(value), options);
});

/**
* Custom command to select DOM element by `data-componentid` attribute.
*
* @example
* cy.dataComponentId("<RAW_TEST_ID>") -> [data-componentid=<RAW_TEST_ID>]
*
* @param {string} value - Attribute value.
* @param {string} options - Query options. i.e timeout etc.
* @returns {Cypress.CanReturnChainable}
*/
Cypress.Commands.add("dataComponentId", (value: string, options?: Partial<Cypress.Loggable & Cypress.Timeoutable
& Cypress.Withinable & Cypress.Shadow>): Cypress.CanReturnChainable => {

return cy.get(CommonUtils.resolveDataTestId(value), options);
});
25 changes: 25 additions & 0 deletions src/ui/commands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

/// <reference types="cypress" />
/// <reference path="../../../types/ui/commands.d.ts" />

import "./authentication";
import "./dom";
import "./user-onboard";
40 changes: 40 additions & 0 deletions src/ui/commands/user-onboard/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/// <reference types="cypress" />

import { ConsoleHeader, ConsoleSidePanel } from "../../page-objects";

/**
* Custom command to navigate to the user management section.
* @example cy.navigateToUserManagement()
*
* @param {boolean} switchPortalTab - If needed to switch to manage portal.
* @returns {Cypress.CanReturnChainable}
*/
Cypress.Commands.add("navigateToUserManagement", (switchPortalTab: boolean = true): Cypress.CanReturnChainable => {

if (switchPortalTab) {
const header: ConsoleHeader = new ConsoleHeader();
header.clickOnManagePortalSwitch({ force: true });
}

const sidePanel: ConsoleSidePanel = new ConsoleSidePanel();

sidePanel.navigateToUsers({ force: true });
});
20 changes: 20 additions & 0 deletions src/ui/commands/user-onboard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/

export * from "./commands";
2 changes: 0 additions & 2 deletions src/ui/page-objects/login-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class LoginPage {
* @return {Cypress.Chainable<JQuery<HTMLElement>>}
*/
public getLoginPasswordInputField(): Cypress.Chainable<Element> {

return cy.dataTestId(LoginPageDomConstants.PASSWORD_INPUT_DATA_ATTR);
}

Expand All @@ -60,7 +59,6 @@ export class LoginPage {
* @return {Cypress.Chainable<JQuery<HTMLElement>>}
*/
public getLoginFormSubmitButton(): Cypress.Chainable<Element> {

return cy.dataTestId(LoginPageDomConstants.SUBMIT_BUTTON_DATA_ATTR);
}

Expand Down
2 changes: 1 addition & 1 deletion types/api/commands.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ declare namespace Cypress {
interface Chainable {

/**
* This command create users from scim2.0 POST method
* Custom command to create users from scim2.0 POST method
*/
createUserViaAPI(host: string, authzHeader: string, reqBody: Cypress.ObjectLike,
failOnStatusCode?: boolean): Cypress.Chainable<any>;
Expand Down
Loading