Created
January 28, 2019 08:00
-
-
Save avseng/ffd7f060e069c42060bbd32515a30890 to your computer and use it in GitHub Desktop.
Selenium code to test OIM use case: Request creation and approval process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.selenium.webdriver.oim; | |
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.support.ui.ExpectedConditions; | |
import org.openqa.selenium.support.ui.WebDriverWait; | |
public class SeleniumOim { | |
WebDriver driver; | |
String requestId = ""; | |
public void invokeBrowser() { | |
try { | |
System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe"); | |
driver = new ChromeDriver(); | |
driver.manage().deleteAllCookies(); | |
driver.manage().window().maximize(); | |
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); | |
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); | |
driver.get("http://192.168.1.18:8005/identity/"); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public boolean authenticateOIM(String username, String password) { | |
boolean status = true; | |
try { | |
driver.findElement(By.xpath("//*[@id=\"pt1:_pt_it1::content\"]")).sendKeys(username); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_pt_it2::content\"]")).sendKeys(password); | |
Thread.sleep(500); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_pt_cb1\"]")).click(); | |
/* | |
* if (driver.findElements(By.xpath( | |
* "//*[@id=\"pt1:_pt_pfl1\"]/table/tbody/tr/td/table/tbody/tr[2]/td/span" | |
* )).size() != 0){ | |
* | |
* System.out.println("Authentication Failed"); status = false; | |
* driver.close(); }else{ | |
* System.out.println("Authentication successfull"); status = true; | |
* } | |
*/ | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return status; | |
} | |
public void runCreateApplicationRequest() { | |
try { | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db3:dc_cil2::icon\"]")).click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db3:cmi1\"]/td[2]")).click(); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:pt1:r1:0:r4:0:pt1:subf1:it3::content\"]")) | |
.sendKeys("SeleniumTest"); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:pt1:r1:0:r4:0:pt1:subf1:cb1\"]/a/span")) | |
.click(); | |
Thread.sleep(300); | |
String itemName = driver | |
.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:pt1:r1:0:t1:10:pgl7\"]/div[1]/span")) | |
.getText(); | |
System.out.println(itemName); | |
if (itemName.equalsIgnoreCase("Selenium Testing")) { | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:pt1:r1:0:t1:10:addToCart\"]/a/span")) | |
.click(); | |
} | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:pt1:trainNextBtn\"]")).click(); | |
Thread.sleep(3000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:oimGeneratedForm::icon\"]")).click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:r2:0:_xg_1::content\"]")) | |
.sendKeys("TEST Login"); | |
Thread.sleep(300); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:r2:0:_xg_3::content\"]")) | |
.sendKeys("Welcome1"); | |
Thread.sleep(300); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:r2:0:_xg_5::content\"]")) | |
.sendKeys("TESTID"); | |
Thread.sleep(300); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:it1::content\"]")) | |
.sendKeys("Sample justification for selenium test"); | |
Thread.sleep(300); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:updateCartDetails\"]")).click(); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:2:pt1:r1:0:commandToolbarButton2\"]/a/span")) | |
.click(); | |
Thread.sleep(2000); | |
WebElement requestDetailsElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions | |
.presenceOfElementLocated(By.xpath("//*[@id=\"pt1:_diags:pgl9\"]/tbody/tr/td[3]"))); | |
if (requestDetailsElement.isDisplayed() || requestDetailsElement.isEnabled()) { | |
System.out.println("11111111 "); | |
String requestDeatils = driver.findElement(By.xpath("//*[@id=\"pt1:_diags:pgl9\"]/tbody/tr/td[3]")) | |
.getText(); | |
String[] splitElement = requestDeatils.split(" "); | |
requestId = splitElement[1]; | |
System.out.println("Request Id: " + requestId); | |
} | |
Thread.sleep(1000); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public void runRequestApproval() { | |
try { | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db7:dc_cil1::icon\"]")).click(); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:keywordFilter::content\"]")) | |
.sendKeys(requestId); | |
Thread.sleep(700); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:searchButton::icon\"]")).click(); | |
Thread.sleep(1000); | |
driver.findElement( | |
By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:taskTable::db\"]/table/tbody/tr/td[6]")).click(); | |
Thread.sleep(1000); | |
driver.findElement(By | |
.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:taskActionsSelect\"]/div/table/tbody/tr/td[3]/div")) | |
.click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:caitr:0:cami\"]/td[2]")).click(); | |
Thread.sleep(2000); | |
} catch (InterruptedException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
public void runFullfilment() { | |
try { | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db6:dc_cil2::icon\"]")).click(); | |
Thread.sleep(1500); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db6:cmi4\"]/td[2]")).click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:keywordFilter::content\"]")) | |
.sendKeys(requestId); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:searchButton::icon\"]")).click(); | |
Thread.sleep(1000); | |
driver.findElement( | |
By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:taskTable::db\"]/table/tbody/tr/td[6]")).click(); | |
Thread.sleep(1000); | |
driver.findElement(By | |
.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:taskActionsSelect\"]/div/table/tbody/tr/td[3]/div")) | |
.click(); | |
Thread.sleep(1000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region1:1:r1:0:tldc:caitr:1:cami\"]/td[2]")).click(); // complete | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_sh_np2:_dtb_0::disclosureAnchor\"]")).click(); // click to home page | |
Thread.sleep(1000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void searchRequestStatus() { | |
try { | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region0:0:db8:dc_cil1::icon\"]")).click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region2:1:dc1:qq1:criterionValue::content\"]")) | |
.sendKeys(requestId); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:_d_reg:region2:1:dc1:qq1::search_icon\"]")).click(); | |
Thread.sleep(3000); | |
driver.close(); | |
System.out.println("********************* Test Successful *********************************"); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void signOut() { | |
try { | |
driver.findElement(By.xpath("//*[@id=\"pt1:bbar:pt_m2\"]/div/table/tbody/tr/td[3]/div")).click(); | |
Thread.sleep(2000); | |
driver.findElement(By.xpath("//*[@id=\"pt1:bbar:cni2\"]/td[2]")).click(); | |
Thread.sleep(2000); | |
driver.close(); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
SeleniumOim a = new SeleniumOim(); | |
a.invokeBrowser(); | |
System.out.println(a.authenticateOIM("USERNAME", "PASSWORD")); // sign in to console as requester | |
a.runCreateApplicationRequest(); // creating request for a disconnected application | |
a.signOut(); // sign out from the console | |
try { | |
Thread.sleep(3000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
a.invokeBrowser(); | |
System.out.println(a.authenticateOIM("USERNAME", "PASSWORD")); // sign in to console as approver | |
a.runRequestApproval(); // Approving the request | |
a.signOut(); // sign out from the console | |
try { | |
Thread.sleep(2000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
a.invokeBrowser(); | |
System.out.println(a.authenticateOIM("USERNAME", "PASSWORD")); // sign in to console implementer | |
a.runFullfilment(); //completing manual fulfillment for the request | |
a.searchRequestStatus(); //check the request status. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment