portals-pluto-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asfgr...@apache.org
Subject [12/22] portals-pluto git commit: PLUTO-733 Add Chat Room Demo test
Date Thu, 25 Oct 2018 20:19:44 GMT
PLUTO-733 Add Chat Room Demo test


Project: http://git-wip-us.apache.org/repos/asf/portals-pluto/repo
Commit: http://git-wip-us.apache.org/repos/asf/portals-pluto/commit/cdd72b33
Tree: http://git-wip-us.apache.org/repos/asf/portals-pluto/tree/cdd72b33
Diff: http://git-wip-us.apache.org/repos/asf/portals-pluto/diff/cdd72b33

Branch: refs/heads/master
Commit: cdd72b33a8b8aa4f26193b67a87ff204ca9f9a21
Parents: 3090b95
Author: Kyle Stiemann <stiemannkj1@gmail.com>
Authored: Wed Oct 10 17:06:44 2018 -0400
Committer: Neil Griffin <neil.griffin.scm@gmail.com>
Committed: Thu Oct 25 15:48:30 2018 -0400

----------------------------------------------------------------------
 .../demo/integration/test/ChatRoomDemoIT.java   | 110 +++++++++++++++++++
 1 file changed, 110 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/portals-pluto/blob/cdd72b33/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
----------------------------------------------------------------------
diff --git a/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
new file mode 100644
index 0000000..e3f953c
--- /dev/null
+++ b/demo-integration-tests/src/test/java/org/apache/portals/pluto/demo/integration/test/ChatRoomDemoIT.java
@@ -0,0 +1,110 @@
+/*  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.portals.pluto.demo.integration.test;
+
+import java.io.UnsupportedEncodingException;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+
+import static org.apache.portals.pluto.demo.integration.test.Util.*;
+import static org.openqa.selenium.support.ui.ExpectedConditions.*;
+
+/**
+ *
+ * @author Kyle Stiemann
+ */
+public class ChatRoomDemoIT extends DemoTestDriver {
+   private static final String CHAT_ROOM_PORTLET_NAMESPACE = "Pluto_chatRoomDemo_BeanPortletDemo";
+
+   @Test
+   public void testChatRoomDemos() throws UnsupportedEncodingException {
+      String chatDemoURL = baseUrl + Util.encodeURL("Chat Room Demo");
+      driver.get(chatDemoURL);
+
+      // 1. Clear any previous chat history.
+      clickElement(driver, waitingAsserter, "input", CHAT_ROOM_PORTLET_NAMESPACE, "clear");
+
+      String chatHistoryXpath = "(" + getXpath("div", CHAT_ROOM_PORTLET_NAMESPACE, "chatHistory")
+ ")[1]";
+      waitingAsserter.assertTrue(textEmpty(By.xpath(chatHistoryXpath)));
+
+      // 2. Open a new window/tab to the same page.
+      String originalWindowHandle = driver.getWindowHandle();
+      ((JavascriptExecutor)driver).executeScript("window.open('" + chatDemoURL + "');");
+
+      // 3. In the current window/tab, add a user named "me".
+      // 4. Verify that an image appears for the user.
+      // 5. Send the message "Hello you!".
+      // 6. Verify that the message appears.
+      // 7. Switch to the next window/tab.
+      // 8. Verify that the message from "me" saying "Hello you!" appears.
+      // 9. Add a user named "you".
+      // 10. Verify that an image appears for the user.
+      // 11. Send the message "Hello me!".
+      // 12. Verify that the message appears.
+      By chatHistoryMessageByXpath = By.xpath(chatHistoryXpath + "/p[text()][position() =
last()]");
+      String name = null;
+      String message = null;
+
+      for (String windowHandle : driver.getWindowHandles()) {
+
+         // See #7
+         driver.switchTo().window(windowHandle);
+
+         String originalName = "me";
+         name = originalName;
+         String originalMessage = "Hello you!";
+         message = originalMessage;
+
+         // See #8.
+         if (!originalWindowHandle.equals(windowHandle)) {
+
+            name = "you";
+            message = "Hello me!";
+            assertMessageVisible(chatHistoryMessageByXpath, originalName, originalMessage);
+         }
+
+         // See #3 and #9.
+         String formXpath = getXpath("form", CHAT_ROOM_PORTLET_NAMESPACE, "setParams");
+         sendKeysToElement(driver, waitingAsserter, "(" + formXpath + "//input[@name='name'])[1]",
name);
+         clickElement(driver, waitingAsserter, "(" + formXpath + "//input[@value='send'][@type='submit'])[1]");
+
+         // See #4 and #10.
+         waitingAsserter.assertTrue(elementToBeClickable(By.xpath(
+               getXpath("div", CHAT_ROOM_PORTLET_NAMESPACE, "image") + "/img")));
+
+         // See #5 and #11.
+         String messageInputXpath = "(" + getXpath("input", CHAT_ROOM_PORTLET_NAMESPACE,
"msg") + ")[1]";
+         sendKeysToElement(driver, waitingAsserter, messageInputXpath, message);
+         clickElement(driver, waitingAsserter, "input", CHAT_ROOM_PORTLET_NAMESPACE, "send");
+
+         // See #6 and #12.
+         assertMessageVisible(chatHistoryMessageByXpath, name, message);
+      }
+
+      // 13. Switch back to the original window/tab and verify that the message from "Hello
me!" message appears
+      // there.
+      driver.switchTo().window(originalWindowHandle);
+      assertMessageVisible(chatHistoryMessageByXpath, name, message);
+   }
+
+   private void assertMessageVisible(By locator, String name, String message) {
+      waitingAsserter.assertTrue(and(visibilityOfElementLocated(locator),
+            textToBePresentInElementLocated(locator, name + ": " + message)));
+   }
+}


Mime
View raw message