Skip to content

Commit

Permalink
MOSIP-33299 added testcases for revamp ui automation (#817)
Browse files Browse the repository at this point in the history
* MOSIP-33299

Signed-off-by: Anup Nehe <[email protected]>

* resolve conflicts

Signed-off-by: Anup Nehe <[email protected]>

* resolve conflicts

Signed-off-by: Anup Nehe <[email protected]>

---------

Signed-off-by: Anup Nehe <[email protected]>
  • Loading branch information
anup-nehe authored Oct 8, 2024
1 parent 9d6209f commit f4e7778
Show file tree
Hide file tree
Showing 17 changed files with 802 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package io.mosip.testrig.pmprevampui.fw.util;
import static io.restassured.RestAssured.given;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


import org.json.JSONObject;

import io.mosip.testrig.pmprevampui.authentication.fw.util.RestClient;
import io.mosip.testrig.pmprevampui.kernel.util.ConfigManager;
import io.mosip.testrig.pmprevampui.kernel.util.KeycloakUserManager;
import io.mosip.testrig.pmprevampui.utility.BaseTestCaseFunc;
import io.mosip.testrig.pmprevampui.utility.TestRunner;
import io.restassured.http.ContentType;
import io.restassured.response.Response;

public class AdminTestUtil extends BaseTestCaseFunc {

private static final org.slf4j.Logger logger= org.slf4j.LoggerFactory.getLogger(RestClient.class);
public static String token;
public static String user;
public static String tokenRoleIdRepo = "idrepo";
public static String tokenRoleAdmin = "admin";
private static String serverComponentsCommitDetails;
public static String propsHealthCheckURL = TestRunner.getResourcePath() + "/"
+ "config/healthCheckEndpoint.properties";
public static boolean initialized = false;


public static String getServerComponentsDetails() {
if (serverComponentsCommitDetails != null && !serverComponentsCommitDetails.isEmpty())
return serverComponentsCommitDetails;

File file = new File(propsHealthCheckURL);
FileReader fileReader = null;
BufferedReader bufferedReader = null;
StringBuilder stringBuilder = new StringBuilder();
try {
fileReader = new FileReader(file);
bufferedReader = new BufferedReader(fileReader);
String line;

while ((line = bufferedReader.readLine()) != null) {
if (line.trim().equals("") || line.trim().startsWith("#"))
continue;
String[] parts = line.trim().split("=");
if (parts.length > 1) {
if (ConfigManager.isInServiceNotDeployedList(parts[1])) {
continue;
}
stringBuilder.append("\n")
.append(getCommitDetails(BaseTestCaseFunc.ApplnURI + parts[1].replace("health", "info")));
}
}
} catch (Exception e) {
logger.error(e.getMessage());
} finally {
AdminTestUtil.closeBufferedReader(bufferedReader);
AdminTestUtil.closeFileReader(fileReader);
}
serverComponentsCommitDetails = stringBuilder.toString();
return serverComponentsCommitDetails;
}
public static void closeBufferedReader(BufferedReader bufferedReader) {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
// logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
}
}
}

public static void closeFileReader(FileReader fileReader) {
if (fileReader != null) {
try {
fileReader.close();
} catch (IOException e) {
// logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
}
}
}

public static String getCommitDetails(String path) {

Response response = null;
response = given().contentType(ContentType.JSON).get(path);
if (response != null && response.getStatusCode() == 200) {
logger.info(response.getBody().asString());
JSONObject jsonResponse = new JSONObject(response.getBody().asString());
return "Group: " + jsonResponse.getJSONObject("build").getString("group") + ", Artifact: "
+ jsonResponse.getJSONObject("build").getString("artifact") + ", version: "
+ jsonResponse.getJSONObject("build").getString("version") + ", Commit ID: "
+ jsonResponse.getJSONObject("git").getJSONObject("commit").getString("id");
}
return path + "- No Response";
}
public static String UserMapping() {
return user;

}

public static void initialize() {
if (initialized == false) {
ConfigManager.init();


BaseTestCaseFunc.initialize();
HashMap<String, List<String>> attrmap=new HashMap<String, List<String>>();
List<String> list=new ArrayList<String>();
String val= "11000000";
list.add(val);
attrmap.put("individualId",list);
KeycloakUserManager.createUsers();
BaseTestCaseFunc.mapUserToZone(BaseTestCaseFunc.currentModule+"-"+propsKernel.getProperty("admin_userName"),"CSB");
BaseTestCaseFunc.mapZone(BaseTestCaseFunc.currentModule+"-"+propsKernel.getProperty("admin_userName"));
initialized = true;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ public class ConfigManager {
private static String SbivalidDate = "sbivalidDate";
private static String PublicKey = "publicKey";
private static String RandomPublicKey = "randompublicKey";

private static String LogoUri = "logouri";
private static String RedirectUri = "redirecturi";
private static String SignPublicKey = "signPublicKey";
private static String Headless = "headless";
private static String Docker = "docker";
private static String Langcode = "langcode";
private static String SbiexpiryDate = "sbiexpiryDate";// loginlang
private static String SbiexpiryDate = "sbiexpiryDate";//loginlang
private static String Loginlang = "loginlang";
private static String PolicyData = "policyData";// loginlang
private static String PolicyData = "policyData";//loginlang
private static String DataSharepolicyData = "dataSharepolicyData";
private static String Testcases = "pmpscenariosToExecute";

Expand All @@ -75,6 +78,9 @@ public class ConfigManager {
private static String signPublicKey;
private static String publicKey;
private static String randomPublicKey;
private static String logouri;
private static String redirectUri;

private static String sbivalidDate;
private static String bulkwait;
private static String sbiexpiryDate;
Expand Down Expand Up @@ -262,6 +268,12 @@ public static void init() {
randomPublicKey = System.getenv(RandomPublicKey) == null ? propsKernel.getProperty(RandomPublicKey)
: System.getenv(RandomPublicKey);
propsKernel.setProperty(RandomPublicKey, randomPublicKey);

logouri =System.getenv(LogoUri) == null ? propsKernel.getProperty(LogoUri) : System.getenv(LogoUri);
propsKernel.setProperty(LogoUri, logouri);

redirectUri =System.getenv(RedirectUri) == null ? propsKernel.getProperty(RedirectUri) : System.getenv(RedirectUri);
propsKernel.setProperty(RedirectUri, redirectUri);

signPublicKey = System.getenv(SignPublicKey) == null ? propsKernel.getProperty(SignPublicKey)
: System.getenv(SignPublicKey);
Expand Down Expand Up @@ -327,11 +339,18 @@ public static String getsignPublicKey() {
public static String getpublicKey() {
return publicKey;
}

public static String getrandomPublicKey() {
return randomPublicKey;
}


public static String getLogouri() {
return logouri;
}

public static String getRedirectUri() {
return redirectUri;
}
public static String getsbivalidDate() {
return sbivalidDate;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package io.mosip.testrig.pmprevampui.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class ApiKeyPage extends BasePage{

@FindBy(xpath = "Enter a name for API key")
private WebElement enterNameOfApiKeyTextBox;

@FindBy(xpath = "generate_submit_btn")
private WebElement submitButton;

@FindBy(id = "generate_partner_id")
private WebElement partnerIdDropdown;

@FindBy(id = "generate_policy_name")
private WebElement policyNameDropdown;

@FindBy(id = "generate_api_key_btn")
private WebElement generateAPIKey;

@FindBy(xpath = "//*[contains(text(), 'Partner ID')]")
private WebElement partnerIDHeaderText;

@FindBy(xpath = "//*[contains(text(), 'Policy Group')]")
private WebElement PolicyGroupHeaderText;

@FindBy(xpath = "//*[contains(text(), 'Policy Name')]")
private WebElement PolicyNameHeaderText;

@FindBy(xpath = "//*[contains(text(), 'API Key Name')]")
private WebElement ApiKeyHeaderText;

@FindBy(xpath = "//*[contains(text(), 'Created Date')]")
private WebElement CreatedDateHeaderText;

@FindBy(xpath = "//*[contains(text(), 'Status')]")
private WebElement StatusHeaderText;

@FindBy(xpath = "//*[contains(text(), 'Action')]")
private WebElement ActionHeaderText;

public ApiKeyPage(WebDriver driver) {
super(driver);
}

public void enterNameOfApiKeyTextBox(String value) {
enter(enterNameOfApiKeyTextBox,value);
}

public void selectPartnerIdDropdown(String value) {
clickOnElement(partnerIdDropdown);
clickOnElement(driver.findElement(By.xpath("(//*[contains(text(),'"+value+"')])[2]")));
}

public boolean isPartnerIdDropdownDisplayed() {
return isElementDisplayed(partnerIdDropdown);
}

public boolean isPolicyNameDropdownDisplayed() {
return isElementDisplayed(policyNameDropdown);
}

public void selectPolicyNameDropdown(String value) {
dropdownByIndex(policyNameDropdown,0);
}

public boolean isGenerateAPIKeyDisplayed() {
return isElementDisplayed(generateAPIKey);
}

public void ClickOnAPIKeyDisplayed() {
clickOnElement(generateAPIKey);
}

public void ClickOnSubmitButton() {
clickOnElement(submitButton);
}

public boolean isPartnerIDHeaderTextDisplayed() {
return isElementDisplayed(partnerIDHeaderText);
}

public boolean isPolicyGroupHeaderTextDisplayed() {
return isElementDisplayed(PolicyGroupHeaderText);
}

public boolean isPolicyNameHeaderTextDisplayed() {
return isElementDisplayed(PolicyNameHeaderText);
}

public boolean isApiKeyHeaderTextDisplayed() {
return isElementDisplayed(ApiKeyHeaderText);
}

public boolean isCreatedDateHeaderTextDisplayed() {
return isElementDisplayed(CreatedDateHeaderText);
}

public boolean isStatusHeaderTextDisplayed() {
return isElementDisplayed(StatusHeaderText);
}

public boolean isActionHeaderTextDisplayed() {
return isElementDisplayed(ActionHeaderText);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.format.DateTimeFormatter;
import java.util.Random;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
Expand All @@ -26,7 +27,7 @@ public class BasePage {

public BasePage(WebDriver driver) {
BasePage.driver = driver;
PageFactory.initElements(driver, this);
PageFactory.initElements(driver, this);
}

public static String getDateTime(){
Expand Down Expand Up @@ -135,6 +136,21 @@ protected boolean isElementDisplayed(WebElement element) {
return false;
}
}

protected boolean isElementEnabled(WebElement element) {
try {
waitForElementToBeVisible(element);
element.isEnabled();
return true;
} catch (Exception e) {
try {
Reporter.log("<p><img src='data:image/png;base64," + Screenshot.ClickScreenshot(driver) + "' width='900' height='450'/></p>");
} catch (IOException e1) {
e1.printStackTrace();
}
return false;
}
}

private void waitForElementToBeVisible(WebElement element) {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(40));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

public class DashboardPage extends BasePage{

@FindBy(xpath = "//div[@class='flex items-center ml-1']/button")
@FindBy(id = "header_user_profile_title")
private WebElement profileDropdown;

@FindBy(xpath = "//button[contains(text(), 'Logout')]")
@FindBy(id = "header_user_profile_logout_btn")
private WebElement logoutButton;

@FindBy(xpath = "//*[text()='Select Policy Group']")
Expand All @@ -33,12 +33,15 @@ public class DashboardPage extends BasePage{
@FindBy(xpath = "//*[text()='Proceed']")
private WebElement proceedButton;

@FindBy(xpath = "//*[text()='Partner Certificate']")
@FindBy(id = "dashboard_partner_certificated_list_card")
private WebElement partnerCertificateTitle;

@FindBy(xpath = "//*[text()='Policies']")
@FindBy(id = "dashboard_policies_card")
private WebElement policiesTitle;

@FindBy(id = "dashboard_authentication_clients_list_card")
private WebElement AuthenticationServices;

public DashboardPage(WebDriver driver) {
super(driver);
}
Expand Down Expand Up @@ -97,6 +100,10 @@ public boolean isPoliciesTitleDisplayed() {
return isElementDisplayed(policiesTitle);
}

public boolean isAuthenticationServicesTitleDisplayed() {
return isElementDisplayed(AuthenticationServices);
}

public PoliciesPage clickOnPoliciesTitle() {
clickOnElement(policiesTitle);
return new PoliciesPage(driver);
Expand All @@ -107,4 +114,9 @@ public PartnerCertificatePage clickOnPartnerCertificateTitle() {
return new PartnerCertificatePage(driver);
}

public OidcClientPage clickOnAuthenticationServicesTitle() {
clickOnElement(AuthenticationServices);
return new OidcClientPage(driver);
}

}
Loading

0 comments on commit f4e7778

Please sign in to comment.