Advertisement
Guest User

Untitled

a guest
Aug 13th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.53 KB | None | 0 0
  1. package com.brite.tests.components.crm;
  2.  
  3. import com.brite.pages.login.LoginPage;
  4. import com.brite.tests.components.login.LoginTests;
  5. import com.brite.utilities.*;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.testng.Assert;
  9. import org.testng.annotations.Test;
  10.  
  11. import java.util.List;
  12.  
  13. public class CRMTests extends TestBase {
  14.  
  15. private static String menuLocator = "//ul[@class='nav navbar-nav navbar-left oe_application_menu_placeholder']//li//a[starts-with(@class,'oe_menu_')]"; //xpath
  16. private static String oppElementLocator = "oe_kanban_color_0 oe_kanban_global_click o_kanban_record ui-sortable-handle"; //class
  17. private static String viewLocator = "//div[@class='btn-group btn-group-sm o_cp_switch_buttons']//button "; //xpath
  18. private static String newButtonLocator = "//table//tr[2]//td[1]"; //xpath
  19. private static String oppLocator = "//a[.='Opportunity']"; //xpath
  20. private static String titleLocator = "//table//tbody//tr[4]//td[1]"; //xpath
  21. private static String valueLocator = "//table//tbody//tr[4]//td[2]"; //xpath
  22. private static String oppTableLocator = "//table//tbody//tr//td[3]"; //xpath
  23. private static String revenueTableLocator = "//table//tbody//tr//td[9]"; //xpath
  24. private static String listButtonLocator = "//button[@accesskey='l']"; //xpath
  25. private static String expectedRevenueTableLocator = "//table//tbody//tr//td[2]"; //xpath
  26. private static String pivotButtonLocator = "//button[@data-view-type='pivot']"; //xpath
  27. private static String crmButtonLocator = "//a[@class='oe_menu_toggler']//span[contains(text(),'CRM')]"; //xpath
  28.  
  29.  
  30.  
  31.  
  32. @Test
  33. public void Test1(){
  34. int waitTime=3;
  35.  
  36. extentLogger = report.createTest("Check Values Report");
  37. //we are instantiating page class inside a tests class,
  38. //because for second test, if we run all tests in a row, driver will have null session
  39. LoginPage loginPage = new LoginPage();
  40. String username = ConfigurationReader.getProperty("username");
  41. String password = ConfigurationReader.getProperty("password");
  42. //extentLogger.info("Clicking on remember me");
  43. //loginPage.clickRememberMe();
  44. loginPage.login(username, password);
  45. //to verify that Discuss/#inbox page opened
  46. //Once page name Discuss displays, means that we have logged in successfully
  47. Assert.assertEquals(BriteUtils.getPageSubTitle(), "#Inbox");
  48. extentLogger.pass("Verified that page name is #Inbox");
  49. // Put all the Menu titles as elements in menuElements List
  50. List<WebElement> menuElements = Driver.getDriver().findElements(By.xpath(menuLocator));
  51. System.out.println(SeleniumUtils.getElementsText(menuElements));
  52.  
  53. // click Menu Item CRM
  54. menuElements.get(4).click();
  55. //SeleniumUtils.waitPlease(waitTime);
  56. BriteUtils.waitUntilLoaderScreenDisappear();
  57. System.out.println(BriteUtils.getPageSubTitle());
  58. Assert.assertEquals("Pipeline", BriteUtils.getPageSubTitle());
  59.  
  60. List<WebElement> oppElements = Driver.getDriver().findElements(By.className(oppElementLocator));
  61. System.out.println(oppElements.size());
  62. if (oppElements.size() < 3) {
  63. createOpp();
  64. }
  65.  
  66. List<WebElement> viewElements = Driver.getDriver().findElements(By.xpath(viewLocator));
  67. System.out.println(viewElements.size());
  68.  
  69. // Go to Pivot view
  70. viewElements.get(3).click();
  71. BriteUtils.waitUntilLoaderScreenDisappear();
  72. //SeleniumUtils.waitPlease(waitTime);
  73.  
  74. // find and click the new button
  75. driver.findElement(By.xpath(newButtonLocator)).click();
  76. BriteUtils.waitUntilLoaderScreenDisappear();
  77.  
  78. // find and click the Opportunity from the popup menu
  79. driver.findElement(By.xpath(oppLocator)).click();
  80. BriteUtils.waitUntilLoaderScreenDisappear();
  81.  
  82. String title = driver.findElement(By.xpath(titleLocator)).getText();
  83. String value = driver.findElement(By.xpath(valueLocator)).getText();
  84.  
  85. System.out.println(title);
  86. System.out.println(value);
  87.  
  88. // go to list view
  89. driver.findElement(By.xpath(listButtonLocator)).click();
  90. BriteUtils.waitUntilLoaderScreenDisappear();
  91.  
  92. // put the Opportunities column elements into a list of Elements
  93. List <WebElement> oppElementList = driver.findElements(By.xpath(oppTableLocator));
  94. // put the Expected Revenue column elements into a list of Elements
  95. List <WebElement> revenueElementList = driver.findElements(By.xpath(revenueTableLocator));
  96.  
  97. // find the Element from the table Opportunities Column that has a text that is equal to title (which was the second item in Pivot View)
  98. // and save its index to location
  99. int location=0;
  100. for (int i=0; i < oppElementList.size();i++){
  101. if (title.equals(oppElementList.get(i).getText())){
  102. location=i;
  103. }
  104. }
  105. // compare the value (which was the second item's value in Pivot View) with same item's value in the list view
  106. Assert.assertEquals(value, revenueElementList.get(location).getText());
  107. SeleniumUtils.waitPlease(5);
  108. }
  109.  
  110.  
  111. @Test
  112. public void Test2(){
  113. int waitTime=2;
  114.  
  115. extentLogger = report.createTest("Sum of Values Report");
  116. //we are instantiating page class inside a tests class,
  117. //because for second test, if we run all tests in a row, driver will have null session
  118. LoginPage loginPage = new LoginPage();
  119. String username = ConfigurationReader.getProperty("username");
  120. String password = ConfigurationReader.getProperty("password");
  121. //extentLogger.info("Clicking on remember me");
  122. //loginPage.clickRememberMe();
  123. loginPage.login(username, password);
  124. //to verify that Discuss/#inbox page opened
  125. //Once page name Discuss displays, means that we have logged in successfully
  126. Assert.assertEquals(BriteUtils.getPageSubTitle(), "#Inbox");
  127. extentLogger.pass("Verified that page name is #Inbox");
  128. // Put all the Menu titles as elements in menuElements List
  129. // List<WebElement> menuElements = Driver.getDriver().findElements(By.xpath(menuLocator));
  130. // System.out.println(SeleniumUtils.getElementsText(menuElements));
  131.  
  132. // click Menu Item CRM
  133. // menuElements.get(4).click();
  134. driver.findElement(By.xpath(crmButtonLocator)).click();
  135. //SeleniumUtils.waitPlease(waitTime);
  136. BriteUtils.waitUntilLoaderScreenDisappear();
  137. System.out.println(BriteUtils.getPageSubTitle());
  138.  
  139. Assert.assertEquals("Pipeline", BriteUtils.getPageSubTitle());
  140.  
  141. // List<WebElement> oppElements = Driver.getDriver().findElements(By.className(oppElementLocator));
  142. // System.out.println(oppElements.size());
  143. // if (oppElements.size() < 3) {
  144. // createOpp();
  145. // }
  146.  
  147. // List<WebElement> viewElements = Driver.getDriver().findElements(By.xpath(viewLocator));
  148. // System.out.println(viewElements.size());
  149.  
  150. // Go to Pivot view
  151. // viewElements.get(3).click();
  152. driver.findElement(By.xpath(pivotButtonLocator)).click();
  153. BriteUtils.waitUntilLoaderScreenDisappear();
  154. //SeleniumUtils.waitPlease(waitTime);
  155.  
  156. // find and click the new button
  157. driver.findElement(By.xpath(newButtonLocator)).click();
  158. BriteUtils.waitUntilLoaderScreenDisappear();
  159.  
  160. // find and click the Opportunity from the popup menu
  161. driver.findElement(By.xpath(oppLocator)).click();
  162. BriteUtils.waitUntilLoaderScreenDisappear();
  163.  
  164.  
  165. List<WebElement> expectedRevenueList = Driver.getDriver().findElements(By.xpath(expectedRevenueTableLocator));
  166.  
  167. double sum = Double.valueOf(expectedRevenueList.get(0).getText().replaceAll(",",""));
  168. double total=0;
  169. for (int i=2; i < expectedRevenueList.size();i++){
  170. total = total + Double.valueOf(expectedRevenueList.get(i).getText().replaceAll(",",""));
  171. }
  172.  
  173. System.out.println("Sum : " + sum);
  174. System.out.println("Total : " + total);
  175.  
  176. int dotLocation = String.valueOf(sum).indexOf(".");
  177. String strSum = String.valueOf(sum).substring(0,dotLocation+3);
  178. dotLocation = String.valueOf(total).indexOf(".");
  179. String strTotal = String.valueOf(total).substring(0,dotLocation+3);
  180. System.out.println("Sum : " + strSum);
  181. System.out.println("Total : " + strTotal);
  182. Assert.assertEquals(strSum, strTotal);
  183.  
  184. //SeleniumUtils.waitPlease(5);
  185. }
  186.  
  187.  
  188.  
  189. public void createOpp(){
  190.  
  191. }
  192.  
  193.  
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement