/portal-web/test/com/liferay/portalweb/plugins/testhook/TearDownPageTest.java

https://github.com/spreddy/liferay-portal · Java · 495 lines · 381 code · 98 blank · 16 comment · 59 complexity · 7cbc23dcb958058605cd3f7a8582f769 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.portalweb.plugins.testhook;
  15. import com.liferay.portalweb.portal.BaseTestCase;
  16. import com.liferay.portalweb.portal.util.RuntimeVariables;
  17. /**
  18. * @author Brian Wing Shun Chan
  19. */
  20. public class TearDownPageTest extends BaseTestCase {
  21. public void testTearDownPage() throws Exception {
  22. int label = 1;
  23. while (label >= 1) {
  24. switch (label) {
  25. case 1:
  26. selenium.open("/web/guest/home/");
  27. selenium.clickAt("//div[@id='dockbar']",
  28. RuntimeVariables.replace("Dockbar"));
  29. for (int second = 0;; second++) {
  30. if (second >= 60) {
  31. fail("timeout");
  32. }
  33. try {
  34. if (selenium.isElementPresent("//div[4]/div/ul/li[1]/a")) {
  35. break;
  36. }
  37. }
  38. catch (Exception e) {
  39. }
  40. Thread.sleep(1000);
  41. }
  42. selenium.saveScreenShotAndSource();
  43. selenium.clickAt("//div[4]/div/ul/li[1]/a",
  44. RuntimeVariables.replace("Manage Pages"));
  45. for (int second = 0;; second++) {
  46. if (second >= 60) {
  47. fail("timeout");
  48. }
  49. try {
  50. if (RuntimeVariables.replace("Public Pages")
  51. .equals(selenium.getText(
  52. "//a[@class='layout-tree']"))) {
  53. break;
  54. }
  55. }
  56. catch (Exception e) {
  57. }
  58. Thread.sleep(1000);
  59. }
  60. selenium.saveScreenShotAndSource();
  61. boolean welcomePresent = selenium.isElementPresent(
  62. "//li/ul/li[1]/div/div[3]/a");
  63. if (welcomePresent) {
  64. label = 2;
  65. continue;
  66. }
  67. selenium.clickAt("//div[@id='_88_layoutsTreeOutput']/ul/li/div/div[1]",
  68. RuntimeVariables.replace("Drop Down Arrow"));
  69. case 2:
  70. for (int second = 0;; second++) {
  71. if (second >= 60) {
  72. fail("timeout");
  73. }
  74. try {
  75. if (RuntimeVariables.replace("Welcome")
  76. .equals(selenium.getText(
  77. "//li/ul/li[1]/div/div[3]/a"))) {
  78. break;
  79. }
  80. }
  81. catch (Exception e) {
  82. }
  83. Thread.sleep(1000);
  84. }
  85. selenium.saveScreenShotAndSource();
  86. boolean page1Present = selenium.isElementPresent(
  87. "//li[2]/div/div[3]/a");
  88. if (!page1Present) {
  89. label = 3;
  90. continue;
  91. }
  92. selenium.clickAt("//li[2]/div/div[3]/a",
  93. RuntimeVariables.replace("Page Name"));
  94. for (int second = 0;; second++) {
  95. if (second >= 60) {
  96. fail("timeout");
  97. }
  98. try {
  99. if (!RuntimeVariables.replace("/home")
  100. .equals(selenium.getValue(
  101. "//input[@id='_88_friendlyURL']"))) {
  102. break;
  103. }
  104. }
  105. catch (Exception e) {
  106. }
  107. Thread.sleep(1000);
  108. }
  109. selenium.saveScreenShotAndSource();
  110. for (int second = 0;; second++) {
  111. if (second >= 60) {
  112. fail("timeout");
  113. }
  114. try {
  115. if (selenium.isVisible("//button[3]")) {
  116. break;
  117. }
  118. }
  119. catch (Exception e) {
  120. }
  121. Thread.sleep(1000);
  122. }
  123. selenium.saveScreenShotAndSource();
  124. assertEquals(RuntimeVariables.replace("Delete"),
  125. selenium.getText("//button[3]"));
  126. selenium.click(RuntimeVariables.replace("//button[3]"));
  127. selenium.waitForPageToLoad("30000");
  128. assertTrue(selenium.getConfirmation()
  129. .matches("^Are you sure you want to delete the selected page[\\s\\S]$"));
  130. selenium.saveScreenShotAndSource();
  131. selenium.clickAt("//div[@id='_88_layoutsTreeOutput']/ul/li/div/div[1]",
  132. RuntimeVariables.replace("Drop Down Arrow"));
  133. for (int second = 0;; second++) {
  134. if (second >= 60) {
  135. fail("timeout");
  136. }
  137. try {
  138. if (RuntimeVariables.replace("Welcome")
  139. .equals(selenium.getText(
  140. "//li/ul/li[1]/div/div[3]/a"))) {
  141. break;
  142. }
  143. }
  144. catch (Exception e) {
  145. }
  146. Thread.sleep(1000);
  147. }
  148. selenium.saveScreenShotAndSource();
  149. boolean page2Present = selenium.isElementPresent(
  150. "//li[2]/div/div[3]/a");
  151. if (!page2Present) {
  152. label = 4;
  153. continue;
  154. }
  155. selenium.clickAt("//li[2]/div/div[3]/a",
  156. RuntimeVariables.replace("Page Name"));
  157. for (int second = 0;; second++) {
  158. if (second >= 60) {
  159. fail("timeout");
  160. }
  161. try {
  162. if (!RuntimeVariables.replace("/home")
  163. .equals(selenium.getValue(
  164. "//input[@id='_88_friendlyURL']"))) {
  165. break;
  166. }
  167. }
  168. catch (Exception e) {
  169. }
  170. Thread.sleep(1000);
  171. }
  172. selenium.saveScreenShotAndSource();
  173. Thread.sleep(5000);
  174. for (int second = 0;; second++) {
  175. if (second >= 60) {
  176. fail("timeout");
  177. }
  178. try {
  179. if (selenium.isVisible("//button[3]")) {
  180. break;
  181. }
  182. }
  183. catch (Exception e) {
  184. }
  185. Thread.sleep(1000);
  186. }
  187. selenium.saveScreenShotAndSource();
  188. assertEquals(RuntimeVariables.replace("Delete"),
  189. selenium.getText("//button[3]"));
  190. selenium.click(RuntimeVariables.replace("//button[3]"));
  191. selenium.waitForPageToLoad("30000");
  192. assertTrue(selenium.getConfirmation()
  193. .matches("^Are you sure you want to delete the selected page[\\s\\S]$"));
  194. selenium.saveScreenShotAndSource();
  195. selenium.clickAt("//div[@id='_88_layoutsTreeOutput']/ul/li/div/div[1]",
  196. RuntimeVariables.replace("Drop Down Arrow"));
  197. for (int second = 0;; second++) {
  198. if (second >= 60) {
  199. fail("timeout");
  200. }
  201. try {
  202. if (RuntimeVariables.replace("Welcome")
  203. .equals(selenium.getText(
  204. "//li/ul/li[1]/div/div[3]/a"))) {
  205. break;
  206. }
  207. }
  208. catch (Exception e) {
  209. }
  210. Thread.sleep(1000);
  211. }
  212. selenium.saveScreenShotAndSource();
  213. boolean page3Present = selenium.isElementPresent(
  214. "//li[2]/div/div[3]/a");
  215. if (!page3Present) {
  216. label = 5;
  217. continue;
  218. }
  219. selenium.clickAt("//li[2]/div/div[3]/a",
  220. RuntimeVariables.replace("Page Name"));
  221. for (int second = 0;; second++) {
  222. if (second >= 60) {
  223. fail("timeout");
  224. }
  225. try {
  226. if (!RuntimeVariables.replace("/home")
  227. .equals(selenium.getValue(
  228. "//input[@id='_88_friendlyURL']"))) {
  229. break;
  230. }
  231. }
  232. catch (Exception e) {
  233. }
  234. Thread.sleep(1000);
  235. }
  236. selenium.saveScreenShotAndSource();
  237. Thread.sleep(5000);
  238. for (int second = 0;; second++) {
  239. if (second >= 60) {
  240. fail("timeout");
  241. }
  242. try {
  243. if (selenium.isVisible("//button[3]")) {
  244. break;
  245. }
  246. }
  247. catch (Exception e) {
  248. }
  249. Thread.sleep(1000);
  250. }
  251. selenium.saveScreenShotAndSource();
  252. assertEquals(RuntimeVariables.replace("Delete"),
  253. selenium.getText("//button[3]"));
  254. selenium.click(RuntimeVariables.replace("//button[3]"));
  255. selenium.waitForPageToLoad("30000");
  256. assertTrue(selenium.getConfirmation()
  257. .matches("^Are you sure you want to delete the selected page[\\s\\S]$"));
  258. selenium.saveScreenShotAndSource();
  259. selenium.clickAt("//div[@id='_88_layoutsTreeOutput']/ul/li/div/div[1]",
  260. RuntimeVariables.replace("Drop Down Arrow"));
  261. for (int second = 0;; second++) {
  262. if (second >= 60) {
  263. fail("timeout");
  264. }
  265. try {
  266. if (RuntimeVariables.replace("Welcome")
  267. .equals(selenium.getText(
  268. "//li/ul/li[1]/div/div[3]/a"))) {
  269. break;
  270. }
  271. }
  272. catch (Exception e) {
  273. }
  274. Thread.sleep(1000);
  275. }
  276. selenium.saveScreenShotAndSource();
  277. boolean page4Present = selenium.isElementPresent(
  278. "//li[2]/div/div[3]/a");
  279. if (!page4Present) {
  280. label = 6;
  281. continue;
  282. }
  283. selenium.clickAt("//li[2]/div/div[3]/a",
  284. RuntimeVariables.replace("Page Name"));
  285. for (int second = 0;; second++) {
  286. if (second >= 60) {
  287. fail("timeout");
  288. }
  289. try {
  290. if (!RuntimeVariables.replace("/home")
  291. .equals(selenium.getValue(
  292. "//input[@id='_88_friendlyURL']"))) {
  293. break;
  294. }
  295. }
  296. catch (Exception e) {
  297. }
  298. Thread.sleep(1000);
  299. }
  300. selenium.saveScreenShotAndSource();
  301. Thread.sleep(5000);
  302. for (int second = 0;; second++) {
  303. if (second >= 60) {
  304. fail("timeout");
  305. }
  306. try {
  307. if (selenium.isVisible("//button[3]")) {
  308. break;
  309. }
  310. }
  311. catch (Exception e) {
  312. }
  313. Thread.sleep(1000);
  314. }
  315. selenium.saveScreenShotAndSource();
  316. assertEquals(RuntimeVariables.replace("Delete"),
  317. selenium.getText("//button[3]"));
  318. selenium.click(RuntimeVariables.replace("//button[3]"));
  319. selenium.waitForPageToLoad("30000");
  320. assertTrue(selenium.getConfirmation()
  321. .matches("^Are you sure you want to delete the selected page[\\s\\S]$"));
  322. selenium.saveScreenShotAndSource();
  323. selenium.clickAt("//div[@id='_88_layoutsTreeOutput']/ul/li/div/div[1]",
  324. RuntimeVariables.replace("Drop Down Arrow"));
  325. for (int second = 0;; second++) {
  326. if (second >= 60) {
  327. fail("timeout");
  328. }
  329. try {
  330. if (RuntimeVariables.replace("Welcome")
  331. .equals(selenium.getText(
  332. "//li/ul/li[1]/div/div[3]/a"))) {
  333. break;
  334. }
  335. }
  336. catch (Exception e) {
  337. }
  338. Thread.sleep(1000);
  339. }
  340. selenium.saveScreenShotAndSource();
  341. boolean page5Present = selenium.isElementPresent(
  342. "//li[2]/div/div[3]/a");
  343. if (!page5Present) {
  344. label = 7;
  345. continue;
  346. }
  347. selenium.clickAt("//li[2]/div/div[3]/a",
  348. RuntimeVariables.replace("Page Name"));
  349. for (int second = 0;; second++) {
  350. if (second >= 60) {
  351. fail("timeout");
  352. }
  353. try {
  354. if (!RuntimeVariables.replace("/home")
  355. .equals(selenium.getValue(
  356. "//input[@id='_88_friendlyURL']"))) {
  357. break;
  358. }
  359. }
  360. catch (Exception e) {
  361. }
  362. Thread.sleep(1000);
  363. }
  364. selenium.saveScreenShotAndSource();
  365. Thread.sleep(5000);
  366. for (int second = 0;; second++) {
  367. if (second >= 60) {
  368. fail("timeout");
  369. }
  370. try {
  371. if (selenium.isVisible("//button[3]")) {
  372. break;
  373. }
  374. }
  375. catch (Exception e) {
  376. }
  377. Thread.sleep(1000);
  378. }
  379. selenium.saveScreenShotAndSource();
  380. assertEquals(RuntimeVariables.replace("Delete"),
  381. selenium.getText("//button[3]"));
  382. selenium.click(RuntimeVariables.replace("//button[3]"));
  383. selenium.waitForPageToLoad("30000");
  384. assertTrue(selenium.getConfirmation()
  385. .matches("^Are you sure you want to delete the selected page[\\s\\S]$"));
  386. selenium.saveScreenShotAndSource();
  387. case 3:
  388. case 4:
  389. case 5:
  390. case 6:
  391. case 7:
  392. case 100:
  393. label = -1;
  394. }
  395. }
  396. }
  397. }