Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.86 KB | None | 0 0
  1. package pageObjects.Utils;
  2.  
  3. import com.sforce.trailhead.tcdev.pages.AbstractPage;
  4. import com.sforce.trailhead.tcdev.util.WebDriverUtils;
  5. import org.apache.commons.lang3.ObjectUtils;
  6. import org.openqa.selenium.support.ui.WebDriverWait;
  7. import org.openqa.selenium.support.ui.Select;
  8.  
  9. import java.time.Duration;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import com.sforce.trailhead.tcdev.pages.AbstractPage;
  13. import com.sforce.trailhead.tcdev.util.WebDriverUtils;
  14.  
  15. import org.openqa.selenium.By;
  16. import org.openqa.selenium.Keys;
  17. import org.openqa.selenium.WebDriver;
  18. import org.openqa.selenium.WebElement;
  19. import com.sforce.trailhead.tcdev.pages.AbstractPage;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.JavascriptExecutor;
  22. import org.openqa.selenium.WebDriver;
  23. import org.openqa.selenium.WebElement;
  24. import org.openqa.selenium.support.ui.ExpectedConditions;
  25. import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;
  26. import org.openqa.selenium.*;
  27. import org.openqa.selenium.support.ui.ExpectedConditions;
  28. import org.openqa.selenium.support.ui.FluentWait;
  29. import pageObjects.Common.LeftPanel;
  30.  
  31.  
  32. /**
  33. * Page Object for common elements in Superbadges flows
  34. */
  35. public class Common extends AbstractPage {
  36.  
  37. public Common(WebDriver driver) {
  38. super(driver);
  39. }
  40.  
  41. WebDriverWait wait = new WebDriverWait(driver, 30);
  42.  
  43.  
  44. public static final Duration SHORT_TIMEOUT = Duration.ofSeconds(3);
  45. public static final Duration MID_TIMEOUT = Duration.ofSeconds(10);
  46. public static final Duration LONG_TIMEOUT = Duration.ofSeconds(30);
  47.  
  48. private String SEARCH_TEXT = "";
  49.  
  50. // ---------------------------------------------------------------
  51. // Strings
  52. // ---------------------------------------------------------------
  53.  
  54.  
  55.  
  56. // ---------------------------------------------------------------
  57. // Locators
  58. // ---------------------------------------------------------------
  59. By IFRAME = By.cssSelector("iframe");
  60.  
  61. // BUTTON "NEXT" 1: input.btn
  62. By BUTTON_NEXT01 = By.cssSelector("div.pbWizardFooter div input.btn");
  63.  
  64. // BUTTON "NEXT" 2: div input:nth-child(2)
  65. By BUTTON_NEXT02 = By.cssSelector("div.pbWizardFooter input:nth-child(2)");
  66.  
  67. // BUTTON "NEW" in Fields and Relationships within an Object
  68. By BUTTON_NEW = By.cssSelector(".slds-grid.slds-align-top div button:nth-child(1)");
  69.  
  70. // BUTTON "New" in Fields and Relationships within an Object
  71. By BUTTON_NEW02 = By.cssSelector("div.slds-col.slds-no-flex.slds-grid.slds-align-top button:nth-child(1)");
  72.  
  73. // BUTTON "SAVE", when creating New custom field
  74. By BUTTON_SAVE_CUSTOM_FIELD = By.cssSelector("div.pbWizardHeader div input:nth-child(3)");
  75.  
  76. // OBJECT "Account" in: Object Manager > Objects and Fields
  77. By ACCOUNT_OBJECT = By.partialLinkText("Account");
  78.  
  79. // OBJECT "Opportunity" in: Object Manager > Objects and Fields
  80. By OPPORTUNITY_OBJECT = By.linkText("Opportunity");
  81.  
  82. // CUSTOM OBJECT "Robot Setup" in: Objects and Fields > Object Manager
  83. By ROBOT_SETUP_OBJECT = By.linkText("Robot Setup");
  84.  
  85. // TEXT BOX "Field Label" in: New custom field / New custom object
  86. By MASTER_LABEL_TEXTBOX = By.id("MasterLabel");
  87.  
  88. // TEXT BOX "Field Name" in: New custom field / New custom object
  89. By FIELD_NAME = By.id("DeveloperName");
  90.  
  91. // TEXT BOX "Plural Label" in: New custom object
  92. By PLURAL_LABEL_TEXTBOX = By.id("PluralLabel");
  93.  
  94. // By SEARCH_ITEM = By.cssSelector("[title='"+ SEARCH_TEXT +"'] mark");
  95.  
  96. // ---------------------------------------------------------------
  97. // WebElements
  98. // ---------------------------------------------------------------
  99. public WebElement iframe(){
  100. wait.until(ExpectedConditions.visibilityOfElementLocated(IFRAME));
  101. return driver.findElement(IFRAME);
  102. }
  103.  
  104. public WebElement button_Next01(){
  105. wait.until(ExpectedConditions.visibilityOfElementLocated(BUTTON_NEXT01));
  106. return driver.findElement(BUTTON_NEXT01);
  107. }
  108.  
  109. public WebElement button_Next02(){
  110. wait.until(ExpectedConditions.visibilityOfElementLocated(BUTTON_NEXT02));
  111. return driver.findElement(BUTTON_NEXT02);
  112. }
  113.  
  114. public WebElement button_New(){
  115. wait.until(ExpectedConditions.visibilityOfElementLocated(BUTTON_NEW));
  116. return driver.findElement(BUTTON_NEW);
  117. }
  118.  
  119. public WebElement button_New02(){
  120. wait.until(ExpectedConditions.visibilityOfElementLocated(BUTTON_NEW02));
  121. return driver.findElement(BUTTON_NEW02);
  122. }
  123.  
  124. public WebElement button_SaveCustomField(){
  125. wait.until(ExpectedConditions.visibilityOfElementLocated(BUTTON_SAVE_CUSTOM_FIELD));
  126. return driver.findElement(BUTTON_SAVE_CUSTOM_FIELD);
  127. }
  128.  
  129. public WebElement account_Object(){
  130. wait.until(ExpectedConditions.visibilityOfElementLocated(ACCOUNT_OBJECT));
  131. return driver.findElement(ACCOUNT_OBJECT);
  132. }
  133.  
  134. public WebElement opportunity_Object(){
  135. wait.until(ExpectedConditions.visibilityOfElementLocated(OPPORTUNITY_OBJECT));
  136. return driver.findElement(OPPORTUNITY_OBJECT);
  137. }
  138.  
  139. public WebElement robotSetup_Object(){
  140. wait.until(ExpectedConditions.visibilityOfElementLocated(ROBOT_SETUP_OBJECT));
  141. return driver.findElement(ROBOT_SETUP_OBJECT);
  142. }
  143.  
  144. public WebElement masterLabel_Textbox(){
  145. wait.until(ExpectedConditions.visibilityOfElementLocated(MASTER_LABEL_TEXTBOX));
  146. return driver.findElement(MASTER_LABEL_TEXTBOX);
  147. }
  148.  
  149. public WebElement fieldName_Textbox(){
  150. wait.until(ExpectedConditions.visibilityOfElementLocated(FIELD_NAME));
  151. return driver.findElement(FIELD_NAME);
  152. }
  153.  
  154. public WebElement pluralLabel_Textbox(){
  155. wait.until(ExpectedConditions.visibilityOfElementLocated(PLURAL_LABEL_TEXTBOX));
  156. return driver.findElement(PLURAL_LABEL_TEXTBOX);
  157. }
  158.  
  159. // public WebElement searchItem(String searchText){
  160. // wait.until(ExpectedConditions.visibilityOfElementLocated(SEARCH_ITEM));
  161. // return driver.findElement(SEARCH_ITEM);
  162. // }
  163.  
  164.  
  165. // ---------------------------------------------------------------
  166. // Actions on WebElements
  167. // ---------------------------------------------------------------
  168. public void clickNextButton01(){
  169. WebElement elem = this.button_Next01();
  170. elem.click();
  171. }
  172.  
  173. public void clickNextButton02(){
  174. WebElement elem = this.button_Next02();
  175. elem.click();
  176. }
  177.  
  178. public void clickNewButton(){
  179. WebElement elem = this.button_New();
  180. elem.click();
  181. }
  182.  
  183. public void clickNewButton02(){
  184. WebElement elem = this.button_New02();
  185. elem.click();
  186. }
  187.  
  188. public void clickSaveCustomField(){
  189. WebElement elem = this.button_SaveCustomField();
  190. elem.click();
  191. }
  192.  
  193. public void clickAccountObject(){
  194. WebElement elem = this.account_Object();
  195. elem.click();
  196. }
  197.  
  198. public void clickOpportunityObject(){
  199. WebElement elem = this.opportunity_Object();
  200. elem.click();
  201. }
  202.  
  203. public void clickRobotSetupObject(){
  204. WebElement elem = this.robotSetup_Object();
  205. elem.click();
  206. }
  207.  
  208. public void clickMasterLabelTextbox(){
  209. WebElement elem = this.masterLabel_Textbox();
  210. elem.click();
  211. }
  212.  
  213. public void clickFieldNameTextbox(){
  214. WebElement elem = this.fieldName_Textbox();
  215. elem.click();
  216. }
  217.  
  218. public void clickPluralLabelTextbox(){
  219. WebElement elem = this.pluralLabel_Textbox();
  220. elem.click();
  221. }
  222.  
  223. // public void clickSearchItem(){
  224. // WebElement elem = this.searchItem(SEARCH_TEXT);
  225. // elem.click();
  226. // }
  227.  
  228.  
  229. // ---------------------------------------------------------------
  230. // Methods
  231. // ---------------------------------------------------------------
  232. public void quickFindSearchAndSelect(String searchText) {
  233.  
  234. LeftPanel leftPanel = new LeftPanel(driver);
  235. // SEARCH_TEXT = searchText;
  236.  
  237. ArrayList tabs = new ArrayList(driver.getWindowHandles());
  238. driver.switchTo().window((String) tabs.get(1));
  239.  
  240. // WebElement quickFindText = WebDriverUtils.findElement(driver, By.cssSelector("[placeholder=\"Quick Find\"]"));
  241. leftPanel.quickFind_Searchbox().clear();
  242. leftPanel.quickFind_Searchbox().sendKeys(searchText);
  243.  
  244. //WebElement searchItem = WebDriverUtils.findElement(driver, By.cssSelector("[title='"+ searchText +"'] mark"));// ?????????????
  245. WebElement searchItem = leftPanel.searchItem(searchText);
  246. leftPanel.clickQuickFind_Item(searchText);
  247.  
  248. logger.info("Navigating to "+ searchText +"...");
  249. // WebDriverUtils.click(driver, By.cssSelector("[title='"+ searchText +"'] mark"));
  250. leftPanel.clickQuickFind_Item(searchText);// searchItem.click();
  251.  
  252. //WebElement iframe = WebDriverUtils.findElement(driver, By.cssSelector("iframe"), Duration.ofSeconds(20));
  253. driver.switchTo().frame(this.iframe());
  254. }
  255.  
  256. public void quickFindSearchAndSelects(String searchText) {
  257.  
  258. ArrayList tabs = new ArrayList(driver.getWindowHandles());
  259. driver.switchTo().window((String) tabs.get(1));
  260. //waitFor(2000);
  261. WebElement quickFindText = WebDriverUtils.findElement(driver, By.cssSelector("[placeholder=\"Quick Find\"]"));
  262. quickFindText.clear();
  263. quickFindText.sendKeys(searchText);
  264. WebElement searchItem = WebDriverUtils.findElement(driver, By.cssSelector("[title='"+ searchText +"'] mark"));
  265.  
  266. logger.info("Navigating to "+ searchText +"...");
  267. WebDriverUtils.click(driver, By.cssSelector("[title='"+ searchText +"'] mark"));
  268. WebElement iframe = WebDriverUtils.findElement(driver, By.cssSelector("iframe"), Duration.ofSeconds(20));
  269. driver.switchTo().frame(iframe);
  270. }
  271.  
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement