summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-05-02 11:06:12 +0300
committerArtur Signell <artur@vaadin.com>2014-05-02 11:06:33 +0300
commit9c1501a5d341082f61398b8e1e6bde4aa7826d7a (patch)
tree95538349d8a13d4792857bc693e7ae288468d94a /uitest
parente96bd18de7234e3c84bb4f693d2dfb4d19265267 (diff)
parent08b0589d05e69da58b58c42b96a69c9331fdce25 (diff)
downloadvaadin-framework-9c1501a5d341082f61398b8e1e6bde4aa7826d7a.tar.gz
vaadin-framework-9c1501a5d341082f61398b8e1e6bde4aa7826d7a.zip
Merge changes from origin/7.2
08b0589 Refactored TimeoutRedirectResetsOnActivity tests. Conflicts: uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java Change-Id: Id2dc47cb5396a24c97a2689c1412b29a421ac400
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java40
-rw-r--r--uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java81
-rw-r--r--uitest/src/com/vaadin/tests/tb3/RetryOnFail.java65
3 files changed, 135 insertions, 51 deletions
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
index 2c649c9ca8..bf58846060 100644
--- a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
+++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivity.java
@@ -23,22 +23,50 @@ import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Label;
public class TimeoutRedirectResetsOnActivity extends AbstractTestUI {
+ private int maxActiveInterval = 15;
+ private int timeoutOverhead = 15;
+
@Override
protected void setup(VaadinRequest request) {
- setupTimout(request);
+ setupTimeout(request);
+
+ Label startedLabel = new Label();
+ startedLabel.setValue(String.valueOf(System.currentTimeMillis()));
+ startedLabel.setId("startedTime");
+
+ Label originalLabel = new Label();
+ originalLabel.setId("originalExpireTime");
+ originalLabel.setValue(String.valueOf(getExpireTime()));
- addComponent(new Button("clicky", new Button.ClickListener() {
+ final Label expiresLabel = new Label();
+ expiresLabel.setId("actualExpireTime");
+
+ Button button = new Button("Reset", new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
- // NOOP
+ expiresLabel.setValue(String.valueOf(getExpireTime()));
}
- }));
+
+ });
+ button.setId("reset");
+
+ addComponent(button);
+
+ addComponent(startedLabel);
+ addComponent(originalLabel);
+ addComponent(expiresLabel);
+ }
+
+ private long getExpireTime() {
+ return System.currentTimeMillis()
+ + (maxActiveInterval + timeoutOverhead) * 1000;
}
- private void setupTimout(VaadinRequest request) {
+ private void setupTimeout(VaadinRequest request) {
request.getService().setSystemMessagesProvider(
new SystemMessagesProvider() {
@Override
@@ -57,7 +85,7 @@ public class TimeoutRedirectResetsOnActivity extends AbstractTestUI {
* implementation details in
* com.vaadin.server.communication.MetadataWriter
*/
- getSession().getSession().setMaxInactiveInterval(10);
+ getSession().getSession().setMaxInactiveInterval(maxActiveInterval);
}
@Override
diff --git a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
index dda416ca7c..eecefbebe1 100644
--- a/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
+++ b/uitest/src/com/vaadin/tests/components/ui/TimeoutRedirectResetsOnActivityTest.java
@@ -15,73 +15,64 @@
*/
package com.vaadin.tests.components.ui;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
-import org.openqa.selenium.By;
-import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import com.vaadin.tests.tb3.MultiBrowserTest;
+import com.vaadin.tests.tb3.RetryOnFail;
public class TimeoutRedirectResetsOnActivityTest extends MultiBrowserTest {
+
+ @Rule
+ // Timing issues are really hard to resolve in a way that this test would be
+ // 100% reliable on all browsers. Hence we shall allow one retry.
+ public RetryOnFail retry = new RetryOnFail();
+
+ private int waitBeforeActivity = 4000;
+ private int communicationOverhead = 2000;
+
+ private static int i = 0;
+
@Test
@Ignore("The test modifies the system messages, which are global and the changes will affect other tests")
public void verifyRedirectWorks() throws Exception {
setDebug(true);
openTestURL();
- long startTime = System.currentTimeMillis();
- while (System.currentTimeMillis() - startTime < 30000) {
- clickTheButton();
- Thread.sleep(1000);
- }
+ long startedTime = getTime("startedTime");
+ long originalExpireTime = getTime("originalExpireTime");
- assertTrue("button disappeared before timeout", buttonIsStillThere());
+ Thread.sleep(waitBeforeActivity);
+ hitButton("reset");
- Thread.sleep(30000);
- assertTrue("no redirection occurred within 30 seconds",
- !buttonIsStillThere());
- }
+ Thread.sleep(200);
- private boolean buttonIsStillThere() {
- try {
- return getButton() != null;
- } catch (NoSuchElementException e) {
- return false;
- }
- }
+ long actualExpireTime = getTime("actualExpireTime");
+
+ Thread.sleep(originalExpireTime - startedTime - waitBeforeActivity);
+
+ assertThat(driver.getCurrentUrl(), is(getTestUrl()));
+
+ testBench().disableWaitForVaadin();
+ Thread.sleep(actualExpireTime - originalExpireTime
+ + communicationOverhead);
- private void clickTheButton() {
- getButton().click();
+ assertThat(driver.getCurrentUrl(), is(not(getTestUrl())));
}
- private WebElement getButton() {
- /*
- * For some reason, the vaadinElement() method doesn't work when tests
- * are run outside of "/run/" and "/run-push/" contexts. The given error
- * message says that the generated Vaadin path doesn't match any
- * elements, but when that selector is put into the recorder, the
- * recorder finds it.
- *
- * XPath works fine.
- */
- /*-
- return vaadinElement("/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VButton[0]");
- */
- return getDriver().findElement(
- By.xpath("//div[contains(@class,'v-button')]"));
+ private long getTime(String id) {
+ WebElement element = vaadinElementById(id);
+ return Long.parseLong(element.getText());
}
@Override
- protected String getDeploymentPath() {
- /*
- * AbstractTB3Test assumes only /run/ and /run-push/ contexts, so this
- * method needs some overriding.
- */
- return "/12446/"
- + TimeoutRedirectResetsOnActivity.class.getCanonicalName()
- + "?restartApplication&debug";
+ protected String getTestUrl() {
+ return super.getTestUrl() + "?restartApplication";
}
}
diff --git a/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.java
new file mode 100644
index 0000000000..b8a3c0e5f3
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/RetryOnFail.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.tb3;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * <strong>ALWAYS</strong> declare the reason for using this test rule in a
+ * test.
+ *
+ * <p>
+ * Violators and abusers of this rule will be punished.
+ * </p>
+ *
+ * @since 7.1.14
+ * @author Vaadin Ltd
+ */
+public class RetryOnFail implements TestRule {
+ private int retryCount = 1;
+
+ @Override
+ public Statement apply(Statement base, Description description) {
+ return statement(base, description);
+ }
+
+ private Statement statement(final Statement base,
+ final Description description) {
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ Throwable caughtThrowable = null;
+
+ for (int i = 0; i <= retryCount; i++) {
+ try {
+ base.evaluate();
+ return;
+ } catch (Throwable t) {
+ caughtThrowable = t;
+ System.err.println(String.format(
+ "%s: run %s/%s failed.",
+ description.getDisplayName(), i + 1,
+ retryCount + 1));
+ System.err.println(t.getMessage());
+ }
+ }
+ throw caughtThrowable;
+ }
+ };
+ }
+}