diff options
author | Artur Signell <artur@vaadin.com> | 2014-03-31 16:27:00 +0300 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-04-02 07:56:06 +0300 |
commit | 7c569ca30267f1f506d6f8870c9c254c922f6568 (patch) | |
tree | 2e9a31430ca36ee7d9c650dab42ca71cf6859d0d /uitest/src/com | |
parent | a71305cdc61c45c4e2799da5398cb531c6579d98 (diff) | |
download | vaadin-framework-7c569ca30267f1f506d6f8870c9c254c922f6568.tar.gz vaadin-framework-7c569ca30267f1f506d6f8870c9c254c922f6568.zip |
Replaced flaky TB2 test with stable TB3 test
Change-Id: I14afbd88d7aa22510f6c0dd605643c072b8e589f
Diffstat (limited to 'uitest/src/com')
3 files changed, 125 insertions, 190 deletions
diff --git a/uitest/src/com/vaadin/tests/components/ui/UriFragment.java b/uitest/src/com/vaadin/tests/components/ui/UriFragment.java new file mode 100644 index 0000000000..c726c49b12 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UriFragment.java @@ -0,0 +1,64 @@ +package com.vaadin.tests.components.ui; + +import com.vaadin.server.Page; +import com.vaadin.server.Page.UriFragmentChangedEvent; +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 UriFragment extends AbstractTestUI { + + private final Label fragmentLabel = new Label(); + + @Override + protected void setup(VaadinRequest request) { + fragmentLabel.setId("fragmentLabel"); + addComponent(fragmentLabel); + updateLabel(); + getPage().addListener(new Page.UriFragmentChangedListener() { + @Override + public void uriFragmentChanged(UriFragmentChangedEvent event) { + updateLabel(); + } + }); + + addComponent(createButton("test", "Navigate to #test", "test")); + addComponent(createButton("empty", "Navigate to #", "")); + addComponent(createButton("null", "setUriFragment(null)", null)); + } + + private Button createButton(String id, String caption, final String fragment) { + Button button = new Button(caption, new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + getPage().setUriFragment(fragment); + } + }); + + button.setId(id); + + return button; + } + + private void updateLabel() { + String fragment = getPage().getUriFragment(); + if (fragment == null) { + fragmentLabel.setValue("No URI fragment set"); + } else { + fragmentLabel.setValue("Current URI fragment: " + fragment); + } + } + + @Override + public String getTestDescription() { + return "URI fragment status should be known when the page is loaded and retained while navigating to different fragments or using the back and forward buttons."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(8048); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.html b/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.html deleted file mode 100644 index ba24b55f64..0000000000 --- a/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.html +++ /dev/null @@ -1,136 +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.UriFragmentTest?restartApplication#urifragment</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td> - <td>Current URI fragment: urifragment</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td> - <td>Current URI fragment: test</td> -</tr> -<tr> - <td>runScript</td> - <td>history.back()</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td></td> - <td>1000</td> -</tr> -<tr> - <td>waitForVaadin</td> - <td></td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td> - <td>Current URI fragment: urifragment</td> -</tr> -<tr> - <td>runScript</td> - <td>history.forward()</td> - <td></td> -</tr> -<tr> - <td>pause</td> - <td></td> - <td>1000</td> -</tr> -<tr> - <td>waitForVaadin</td> - <td></td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td> - <td>Current URI fragment: test</td> -</tr> -<!--Open other URL in between to ensure the page is loaded again (testbench doesn't like opening a URI that only changes the fragment)--> -<tr> - <td>open</td> - <td>/run/</td> - <td></td> -</tr> -<tr> - <td>open</td> - <td>/run/com.vaadin.tests.components.ui.UriFragmentTest?restartApplication</td> - <td></td> -</tr> -<!--Empty initial fragment--> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>No URI fragment set</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<!--Still no # after setting to null--> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>No URI fragment set</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<!--Empty # is added when setting to ""--> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Current URI fragment:</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Current URI fragment: test</td> -</tr> -<tr> - <td>click</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[3]/VButton[0]/domChild[0]/domChild[0]</td> - <td></td> -</tr> -<!--Setting to null when there is a fragment actually sets it to #--> -<tr> - <td>assertText</td> - <td>vaadin=runcomvaadintestscomponentsuiUriFragmentTest::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VLabel[0]</td> - <td>Current URI fragment:</td> -</tr> -</tbody></table> -</body> -</html> diff --git a/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.java b/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.java index bfd784280a..e7fbf4f7ec 100644 --- a/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.java +++ b/uitest/src/com/vaadin/tests/components/ui/UriFragmentTest.java @@ -1,68 +1,75 @@ package com.vaadin.tests.components.ui; -import com.vaadin.server.Page; -import com.vaadin.server.Page.UriFragmentChangedEvent; -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 UriFragmentTest extends AbstractTestUI { - - private final Label fragmentLabel = new Label(); - - @Override - protected void setup(VaadinRequest request) { - addComponent(fragmentLabel); - updateLabel(); - getPage().addListener(new Page.UriFragmentChangedListener() { +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UriFragmentTest extends MultiBrowserTest { + + @Test + public void testUriFragment() throws Exception { + driver.get(getTestUrl() + "#urifragment"); + assertFragment("urifragment"); + navigateToTest(); + assertFragment("test"); + ((JavascriptExecutor) driver).executeScript("history.back()"); + + assertFragment("urifragment"); + ((JavascriptExecutor) driver).executeScript("history.forward()"); + assertFragment("test"); + + // Open other URL in between to ensure the page is loaded again + // (testbench doesn't like opening a URI that only changes the fragment) + driver.get(getBaseURL() + "/statictestfiles/"); + driver.get(getTestUrl()); + + // Empty initial fragment + assertEquals("No URI fragment set", getFragmentLabelValue()); + + navigateToNull(); + // Still no # after setting to null + assertEquals("No URI fragment set", getFragmentLabelValue()); + navigateToEmptyFragment(); + // Empty # is added when setting to "" + assertEquals("Current URI fragment:", getFragmentLabelValue()); + navigateToTest(); + assertFragment("test"); + navigateToNull(); // Setting to null when there is a fragment actually + // sets it to # + assertEquals("Current URI fragment:", getFragmentLabelValue()); + } + + private void assertFragment(String fragment) { + final String expectedText = "Current URI fragment: " + fragment; + waitUntil(new ExpectedCondition<Boolean>() { + @Override - public void uriFragmentChanged(UriFragmentChangedEvent event) { - updateLabel(); + public Boolean apply(WebDriver input) { + return expectedText.equals(getFragmentLabelValue()); } }); - addComponent(new Button("Navigate to #test", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - getPage().setUriFragment("test"); - } - })); - - addComponent(new Button("Navigate to #", new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - getPage().setUriFragment(""); - } - })); - - addComponent(new Button("setUriFragment(null)", - new Button.ClickListener() { - @Override - public void buttonClick(ClickEvent event) { - getPage().setUriFragment(null); - } - })); + + } + + private void navigateToEmptyFragment() { + hitButton("empty"); } - private void updateLabel() { - String fragment = getPage().getUriFragment(); - if (fragment == null) { - fragmentLabel.setValue("No URI fragment set"); - } else { - fragmentLabel.setValue("Current URI fragment: " + fragment); - } + private void navigateToNull() { + hitButton("null"); } - @Override - public String getTestDescription() { - return "URI fragment status should be known when the page is loaded and retained while navigating to different fragments or using the back and forward buttons."; + private void navigateToTest() { + hitButton("test"); } - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(8048); + private String getFragmentLabelValue() { + return vaadinElementById("fragmentLabel").getText(); } } |