|
| 1 | +package basics; |
| 2 | + |
| 3 | +import basepkg.BaseClass; |
| 4 | +import org.openqa.selenium.By; |
| 5 | +import org.openqa.selenium.StaleElementReferenceException; |
| 6 | +import org.openqa.selenium.WebElement; |
| 7 | +import org.openqa.selenium.support.ui.ExpectedConditions; |
| 8 | +import org.openqa.selenium.support.ui.WebDriverWait; |
| 9 | +import org.testng.Assert; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +import javax.swing.*; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +/** |
| 16 | + * Created by jitendra on 29/6/17. |
| 17 | + */ |
| 18 | +public class UpdateTickets extends BaseClass{ |
| 19 | + |
| 20 | + @Test(priority = 0) |
| 21 | + public void login(){ |
| 22 | + driver.get("http://support.forgeahead.io/login.jsp?os_destination=%2Fsecure%2FDashboard.jspa"); |
| 23 | + WebDriverWait wait = new WebDriverWait(driver,20); |
| 24 | + driver.findElement(By.id("login-form-username")).sendKeys(System.getProperty("username")); |
| 25 | + driver.findElement(By.id("login-form-password")).sendKeys(System.getProperty("password")); |
| 26 | + driver.findElement(By.id("login-form-submit")).click(); |
| 27 | + } |
| 28 | + |
| 29 | + @Test(priority = 1) |
| 30 | + public void updateTickets() throws InterruptedException { |
| 31 | + WebDriverWait wait = new WebDriverWait(driver,20); |
| 32 | + driver.switchTo().frame("gadget-10002"); |
| 33 | + boolean isTrPresent = false; |
| 34 | + if (isTicketEmpty()) { |
| 35 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//table[@id='issuetable']"))); |
| 36 | + isTrPresent = driver.findElement(By.xpath(".//table[@id='issuetable']/tbody/tr")).isDisplayed(); |
| 37 | + } |
| 38 | + while(isTrPresent) { |
| 39 | + List<WebElement> allRows; |
| 40 | + try { |
| 41 | + allRows = driver.findElements(By.xpath(".//table[@id='issuetable']/tbody/tr")); |
| 42 | + }catch (Exception e){ |
| 43 | + break; |
| 44 | + } |
| 45 | + String issueId = allRows.get(0).getAttribute("id"); |
| 46 | + String isLeave = driver.findElement(By.xpath(".//tr[@id='"+issueId+"']//td[@class='nav summary']//a[@class='issue-link']")).getText(); |
| 47 | + if (isLeave.contains("Leave")){ |
| 48 | + driver.findElement(By.xpath(".//tr[@id='"+issueId+"']//td[@class='nav summary']//a[@class='issue-link']")).click(); |
| 49 | + driver.findElement(By.ByClassName.xpath(".//ul[@id='opsbar-opsbar-transitions']//span[text()='Resolve Issue']")).click(); |
| 50 | + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("issue-workflow-transition-submit"))); |
| 51 | + driver.findElement(By.id("issue-workflow-transition-submit")).submit(); |
| 52 | + }else { |
| 53 | + driver.findElement(By.xpath(".//tr[@id='" + issueId + "']//td[@class='nav summary']/p/a[contains(text(),'Automation')]")).click(); |
| 54 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//a[@id='edit-issue']//span[text()='Edit']"))); |
| 55 | + driver.findElement(By.xpath(".//a[@id='edit-issue']//span[text()='Edit']")).click(); |
| 56 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.id("timetracking_originalestimate"))); |
| 57 | + driver.findElement(By.id("timetracking_originalestimate")).click(); |
| 58 | + driver.findElement(By.id("timetracking_originalestimate")).clear(); |
| 59 | + driver.findElement(By.id("timetracking_originalestimate")).sendKeys("1d"); |
| 60 | + driver.findElement(By.id("edit-issue-submit")).submit(); |
| 61 | + |
| 62 | + Thread.sleep(2000); |
| 63 | + |
| 64 | + boolean breakIt = true; |
| 65 | + while (true) { |
| 66 | + breakIt = true; |
| 67 | + try { |
| 68 | + driver.findElement(By.xpath(".//a[@id='opsbar-operations_more']//span[text()='More']")).click(); |
| 69 | + ; |
| 70 | + } catch (Exception e) { |
| 71 | + if (e.getMessage().contains("element is not attached")) { |
| 72 | + breakIt = false; |
| 73 | + } |
| 74 | + } |
| 75 | + if (breakIt) { |
| 76 | + break; |
| 77 | + } |
| 78 | + |
| 79 | + } |
| 80 | + |
| 81 | + if (!driver.findElement(By.id("log-work")).isDisplayed()){ |
| 82 | + driver.findElement(By.xpath(".//a[@id='opsbar-operations_more']//span[text()='More']")).click(); |
| 83 | + } |
| 84 | + driver.findElement(By.id("log-work")).click(); |
| 85 | + Thread.sleep(1000); |
| 86 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.id("log-work-time-logged"))); |
| 87 | + driver.findElement(By.id("log-work-time-logged")).clear(); |
| 88 | + driver.findElement(By.id("log-work-time-logged")).click(); |
| 89 | + driver.findElement(By.id("log-work-time-logged")).sendKeys("1d"); |
| 90 | + driver.findElement(By.id("log-work-submit")).submit(); |
| 91 | + Thread.sleep(1000); |
| 92 | + driver.findElement(By.ByClassName.xpath(".//ul[@id='opsbar-opsbar-transitions']//span[text()='Resolve Issue']")).click(); |
| 93 | + wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("issue-workflow-transition-submit"))); |
| 94 | + driver.findElement(By.id("issue-workflow-transition-submit")).submit(); |
| 95 | + } |
| 96 | + driver.navigate().back(); |
| 97 | + driver.switchTo().frame("gadget-10002"); |
| 98 | + |
| 99 | + if(isTicketEmpty()) { |
| 100 | + wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//table[@id='issuetable']"))); |
| 101 | + isTrPresent = driver.findElement(By.xpath(".//table[@id='issuetable']/tbody/tr")).isDisplayed(); |
| 102 | + }else { |
| 103 | + isTrPresent = false; |
| 104 | + } |
| 105 | + } |
| 106 | + waitOnElement(10,By.id("header-details-user-fullname")); |
| 107 | + driver.findElement(By.id("header-details-user-fullname")).click(); |
| 108 | + waitOnElement(10,By.id("log_out")); |
| 109 | + driver.findElement(By.id("log_out")).click(); |
| 110 | + waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")); |
| 111 | + Assert.assertTrue(waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")),"User in not looged out successfully"); |
| 112 | + System.out.println("Logged Out Successfully"); |
| 113 | + } |
| 114 | + |
| 115 | + @Test(priority = 2) |
| 116 | + public void logout(){ |
| 117 | + /*waitOnElement(10,By.id("header-details-user-fullname")); |
| 118 | + driver.findElement(By.id("header-details-user-fullname")).click(); |
| 119 | + waitOnElement(10,By.id("log_out")); |
| 120 | + driver.findElement(By.id("log_out")).click(); |
| 121 | + waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")); |
| 122 | + Assert.assertTrue(waitOnElement(10,By.xpath("//li[@id='user-options']//a[text()='Log In']")),"User in not looged out successfully"); |
| 123 | + System.out.println("Logged Out Successfully");*/ |
| 124 | + } |
| 125 | + |
| 126 | + public boolean apply(WebElement element) { |
| 127 | + try { |
| 128 | + return !element.isDisplayed(); |
| 129 | + } catch (StaleElementReferenceException elementHasDisappeared) { |
| 130 | + return true; |
| 131 | + } |
| 132 | + } |
| 133 | + |
| 134 | + public boolean isTicketEmpty(){ |
| 135 | + boolean flag = false; |
| 136 | + try{ |
| 137 | + driver.findElement(By.className("empty-results")); |
| 138 | + System.out.println("No more tickets available for resolve"); |
| 139 | + flag = false; |
| 140 | + }catch (Exception e){ |
| 141 | + flag = true; |
| 142 | + } |
| 143 | + return flag; |
| 144 | + } |
| 145 | +} |
0 commit comments