Guest User

Untitled

a guest
Feb 26th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.nio.file.Files;
  3. import java.nio.file.Paths;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.Keys;
  8. import org.openqa.selenium.WebDriver;
  9. import org.openqa.selenium.WebElement;
  10. import org.openqa.selenium.chrome.ChromeDriver;
  11.  
  12. public class InstallServers {
  13.  
  14. WebDriver driver = new ChromeDriver();
  15.  
  16. /* DEV and MR will be parameters for the future */
  17. private String MR = "17.11";
  18. private String env_Name = "QA3";
  19. private String BE_Jira_Version; /* latest pokerbackend version from jira */
  20. private String SE_Jira_Version; /* latest server version from jira */
  21. private String BE_apps_Version; /*
  22. * the installed backend version on the
  23. * environment
  24. */
  25. private String SE_apps_Version; /*
  26. * the installed server version on the
  27. * environment
  28. */
  29.  
  30. @Before
  31. public void getinfo() throws IOException, InterruptedException {
  32. System.setProperty("webdriver.chrome.driver ", "chromedriver.exe");
  33.  
  34. driver.get(
  35. "https://jira.poker.ptec/issues/?jql=issuetype%20%3D%20Build%20and%20component%3Dpokerbackend%20and%20fixVersion%3D17.11");
  36. driver.manage().window().maximize();
  37.  
  38. /* Login into jira using credentials from txt file */
  39. String username = Files.readAllLines(Paths.get("up.txt")).get(0);
  40. String pass = Files.readAllLines(Paths.get("up.txt")).get(1);
  41. driver.findElement(By.id("user-options")).click();
  42. driver.findElement(By.name("os_username")).sendKeys(username);
  43. driver.findElement(By.name("os_password")).sendKeys(pass);
  44. driver.findElement(By.name("login")).click();
  45.  
  46. /* getting the latest BE version */
  47. WebElement BE = driver.findElement(By.xpath("//td[@class='summary']"));
  48. BE_Jira_Version = BE.getText();
  49. System.out.println("Latest BE version is : " + BE_Jira_Version);
  50.  
  51. /* getting latest server_version */
  52. driver.findElement(By.id("advanced-search")).clear();
  53. driver.findElement(By.id("advanced-search"))
  54. .sendKeys("issuetype = Build and component=pokergame and fixVersion=" + MR);
  55. driver.findElement(By.xpath("//span[text()='Search']")).click();
  56. Thread.sleep(2000);
  57. WebElement SE = driver.findElement(By.xpath("//td[@class='summary']"));
  58. SE_Jira_Version = SE.getText();
  59. System.out.println("Latest server version is : " + SE_Jira_Version);
  60.  
  61. /* getting current version of server and BE from poker_apps page */
  62. driver.get("http://bg-hs/poker-versions/");
  63. WebElement BE_apps = driver
  64. .findElement(By.xpath("//td[@site='" + env_Name + "'" + "and @field='poker_backend']"));
  65. BE_apps_Version = BE_apps.getText();
  66. System.out.println("Current BE version is : " + BE_apps_Version);
  67. WebElement SE_apps = driver
  68. .findElement(By.xpath("//td[@site='" + env_Name + "'" + "and @field='poker_servers']"));
  69. SE_apps_Version = SE_apps.getText();
  70. System.out.println("Current Server version is : " + SE_apps_Version);
  71.  
  72. /* All required versions are collected */
  73.  
  74. }
  75.  
  76. public void setBE_version(String BE_Jira_Version) {
  77. this.BE_Jira_Version = BE_Jira_Version;
  78. }
  79.  
  80. public void setSE_version(String SE_Jira_Version) {
  81. this.SE_Jira_Version = SE_Jira_Version;
  82. }
  83.  
  84. public void setBE_App_Version(String BE_apps_Version) {
  85. this.BE_apps_Version = BE_apps_Version;
  86. }
  87.  
  88. public void setSE_App_Version(String SE_apps_Version) {
  89. this.SE_apps_Version = SE_apps_Version;
  90. }
  91.  
  92. @Test
  93. public void Install() throws IOException {
  94. String username = Files.readAllLines(Paths.get("up.txt")).get(0);
  95. String pass = Files.readAllLines(Paths.get("up.txt")).get(1);
  96. driver.get("http://bamboo.poker.ptec/allPlans.action");
  97. driver.findElement(By.id("login")).click();
  98. driver.findElement(By.name("os_username")).sendKeys(username);
  99. driver.findElement(By.name("os_password")).sendKeys(pass);
  100. driver.findElement(By.id("loginForm_save")).click();
  101. driver.findElement(By.id("viewBuild:POKDEP-" + env_Name)).click();
  102. driver.findElement(By.xpath("//button[contains(., 'Action')]")).click();
  103. driver.findElement(By.id("editBuild:POKDEP-" + env_Name)).click();
  104. driver.findElement(By.id("variables_POKDEP-" + env_Name)).click();
  105.  
  106. /* if versions are up to date nothing to update */
  107. if (BE_Jira_Version.equals(BE_apps_Version) & SE_Jira_Version.equals(SE_apps_Version)) {
  108. driver.close();
  109. }
  110.  
  111. /* install all */
  112. if (!BE_Jira_Version.equals(BE_apps_Version) & !SE_Jira_Version.equals(SE_apps_Version)) {
  113.  
  114. }
  115. /* install BE */
  116. if (!BE_Jira_Version.equals(BE_apps_Version)) {
  117.  
  118. WebElement backend_Field = driver.findElement(By.xpath("//td[@data-variable-key='BE_VERSION']//span"));
  119. backend_Field.click();
  120. WebElement backend_Input_Field = driver
  121. .findElement(By.xpath("//td[@data-variable-key='BE_VERSION']//input"));
  122. backend_Input_Field.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  123. backend_Input_Field.sendKeys(BE_Jira_Version);
  124.  
  125. }
  126.  
  127. if (!SE_Jira_Version.equals(SE_apps_Version)) {
  128. /* send version for server */
  129. WebElement server_Field = driver.findElement(By.xpath("//td[@data-variable-key='SERVERS_VERSION']//span"));
  130. server_Field.click();
  131. WebElement server_Input_Feld = driver
  132. .findElement(By.xpath("//td[@data-variable-key='SERVERS_VERSION']//input"));
  133. server_Input_Feld.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  134. server_Input_Feld.sendKeys(SE_Jira_Version);
  135. server_Input_Feld.sendKeys(Keys.ENTER);
  136. /* activate BE field */
  137. WebElement activate_BE = driver.findElement(By.xpath("//td[@data-variable-key='activate_backend']//span"));
  138. activate_BE.click();
  139. WebElement activate_Be_inputField = driver
  140. .findElement(By.xpath("//td[@data-variable-key='activate_backend']//input"));
  141. ;
  142. activate_Be_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  143. activate_Be_inputField.sendKeys("no");
  144. activate_Be_inputField.sendKeys(Keys.ENTER);
  145. /* activate servers input field */
  146. WebElement activate_SE = driver.findElement(By.xpath("//td[@data-variable-key='activate_servers']//span"));
  147. activate_SE.click();
  148. WebElement activate_SE_inputField = driver
  149. .findElement(By.xpath("//td[@data-variable-key='activate_servers']//input"));
  150. ;
  151. activate_SE_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  152. activate_SE_inputField.sendKeys("yes");
  153. activate_SE_inputField.sendKeys(Keys.ENTER);
  154.  
  155. /* install BE field */
  156. WebElement install_BE = driver.findElement(By.xpath("//td[@data-variable-key='install_backend']//span"));
  157. install_BE.click();
  158. WebElement install_BE_inputField = driver
  159. .findElement(By.xpath("//td[@data-variable-key='install_backend']//input"));
  160. ;
  161. install_BE_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  162. install_BE_inputField.sendKeys("no");
  163. install_BE_inputField.sendKeys(Keys.ENTER);
  164.  
  165. /* install scripts */
  166. WebElement install_SCRIPT = driver.findElement(By.xpath("//td[@data-variable-key='install_scripts']//span"));
  167. install_SCRIPT.click();
  168. WebElement install_SCRIPT_inputField = driver.findElement(By.xpath("//td[@data-variable-key='install_scripts']//input"));
  169.  
  170. install_SCRIPT_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  171. install_SCRIPT_inputField.sendKeys("no");
  172. install_SCRIPT_inputField.sendKeys(Keys.ENTER);
  173. /* install servers */
  174. WebElement install_SE = driver.findElement(By.xpath("//td[@data-variable-key='install_servers']//span"));
  175. install_SE.click();
  176. WebElement install_SE_inputField = driver
  177. .findElement(By.xpath("//td[@data-variable-key='install_servers']//input"));
  178. ;
  179. install_SE_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  180. install_SE_inputField.sendKeys("no");
  181. install_SE_inputField.sendKeys(Keys.ENTER);
  182. /*restart servers*/
  183. WebElement restart_SE = driver.findElement(By.xpath("//td[@data-variable-key='install_backend']//span"));
  184. restart_SE.click();
  185. WebElement restart_SE_inputField = driver
  186. .findElement(By.xpath("//td[@data-variable-key='install_backend']//input"));
  187. ;
  188. restart_SE_inputField.sendKeys(Keys.chord(Keys.CONTROL, "a"));
  189. restart_SE_inputField.sendKeys("yes");
  190. restart_SE_inputField.sendKeys(Keys.ENTER);
  191. }
  192.  
  193. }
  194. }
Add Comment
Please, Sign In to add comment