diff options
author | Artur Signell <artur@vaadin.com> | 2013-09-16 14:44:43 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-09-25 11:22:28 +0000 |
commit | a2daf65958c602dd02099bf4415e7e432b706dc7 (patch) | |
tree | 357c599a8249f887fa8a4da62e780c8c6cc7576a /uitest | |
parent | 1df28c314141d7531591ff9c5ee1ab3521f29e8c (diff) | |
download | vaadin-framework-a2daf65958c602dd02099bf4415e7e432b706dc7.tar.gz vaadin-framework-a2daf65958c602dd02099bf4415e7e432b706dc7.zip |
Converted TB2 push tests to TB3 (#12580)
Change-Id: Ifd6286aee75946eb47c39886c08473a5a0c10545
Diffstat (limited to 'uitest')
25 files changed, 799 insertions, 792 deletions
diff --git a/uitest/src/com/vaadin/tests/components/ui/UiAccess.java b/uitest/src/com/vaadin/tests/components/ui/UIAccess.java index 09f2fd8816..057dcaa917 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UiAccess.java +++ b/uitest/src/com/vaadin/tests/components/ui/UIAccess.java @@ -21,17 +21,48 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.locks.ReentrantLock; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinSession; import com.vaadin.shared.communication.PushMode; import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.UI; import com.vaadin.util.CurrentInstance; -public class UiAccess extends AbstractTestUIWithLog { +public class UIAccess extends AbstractTestUIWithLog { + + public static class UIAccessTest extends MultiBrowserTest { + @Override + protected boolean isPushEnabled() { + return true; + } + + @Test + public void testThreadLocals() { + getCurrentInstanceWhenPushingButton().click(); + waitUntil(ExpectedConditions.textToBePresentInElement( + vaadinLocatorById("Log_row_0"), "1.")); + Assert.assertEquals( + "0. Current UI matches in beforeResponse? true", + vaadinElementById("Log_row_1").getText()); + Assert.assertEquals( + "1. Current session matches in beforeResponse? true", + vaadinElementById("Log_row_0").getText()); + + } + + private WebElement getCurrentInstanceWhenPushingButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]"); + } + } private volatile boolean checkCurrentInstancesBeforeResponse = false; diff --git a/uitest/src/com/vaadin/tests/components/ui/UiAccessPush.html b/uitest/src/com/vaadin/tests/components/ui/UiAccessPush.html deleted file mode 100644 index bc29534ee4..0000000000 --- a/uitest/src/com/vaadin/tests/components/ui/UiAccessPush.html +++ /dev/null @@ -1,41 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.components.ui.UiAccess?restartApplication&transport=websocket</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUiAccess::/VVerticalLayout[0]/Slot[2]/VVerticalLayout[0]/Slot[7]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>waitForNotText</td> - <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_0</td> - <td>exact:1. Current session matches in beforeResponse? true</td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUiAccess::PID_SLog_row_1</td> - <td>exact:0. Current UI matches in beforeResponse? true</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/BarInUIDL.html b/uitest/src/com/vaadin/tests/push/BarInUIDL.html deleted file mode 100644 index 66f03158b6..0000000000 --- a/uitest/src/com/vaadin/tests/push/BarInUIDL.html +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.BarInUIDL?restartApplication</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>Thank you for clicking | bar</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBarInUIDL::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]</td> - <td>Thank you for clicking | bar</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/BarInUIDL.java b/uitest/src/com/vaadin/tests/push/BarInUIDL.java index 7e414cc89d..ef2568bebe 100644 --- a/uitest/src/com/vaadin/tests/push/BarInUIDL.java +++ b/uitest/src/com/vaadin/tests/push/BarInUIDL.java @@ -16,14 +16,44 @@ package com.vaadin.tests.push; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.annotations.Push; import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ui.Transport; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; +@Push(transport = Transport.STREAMING) public class BarInUIDL extends AbstractTestUI { + public static class BarInUIDLTest extends MultiBrowserTest { + @Test + public void sendBarInUIDL() { + getButton().click(); + Assert.assertEquals( + "Thank you for clicking | bar", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]") + .getText()); + getButton().click(); + Assert.assertEquals( + "Thank you for clicking | bar", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VLabel[0]") + .getText()); + } + + private WebElement getButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]"); + } + } + /* * (non-Javadoc) * diff --git a/uitest/src/com/vaadin/tests/push/BasicPush.html b/uitest/src/com/vaadin/tests/push/BasicPush.html deleted file mode 100644 index 173ec90674..0000000000 --- a/uitest/src/com/vaadin/tests/push/BasicPush.html +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.BasicPush?restartApplication&debug</td> - <td></td> -</tr> -<!--Test client initiated push --> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>0</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>1</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>4</td> -</tr> -<!--Test server initiated push--> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>0</td> -</tr> -<tr> - <td>pause</td> - <td>3000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>1</td> -</tr> -<tr> - <td>pause</td> - <td>3000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>2</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/BasicPush.java b/uitest/src/com/vaadin/tests/push/BasicPush.java index b80d287a1d..1f184863f7 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPush.java +++ b/uitest/src/com/vaadin/tests/push/BasicPush.java @@ -1,40 +1,115 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; -import java.util.Date; import java.util.Timer; import java.util.TimerTask; -import com.vaadin.annotations.Widgetset; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.annotations.Push; import com.vaadin.data.util.ObjectProperty; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; -@Widgetset(TestingWidgetSet.NAME) +@Push public class BasicPush extends AbstractTestUI { + public static abstract class BasicPushTest extends MultiBrowserTest { + + @Test + public void testPush() { + // Test client initiated push + Assert.assertEquals(0, getClientCounter()); + getIncrementButton().click(); + Assert.assertEquals( + "Client counter not incremented by button click", 1, + getClientCounter()); + getIncrementButton().click(); + getIncrementButton().click(); + getIncrementButton().click(); + Assert.assertEquals( + "Four clicks should have incremented counter to 4", 4, + getClientCounter()); + + // Test server initiated push + getServerCounterStartButton().click(); + try { + Assert.assertEquals(0, getServerCounter()); + sleep(3000); + int serverCounter = getServerCounter(); + if (serverCounter < 1) { + // No push has happened + Assert.fail("No push has occured within 3s"); + } + sleep(3000); + if (getServerCounter() <= serverCounter) { + // No push has happened + Assert.fail("Only one push took place within 6s"); + + } + } finally { + // Avoid triggering push assertions + getServerCounterStopButton().click(); + } + } + + private int getServerCounter() { + return Integer.parseInt(getServerCounterElement().getText()); + } + + private int getClientCounter() { + return Integer.parseInt(getClientCounterElement().getText()); + } + + private WebElement getServerCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]"); + } + + private WebElement getServerCounterStartButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getServerCounterStopButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[6]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getIncrementButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getClientCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]"); + } + } + private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); private final Timer timer = new Timer(true); - private final TimerTask task = new TimerTask() { - - @Override - public void run() { - access(new Runnable() { - @Override - public void run() { - counter2.setValue(counter2.getValue() + 1); - } - }); - } - }; + private TimerTask task; @Override protected void setup(VaadinRequest request) { @@ -65,11 +140,37 @@ public class BasicPush extends AbstractTestUI { lbl.setCaption("Server counter (updates each 3s by server thread) :"); addComponent(lbl); - addComponent(new Button("Reset", new Button.ClickListener() { + addComponent(new Button("Start timer", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { counter2.setValue(0); + if (task != null) { + task.cancel(); + } + task = new TimerTask() { + + @Override + public void run() { + access(new Runnable() { + @Override + public void run() { + counter2.setValue(counter2.getValue() + 1); + } + }); + } + }; + timer.scheduleAtFixedRate(task, 3000, 3000); + } + })); + + addComponent(new Button("Stop timer", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + if (task != null) { + task.cancel(); + task = null; + } } })); } @@ -94,7 +195,6 @@ public class BasicPush extends AbstractTestUI { @Override public void attach() { super.attach(); - timer.scheduleAtFixedRate(task, new Date(), 3000); } @Override diff --git a/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java b/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java index 37a8afd819..29534e1f5c 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushStreaming.java @@ -1,12 +1,42 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; +import org.junit.Test; + import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.Transport; @Push(transport = Transport.STREAMING) public class BasicPushStreaming extends BasicPush { @Override - protected void setup(com.vaadin.server.VaadinRequest request) { - addComponent(new PushConfigurator(this)); + public void init(VaadinRequest request) { + super.init(request); + // Don't use fallback so we can easier detect if streaming fails + getPushConfiguration().setFallbackTransport(Transport.STREAMING); + } + + public static class BasicPushStreamingTest extends BasicPushTest { + @Override + @Test + public void testPush() { + super.testPush(); + } + } + } diff --git a/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java b/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java index 6fc27e8974..4765183fca 100644 --- a/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java +++ b/uitest/src/com/vaadin/tests/push/BasicPushWebsocket.java @@ -1,8 +1,44 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; +import java.util.Collection; + +import org.openqa.selenium.remote.DesiredCapabilities; + import com.vaadin.annotations.Push; +import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.ui.Transport; +import com.vaadin.tests.tb3.WebsocketTest; @Push(transport = Transport.WEBSOCKET) public class BasicPushWebsocket extends BasicPush { + + @Override + public void init(VaadinRequest request) { + super.init(request); + // Don't use fallback so we can easier detect if websocket fails + getPushConfiguration().setFallbackTransport(Transport.WEBSOCKET); + } + + public static class BasicPushWebsocketTest extends BasicPushTest { + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return WebsocketTest.getWebsocketBrowsers(); + } + } + } diff --git a/uitest/src/com/vaadin/tests/push/PushConfiguration.html b/uitest/src/com/vaadin/tests/push/PushConfiguration.html deleted file mode 100644 index c3786b1cc1..0000000000 --- a/uitest/src/com/vaadin/tests/push/PushConfiguration.html +++ /dev/null @@ -1,130 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<!--Websocket--> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]</td> - <td>label=WEBSOCKET</td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td> - <td>label=AUTOMATIC</td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]</td> - <td>*fallbackTransport: streaming*transport: websocket*</td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>waitForText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<!--Use debug console to verify we used the correct transport type--> -<tr> - <td>assertTextPresent</td> - <td>Push connection established using websocket</td> - <td></td> -</tr> -<tr> - <td>assertTextNotPresent</td> - <td>Push connection established using streaming</td> - <td>Push connection established using streaming</td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td> - <td>label=DISABLED</td> -</tr> -<!--Streaming--> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.push.PushConfigurationTest?debug&restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]</td> - <td>label=STREAMING</td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td> - <td>label=AUTOMATIC</td> -</tr> -<tr> - <td>assertNotText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]</td> - <td>*fallbackTransport: streaming*transport: streaming*</td> -</tr> -<tr> - <td>waitForText</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]</td> - <td>4</td> -</tr> -<!--Use debug console to verify we used the correct transport type--> -<tr> - <td>assertTextNotPresent</td> - <td>Push connection established using websocket</td> - <td></td> -</tr> -<tr> - <td>assertTextPresent</td> - <td>Push connection established using streaming</td> - <td></td> -</tr> -<tr> - <td>select</td> - <td>vaadin=runcomvaadintestspushPushConfigurationTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]</td> - <td>label=DISABLED</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java index b57e9732cc..f4a537392d 100644 --- a/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java +++ b/uitest/src/com/vaadin/tests/push/PushConfigurationTest.java @@ -1,19 +1,132 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; import java.util.Date; import java.util.Timer; import java.util.TimerTask; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + import com.vaadin.data.util.ObjectProperty; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.ui.label.ContentMode; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.tb3.WebsocketTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Label; public class PushConfigurationTest extends AbstractTestUI { + public static class PushConfigurationWebsocket extends WebsocketTest { + + @Override + protected boolean isDebug() { + return true; + } + + @Test + public void testWebsocketAndStreaming() { + // Websocket + Assert.assertEquals(1, getServerCounter()); + new Select(getTransportSelect()).selectByVisibleText("WEBSOCKET"); + new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); + Assert.assertTrue(vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]") + .getText() + .matches( + "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: websocket[\\s\\S]*$")); + int counter = getServerCounter(); + + for (int second = 0;; second++) { + if (second >= 5) { + Assert.fail("timeout"); + } + if (getServerCounter() >= (counter + 2)) { + break; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + + // Use debug console to verify we used the correct transport type + Assert.assertTrue(driver.getPageSource().contains( + "Push connection established using websocket")); + Assert.assertFalse(driver.getPageSource().contains( + "Push connection established using streaming")); + + new Select(getPushModeSelect()).selectByVisibleText("DISABLED"); + + // Streaming + driver.get(getTestUrl()); + Assert.assertEquals(1, getServerCounter()); + + new Select(getTransportSelect()).selectByVisibleText("STREAMING"); + new Select(getPushModeSelect()).selectByVisibleText("AUTOMATIC"); + Assert.assertTrue(vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[5]/VLabel[0]/domChild[0]") + .getText() + .matches( + "^[\\s\\S]*fallbackTransport: streaming[\\s\\S]*transport: streaming[\\s\\S]*$")); + + counter = getServerCounter(); + for (int second = 0;; second++) { + if (second >= 5) { + Assert.fail("timeout"); + } + if (getServerCounter() >= (counter + 2)) { + break; + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + + // Use debug console to verify we used the correct transport type + Assert.assertFalse(driver.getPageSource().contains( + "Push connection established using websocket")); + Assert.assertTrue(driver.getPageSource().contains( + "Push connection established using streaming")); + + } + + private WebElement getPushModeSelect() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VNativeSelect[0]/domChild[0]"); + } + + private WebElement getTransportSelect() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[0]/VVerticalLayout[0]/Slot[1]/VNativeSelect[0]/domChild[0]"); + } + + private int getServerCounter() { + return Integer.parseInt(getServerCounterElement().getText()); + } + + private WebElement getServerCounterElement() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VLabel[0]"); + } + } + private ObjectProperty<Integer> counter = new ObjectProperty<Integer>(0); private ObjectProperty<Integer> counter2 = new ObjectProperty<Integer>(0); diff --git a/uitest/src/com/vaadin/tests/push/PushFromInit.html b/uitest/src/com/vaadin/tests/push/PushFromInit.html deleted file mode 100644 index d009eb3baf..0000000000 --- a/uitest/src/com/vaadin/tests/push/PushFromInit.html +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.PushFromInit?debug&restartApplication</td> - <td></td> -</tr> -<tr> - <td>waitForText</td> - <td>vaadin=runpushcomvaadintestspushPushFromInit::PID_SLog_row_1</td> - <td>1. Logged in init</td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushPushFromInit::PID_SLog_row_0</td> - <td>2. Logged from background thread started in init</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/PushFromInit.java b/uitest/src/com/vaadin/tests/push/PushFromInit.java index 4b442de499..000d5c0bce 100644 --- a/uitest/src/com/vaadin/tests/push/PushFromInit.java +++ b/uitest/src/com/vaadin/tests/push/PushFromInit.java @@ -1,11 +1,57 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; +import org.junit.Assert; +import org.junit.Test; + import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; public class PushFromInit extends AbstractTestUIWithLog { + public static class PushFromInitTB3 extends MultiBrowserTest { + @Test + public void testPushFromInit() { + for (int second = 0;; second++) { + if (second >= 30) { + Assert.fail("timeout"); + } + try { + if ("1. Logged in init".equals(vaadinElementById( + "Log_row_1").getText())) { + break; + } + } catch (Exception e) { + } + try { + Thread.sleep(200); + } catch (InterruptedException e) { + } + } + + Assert.assertEquals( + "2. Logged from background thread started in init", + vaadinElementById("Log_row_0").getText()); + + } + } + @Override protected void setup(VaadinRequest request) { new Thread() { diff --git a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.html b/uitest/src/com/vaadin/tests/push/PushReattachedComponent.html deleted file mode 100644 index e1f6a5f048..0000000000 --- a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.html +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://192.168.2.162:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.components.panel.PanelChangeContents?restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>stats</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>companies</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestscomponentspanelPanelChangeContents::/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>stats</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java b/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java new file mode 100644 index 0000000000..35934273a4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/push/PushReattachedComponent.java @@ -0,0 +1,65 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.components.panel.PanelChangeContents; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PushReattachedComponent extends MultiBrowserTest { + + @Override + protected boolean isPushEnabled() { + return true; + } + + @Override + protected Class<?> getUIClass() { + return PanelChangeContents.class; + } + + @Test + public void testReattachComponentUsingPush() { + Assert.assertEquals( + "stats", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText()); + vaadinElement( + "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]") + .click(); + Assert.assertEquals( + "companies", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText()); + vaadinElement( + "/VVerticalLayout[0]/Slot[0]/VHorizontalLayout[0]/Slot[0]/VButton[0]/domChild[0]/domChild[0]") + .click(); + Assert.assertEquals( + "stats", + vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VPanel[0]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText()); + + } +} diff --git a/uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html b/uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html deleted file mode 100644 index 854dd458bb..0000000000 --- a/uitest/src/com/vaadin/tests/push/PushTransportAnnotation.html +++ /dev/null @@ -1,46 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.push.BasicPushStreaming?debug&restartApplication</td> - <td></td> -</tr> -<tr> - <td>waitForTextPresent</td> - <td>Push connection established using streaming</td> - <td></td> -</tr> -<tr> - <td>assertTextNotPresent</td> - <td>Push connection established using websocket</td> - <td></td> -</tr> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.push.BasicPushWebsocket?debug&restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertTextNotPresent</td> - <td>Push connection established using streaming</td> - <td></td> -</tr> -<tr> - <td>waitForTextPresent</td> - <td>Push connection established using websocket</td> - <td></td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/StreamingPush.html b/uitest/src/com/vaadin/tests/push/StreamingPush.html deleted file mode 100644 index cf94a09c63..0000000000 --- a/uitest/src/com/vaadin/tests/push/StreamingPush.html +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.BasicPush?restartApplication&debug&transport=streaming</td> - <td></td> -</tr> -<!--Test client initiated push --> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>0</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>1</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VLabel[0]</td> - <td>4</td> -</tr> -<!--Test server initiated push--> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[5]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>0</td> -</tr> -<tr> - <td>pause</td> - <td>3000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>1</td> -</tr> -<tr> - <td>pause</td> - <td>3000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushBasicPush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[4]/VLabel[0]</td> - <td>2</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.html b/uitest/src/com/vaadin/tests/push/TogglePush.html deleted file mode 100644 index b752d2120c..0000000000 --- a/uitest/src/com/vaadin/tests/push/TogglePush.html +++ /dev/null @@ -1,91 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.TogglePush?restartApplication</td> - <td></td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td>2000</td> - <td></td> -</tr> -<!--Push is enabled, so text gets updated--> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 1 times</td> -</tr> -<tr> - <td>mouseClick</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> - <td>61,6</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td>2000</td> - <td></td> -</tr> -<!--Push is disabled, so text is not updated--> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 1 times</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<!--Direct update is visible, and includes previous update--> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 3 times</td> -</tr> -<tr> - <td>mouseClick</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> - <td>61,3</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td>2000</td> - <td></td> -</tr> -<!--Push is enabled again, so text gets updated--> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 4 times</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/TogglePush.java b/uitest/src/com/vaadin/tests/push/TogglePush.java index c0bdc54ee0..f59ef83fe7 100644 --- a/uitest/src/com/vaadin/tests/push/TogglePush.java +++ b/uitest/src/com/vaadin/tests/push/TogglePush.java @@ -1,19 +1,173 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.push; import java.util.Timer; import java.util.TimerTask; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; import com.vaadin.server.VaadinRequest; import com.vaadin.shared.communication.PushMode; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.CheckBox; import com.vaadin.ui.Label; public class TogglePush extends AbstractTestUI { + public static class TogglePushInInitTB3 extends MultiBrowserTest { + @Override + protected boolean isPushEnabled() { + return true; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getTestUrl() + */ + @Override + protected String getTestUrl() { + return null; + } + + @Test + public void togglePushInInit() { + String baseUrl = getBaseURL(); + if (baseUrl.endsWith("/")) { + baseUrl = baseUrl.substring(0, baseUrl.length() - 1); + } + + String url = baseUrl + getDeploymentPath(); + + // Open with push disabled + driver.get(addParameter(url, "push=disabled")); + + Assert.assertFalse(getPushToggle().isSelected()); + + getDelayedCounterUpdateButton().click(); + sleep(2000); + Assert.assertEquals("Counter has been updated 0 times", + getCounterText()); + + // Open with push enabled + driver.get(addParameter(url, "push=enabled")); + Assert.assertTrue(getPushToggle().isSelected()); + + getDelayedCounterUpdateButton().click(); + sleep(2000); + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + } + + /** + * @since + * @param url + * @param string + * @return + */ + private String addParameter(String url, String queryParameter) { + if (url.contains("?")) { + return url + "&" + queryParameter; + } else { + return url + "?" + queryParameter; + } + } + + private String getCounterText() { + return vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText(); + } + + private WebElement getPushToggle() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]"); + } + + private WebElement getDelayedCounterUpdateButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]"); + } + + } + + public static class TogglePushTB3 extends MultiBrowserTest { + + @Override + protected boolean isPushEnabled() { + return true; + } + + @Test + public void togglePush() { + getDelayedCounterUpdateButton().click(); + sleep(2000); + + // Push is enabled, so text gets updated + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + // Disable push + getPushToggle().click(); + getDelayedCounterUpdateButton().click(); + sleep(2000); + // Push is disabled, so text is not updated + Assert.assertEquals("Counter has been updated 1 times", + getCounterText()); + + getDirectCounterUpdateButton().click(); + // Direct update is visible, and includes previous update + Assert.assertEquals("Counter has been updated 3 times", + getCounterText()); + + // Re-enable push + getPushToggle().click(); + getDelayedCounterUpdateButton().click(); + sleep(2000); + + // Push is enabled again, so text gets updated + Assert.assertEquals("Counter has been updated 4 times", + getCounterText()); + } + + private WebElement getDirectCounterUpdateButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]"); + } + + private WebElement getPushToggle() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]"); + } + + private String getCounterText() { + return vaadinElement( + "/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]") + .getText(); + } + + private WebElement getDelayedCounterUpdateButton() { + return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]"); + } + } + private final Label counterLabel = new Label(); private int counter = 0; diff --git a/uitest/src/com/vaadin/tests/push/TogglePushInInit.html b/uitest/src/com/vaadin/tests/push/TogglePushInInit.html deleted file mode 100644 index c735f225e1..0000000000 --- a/uitest/src/com/vaadin/tests/push/TogglePushInInit.html +++ /dev/null @@ -1,69 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://localhost:8071/" /> -<title>TogglePushInInit</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">TogglePushInInit</td></tr> -</thead><tbody> -<!--Open with push disabled--> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.TogglePush?restartApplication&push=disabled</td> - <td></td> -</tr> -<tr> - <td>assertValue</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> - <td>off</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td>2000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 0 times</td> -</tr> -<!--Open with push enabled--> -<tr> - <td>open</td> - <td>/run-push/com.vaadin.tests.push.TogglePush?restartApplication&push=enabled</td> - <td></td> -</tr> -<tr> - <td>assertValue</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VCheckBox[0]/domChild[0]</td> - <td>on</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td>2000</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runpushcomvaadintestspushTogglePush::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Counter has been updated 1 times</td> -</tr> - -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.html b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.html deleted file mode 100644 index 89dd7d4e78..0000000000 --- a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.html +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> -<head profile="http://selenium-ide.openqa.org/profiles/test-case"> -<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> -<link rel="selenium.base" href="http://192.168.2.162:8888/" /> -<title>New Test</title> -</head> -<body> -<table cellpadding="1" cellspacing="1" border="1"> -<thead> -<tr><td rowspan="1" colspan="3">New Test</td></tr> -</thead><tbody> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.push.TrackMessageSizeUnitTests?restartApplication</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestspushTrackMessageSizeUnitTests::PID_SLog_row_0</td> - <td>1. All tests run</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java index 062698edf5..d7459f83ab 100644 --- a/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java +++ b/uitest/src/com/vaadin/tests/push/TrackMessageSizeUnitTests.java @@ -25,18 +25,29 @@ import javax.servlet.ServletContext; import org.apache.commons.io.IOUtils; import org.json.JSONArray; import org.json.JSONException; +import org.junit.Assert; +import org.junit.Test; import com.vaadin.annotations.JavaScript; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinService; import com.vaadin.server.VaadinServletService; import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.ui.JavaScriptFunction; // Load vaadinPush.js so that jQueryVaadin is defined @JavaScript("vaadin://vaadinPush.js") public class TrackMessageSizeUnitTests extends AbstractTestUIWithLog { + public static class TrackMessageSizeUnitTestsTB3 extends MultiBrowserTest { + @Test + public void runTests() { + Assert.assertEquals("1. All tests run", + vaadinElementById("Log_row_0").getText()); + } + } + private String testMethod = "function testSequence(expected, data) {\n" + " var request = {trackMessageLength: true, messageDelimiter: '|'};\n" + " var response = {partialMessage: ''};\n" diff --git a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java index 63819e5f07..1897728366 100644 --- a/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java +++ b/uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java @@ -17,18 +17,24 @@ package com.vaadin.tests.tb3; import java.net.URL; +import java.util.Collection; +import java.util.Collections; import org.junit.After; import org.junit.Before; +import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.BrowserType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import com.vaadin.server.LegacyApplication; -import com.vaadin.testbench.By; import com.vaadin.testbench.TestBench; import com.vaadin.testbench.TestBenchTestCase; import com.vaadin.ui.UI; @@ -50,6 +56,7 @@ import com.vaadin.ui.UI; * * @author Vaadin Ltd */ +@RunWith(value = TB3Runner.class) public abstract class AbstractTB3Test extends TestBenchTestCase { /** * Height of the screenshots we want to capture @@ -154,6 +161,24 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { protected abstract String getDeploymentHostname(); /** + * Produces a collection of browsers to run the test on. This method is + * executed by the test runner when determining how many test methods to + * invoke and with what parameters. For each returned value a test method is + * ran and before running that, + * {@link #setDesiredCapabilities(DesiredCapabilities)} is invoked with the + * value returned by this method. + * + * This method is not static to allow overriding it in sub classes. By + * default runs the test only on Firefox + * + * @return The browsers to run the test on + */ + public Collection<DesiredCapabilities> getBrowsersToTest() { + return Collections.singleton(BrowserUtil.firefox(17)); + + } + + /** * Used to determine which capabilities should be used when setting up a * {@link WebDriver} for this test. Typically set by a test runner or left * at its default (Firefox 24). If you want to run a test on a single @@ -189,9 +214,8 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { } /** - * Finds a Vaadin element based on the part of a TB3 style locator following - * the :: (e.g. - * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> + * Finds an element based on the part of a TB2 style locator following the + * :: (e.g. vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> * PID_Scheckboxaction-Enabled/domChild[0]). * * @param vaadinLocator @@ -199,11 +223,7 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return */ protected WebElement vaadinElement(String vaadinLocator) { - String base = getApplicationId(getDeploymentPath()); - - base += "::"; - - return driver.findElement(By.vaadin(base + vaadinLocator)); + return driver.findElement(vaadinLocator(vaadinLocator)); } /** @@ -214,7 +234,58 @@ public abstract class AbstractTB3Test extends TestBenchTestCase { * @return */ public WebElement vaadinElementById(String id) { - return vaadinElement("PID_S" + id); + return driver.findElement(vaadinLocatorById(id)); + } + + /** + * Finds a {@link By} locator based on the part of a TB2 style locator + * following the :: (e.g. + * vaadin=runLabelModes::PID_Scheckboxaction-Enabled/domChild[0] -> + * PID_Scheckboxaction-Enabled/domChild[0]). + * + * @param vaadinLocator + * The part following :: of the vaadin locator string + * @return + */ + public org.openqa.selenium.By vaadinLocator(String vaadinLocator) { + String base = getApplicationId(getDeploymentPath()); + + base += "::"; + return com.vaadin.testbench.By.vaadin(base + vaadinLocator); + } + + /** + * Constructs a {@link By} locator for the id given using Component.setId + * + * @param id + * The id to locate + * @return a locator for the given id + */ + public By vaadinLocatorById(String id) { + return vaadinLocator("PID_S" + id); + } + + /** + * Waits a short while for the given condition to become true. Use e.g. as + * {@link #waitUntil(ExpectedConditions.textToBePresentInElement(by, text))} + * + * @param condition + * the condition to wait for to become true + */ + protected void waitUntil(ExpectedCondition<Boolean> condition) { + new WebDriverWait(driver, 10).until(condition); + } + + /** + * Waits a short while for the given condition to become false. Use e.g. as + * {@link #waitUntilNot(ExpectedConditions.textToBePresentInElement(by, + * text))} + * + * @param condition + * the condition to wait for to become false + */ + protected void waitUntilNot(ExpectedCondition<Boolean> condition) { + new WebDriverWait(driver, 10).until(ExpectedConditions.not(condition)); } /** diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java index e24218eeb4..3553954ec0 100644 --- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java +++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java @@ -18,11 +18,8 @@ package com.vaadin.tests.tb3; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized.Parameters; import org.openqa.selenium.remote.DesiredCapabilities; /** @@ -41,11 +38,9 @@ import org.openqa.selenium.remote.DesiredCapabilities; * * @author Vaadin Ltd */ -@RunWith(value = TB3Runner.class) public abstract class MultiBrowserTest extends PrivateTB3Configuration { - private static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>(); - private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>(); + static List<DesiredCapabilities> allBrowsers = new ArrayList<DesiredCapabilities>(); static { allBrowsers.add(BrowserUtil.ie(8)); allBrowsers.add(BrowserUtil.ie(9)); @@ -57,26 +52,18 @@ public abstract class MultiBrowserTest extends PrivateTB3Configuration { allBrowsers.add(BrowserUtil.chrome(29)); allBrowsers.add(BrowserUtil.opera(12)); - websocketBrowsers.addAll(allBrowsers); - websocketBrowsers.remove(BrowserUtil.ie(8)); - websocketBrowsers.remove(BrowserUtil.ie(9)); - } - - @Parameters - public static Collection<DesiredCapabilities> getBrowsersForTest() { - return getAllBrowsers(); - } - - public static Collection<DesiredCapabilities> getAllBrowsers() { - return Collections.unmodifiableCollection(allBrowsers); } /** - * @return A subset of {@link #getAllBrowsers()} including only those which - * support websockets + * @return all supported browsers which are actively tested */ - public static Collection<DesiredCapabilities> getWebsocketBrowsers() { - return Collections.unmodifiableCollection(websocketBrowsers); + public static List<DesiredCapabilities> getAllBrowsers() { + return allBrowsers; + } + + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return allBrowsers; } } diff --git a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java index 510d200ffa..5860ac42c0 100644 --- a/uitest/src/com/vaadin/tests/tb3/TB3Runner.java +++ b/uitest/src/com/vaadin/tests/tb3/TB3Runner.java @@ -17,16 +17,12 @@ package com.vaadin.tests.tb3; import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Collections; import java.util.LinkedList; import java.util.List; import org.junit.Test; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.InitializationError; import org.junit.runners.model.Statement; @@ -53,49 +49,26 @@ public class TB3Runner extends BlockJUnit4ClassRunner { protected List<FrameworkMethod> computeTestMethods() { List<FrameworkMethod> tests = new LinkedList<FrameworkMethod>(); - // Find all methods in our test class marked with @Parameters. - for (FrameworkMethod method : getTestClass().getAnnotatedMethods( - Parameters.class)) { - // Make sure the Parameters method is static - if (!Modifier.isStatic(method.getMethod().getModifiers())) { - throw new IllegalArgumentException("@Parameters " + method - + " must be static."); - } - - // Execute the method (statically) - Object params; - try { - params = method.getMethod().invoke( - getTestClass().getJavaClass()); - } catch (Throwable t) { - throw new RuntimeException("Could not run test factory method " - + method.getName(), t); - } - - // Did the factory return an array? If so, make it a list. - if (params.getClass().isArray()) { - params = Arrays.asList((Object[]) params); - } + if (!AbstractTB3Test.class.isAssignableFrom(getTestClass() + .getJavaClass())) { + throw new RuntimeException(getClass().getName() + " only supports " + + AbstractTB3Test.class.getName()); + } - // Did the factory return a scalar object? If so, put it in a list. - if (!(params instanceof Iterable<?>)) { - params = Collections.singletonList(params); - } + try { + AbstractTB3Test testClassInstance = (AbstractTB3Test) getTestClass() + .getOnlyConstructor().newInstance(); + for (DesiredCapabilities capabilities : testClassInstance + .getBrowsersToTest()) { - // For each object returned by the factory. - for (Object param : (Iterable<?>) params) { - if (!(param instanceof DesiredCapabilities)) { - throw new RuntimeException("Unexpected parameter type " - + param.getClass().getName() - + " when expecting DesiredCapabilities"); - } - DesiredCapabilities capabilities = (DesiredCapabilities) param; // Find any methods marked with @Test. for (FrameworkMethod m : getTestClass().getAnnotatedMethods( Test.class)) { tests.add(new TB3Method(m.getMethod(), capabilities)); } } + } catch (Exception e) { + throw new RuntimeException("Error retrieving browsers to run on", e); } return tests; diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java new file mode 100644 index 0000000000..5c6ea329f5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed 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 com.vaadin.tests.tb3; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.openqa.selenium.remote.DesiredCapabilities; + +/** + * A {@link MultiBrowserTest} which restricts the tests to the browsers which + * support websocket + * + * @author Vaadin Ltd + */ +public abstract class WebsocketTest extends PrivateTB3Configuration { + private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>(); + static { + websocketBrowsers.addAll(MultiBrowserTest.getAllBrowsers()); + websocketBrowsers.remove(BrowserUtil.ie(8)); + websocketBrowsers.remove(BrowserUtil.ie(9)); + } + + /** + * @return All supported browsers which are actively tested and support + * websockets + */ + public static Collection<DesiredCapabilities> getWebsocketBrowsers() { + return Collections.unmodifiableCollection(websocketBrowsers); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.tb3.AbstractTB3Test#getBrowserToRunOn() + */ + @Override + public Collection<DesiredCapabilities> getBrowsersToTest() { + return getWebsocketBrowsers(); + } +} |