Skip to content

Commit

Permalink
Merge pull request #156 from anup-nehe/develop
Browse files Browse the repository at this point in the history
INJIVER-606  fixed ui automation for inji verify
  • Loading branch information
sree96 authored Sep 18, 2024
2 parents f2d2f77 + a82024d commit ac64a31
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 77 deletions.
37 changes: 33 additions & 4 deletions ui-test/src/main/java/base/BasePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import java.net.URL;
import java.util.List;

import static java.time.Duration.ofSeconds;

public class BasePage {

public WebDriver driver;

public void waitForElementVisible(WebDriver driver, WebElement element, long seconds) {
new WebDriverWait(driver, Duration.ofSeconds(seconds)).until(ExpectedConditions.visibilityOf(element));
new WebDriverWait(driver, ofSeconds(seconds)).until(ExpectedConditions.visibilityOf(element));
}

public void clickOnElement(WebDriver driver, WebElement element) {
Expand All @@ -38,6 +40,11 @@ public Boolean isButtonEnabled(WebDriver driver, WebElement element) {
waitForElementVisible(driver, element, 10);
return element.isEnabled();
}
public void enterText(WebDriver driver, By locator, String text) {
WebElement element = new WebDriverWait(driver, Duration.ofSeconds(30)).until(ExpectedConditions.presenceOfElementLocated(locator));
element.clear();
element.sendKeys(text);
}

public void refreshBrowser(WebDriver driver) {
driver.navigate().refresh();
Expand All @@ -48,17 +55,26 @@ public void browserBackButton(WebDriver driver) {
}

public void uploadFile(WebDriver driver, WebElement element, String filename) {
String filePath = System.getProperty("user.dir") + "\\src\\test\\resources\\QRCodes\\" + filename;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
String filePath = System.getProperty("user.dir") + "/" + filename;
WebDriverWait wait = new WebDriverWait(driver, ofSeconds(10));
WebElement spanElement = wait.until(ExpectedConditions.elementToBeClickable(element));
spanElement.click();
WebElement fileInput = wait
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='file']")));
fileInput.sendKeys(filePath);
}

public void uploadFileForInvalid(WebDriver driver, WebElement element, String filename) {
String filePath = System.getProperty("user.dir") + "\\src\\test\\resources\\QRCodes\\" + filename;
WebDriverWait wait = new WebDriverWait(driver, ofSeconds(10));
WebElement spanElement = wait.until(ExpectedConditions.elementToBeClickable(element));
spanElement.click();
WebElement fileInput = wait
.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='file']")));
fileInput.sendKeys(filePath);
}
public void waitForElementVisibleWithPolling(WebDriver driver, WebElement element) {
FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(Duration.ofSeconds(90))
FluentWait<WebDriver> wait = new FluentWait<>(driver).withTimeout(ofSeconds(90))
.pollingEvery(Duration.ofMillis(300)).ignoring(NoSuchElementException.class);
wait.until(ExpectedConditions.visibilityOf(element));
}
Expand Down Expand Up @@ -86,4 +102,17 @@ public void verifyHomePageLinks(WebDriver driver, List<WebElement> links) {
}

}
protected void sendKeysToTextBox(WebDriver driver ,WebElement element, String text) {
this.waitForElementToBeVisible(element);
element.sendKeys(text);
}
private void waitForElementToBeVisible(WebElement element) {
WebDriverWait wait = new WebDriverWait(driver, ofSeconds(30));
wait.until(ExpectedConditions.visibilityOf(element));
}
protected void sendKeysToTextBox(WebElement element, String text) {
this.waitForElementToBeVisible(element);
element.sendKeys(text);
}

}
188 changes: 183 additions & 5 deletions ui-test/src/main/java/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package pages;

import base.BasePage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.*;
import org.openqa.selenium.support.FindBy;
import java.util.List;
import java.util.Set;

import org.openqa.selenium.support.PageFactory;

public class HomePage extends BasePage {
Expand Down Expand Up @@ -43,7 +44,7 @@ public HomePage(WebDriver driver) {
@FindBy(xpath = "//div[@id='help-submenu']/a")
List<WebElement> HelpOptionLinks;

@FindBy(xpath = "(//*[@id='help-button']//*[@class='mx-1.5 ']//*)[2]")
@FindBy(xpath = "//*[@id='help-button']/*[@stroke='currentColor']")
WebElement minimizeHelpButton;

@FindBy(xpath = "//*[@id='upload-qr-code-tab']")
Expand Down Expand Up @@ -79,7 +80,7 @@ public HomePage(WebDriver driver) {
@FindBy(xpath = "//span[@class='inline-grid mr-1.5']")
WebElement UploadIcon;

@FindBy(xpath = "//*[@id='upload-qr-code-button']")
@FindBy(id = "upload-qr-code-button")
WebElement UploadButton;

@FindBy(xpath = "//div[@class='grid text-center content-center justify-center pt-2']")
Expand All @@ -91,6 +92,43 @@ public HomePage(WebDriver driver) {
@FindBy(xpath = "//button[@id='ble-tab']")
WebElement bleTab;

@FindBy(xpath = "//input[@type='text']")
WebElement SearchBox;

@FindBy(xpath = "//p[@data-testid='IntroBox-SubText']")
WebElement IntroSubText;

@FindBy(xpath = "(//h3[@data-testid='ItemBox-Text'])[1]")
WebElement mosipCrdentials;

@FindBy(xpath = "//h3[@data-testid='ItemBox-Text']")
WebElement isMosipNationalId;

@FindBy(xpath = "//input[@id='Otp_mosip-vid']")
WebElement vidTextBox;

@FindBy(xpath = "//button[@id='get_otp']")
WebElement getOtp;

@FindBy(xpath = "//button[@id='verify_otp']")
WebElement verifyOtp;

@FindBy(xpath = "//p[@data-testid='DownloadResult-Title']")
WebElement succsessMessage;

@FindBy(xpath = "//label[text() = 'Enter Full Name']")
WebElement enterFullnameTextBox;

@FindBy(xpath = "//button[@id='verify_form']")
WebElement verifyButton;

@FindBy(xpath = "//*[@data-testid='DownloadResult-Home-Button']")
WebElement HomeButton;

@FindBy(xpath = "//p[text() = 'Something went wrong with your request. Please check and try again.']")
WebElement errorMeassage;


public Boolean isLogoDisplayed() {
return injiVerifyLogo.isDisplayed();

Expand Down Expand Up @@ -206,6 +244,7 @@ public Boolean isUploadIconIsVisible() {
}

public Boolean isUploadButtonIsVisible() {
driver.navigate().refresh();
return isElementIsVisible(driver, UploadButton);
}

Expand All @@ -219,4 +258,143 @@ public void ClickonQRUploadButton() {
clickOnElement(driver, QRUploadButton);
}

}

public void enterIssuersInSearchBox(String string) {
enterText(driver, By.xpath("//input[@type='text']"), string);

}

public void clickOnDownloadMosipCredentials() {
clickOnElement(driver,mosipCrdentials);
}

public Boolean isMosipNationalIdDisplayed() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return isElementIsVisible(driver, isMosipNationalId);
}

public void clickOnMosipNationalId() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
clickOnElement(driver, isMosipNationalId);
}

public void enterVid(String string) {
enterText(driver, By.xpath("//input[@id='Otp_mosip-vid']"), string);
}

public void clickOnGetOtpButton() {
clickOnElement(driver, getOtp);
}
public void enterOtp( String otpString) {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < otpString.length(); i++) {
String locator = "(//input[@class='pincode-input-text'])[" + (i + 1) + "]";
driver.findElement(By.xpath(locator)).sendKeys(String.valueOf(otpString.charAt(i)));
}
}

public void clickOnVerify() {
clickOnElement(driver, verifyOtp);
}

public String isSuccessMessageDisplayed() {
try {
Thread.sleep(6000);
;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return getText(driver, succsessMessage);
}

public void openNewTab(){
((JavascriptExecutor) driver).executeScript("window.open('https://injiweb.qa-inji.mosip.net/')");
Set<String> allWindowHandles = driver.getWindowHandles();
System.out.println(allWindowHandles);
if (allWindowHandles.size() >= 2) {
String secondWindowHandle = allWindowHandles.toArray(new String[0])[1];
String firstWindowHandle = allWindowHandles.toArray(new String[0])[0];
driver.switchTo().window(secondWindowHandle);
}
}

public void SwitchToWebTab(){
Set<String> allWindowHandles = driver.getWindowHandles();
System.out.println(allWindowHandles);
if (allWindowHandles.size() >= 2) {
String secondWindowHandle = allWindowHandles.toArray(new String[0])[1];
String firstWindowHandle = allWindowHandles.toArray(new String[0])[0];
// Switch to the second window
driver.switchTo().window(secondWindowHandle);
}
}

public void SwitchToVerifyTab(){
Set<String> allWindowHandles = driver.getWindowHandles();
System.out.println(allWindowHandles);
if (allWindowHandles.size() >= 2) {
String secondWindowHandle = allWindowHandles.toArray(new String[0])[1];
String firstWindowHandle = allWindowHandles.toArray(new String[0])[0];
driver.switchTo().window(firstWindowHandle);
}
}
public void enterPolicyNumer(String string) {
enterText(driver, By.xpath("//input[@id='_form_policyNumber']"), string);
}

public void enterFullName(String string) {
enterText(driver, By.xpath("//input[@id='_form_fullName']"), string);
}
public void selectDateOfBirth() {
driver.findElement(By.xpath("//input[@id='_form_fullName']")).sendKeys(Keys.TAB);
driver.findElement(By.id("_form_dob")).sendKeys("01/01/2024");


driver.findElement(By.xpath("//input[@id='_form_dob']")).click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(driver.getWindowHandles());

JavascriptExecutor js = (JavascriptExecutor) driver;
String xpath = "//*[contains(@text,'SET')]"; // Improved XPath (consider adding specificity)

try {
js.executeScript("document.evaluate(arguments[0], document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click()", xpath);
} catch (NoSuchElementException e) {
System.out.println("Element not found with XPath: " + xpath);
} catch (JavascriptException e) {
System.out.println("JavaScript error: " + e.getMessage());
}
}

public void clickOnLogin() {
clickOnElement(driver,verifyButton );
}

public void clickOnHomebutton() {
clickOnElement(driver,HomeButton );
}

public Boolean isErrorMessageVisible() {
return isElementIsVisible(driver, errorMeassage);
}

}
7 changes: 7 additions & 0 deletions ui-test/src/main/java/pages/ScanQRCodePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public ScanQRCodePage(WebDriver driver) {
@FindBy(xpath = "//button[@id='verification-back-button']")
WebElement BackButton;

@FindBy(id="camer-access-denied-okay-button")
WebElement OkayButton;

@FindBy(xpath = "//div[@id='scanning-line']")
WebElement ScanLine;

Expand Down Expand Up @@ -150,6 +153,10 @@ public void ClickonBackButton() {
clickOnElement(driver, BackButton);
}

public void ClickonOkayButton() {
clickOnElement(driver, OkayButton);
}

public boolean isVisibleScanLine() {
return isElementIsVisible(driver, ScanLine);
}
Expand Down
Loading

0 comments on commit ac64a31

Please sign in to comment.