* Generates all screenshot names based on the test names Change-Id: Ie42489d31b78eff0b021c22a2d747326f57d0d2etags/7.6.0.alpha5
import com.vaadin.testbench.elements.NotificationElement; | import com.vaadin.testbench.elements.NotificationElement; | ||||
import com.vaadin.tests.tb3.MultiBrowserThemeTest; | import com.vaadin.tests.tb3.MultiBrowserThemeTest; | ||||
public abstract class CriticalNotificationsTestBase extends | |||||
MultiBrowserThemeTest { | |||||
public static class ValoCriticalNotificationsTest extends | |||||
CriticalNotificationsTestBase { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "valo"; | |||||
} | |||||
} | |||||
public static class ReindeerCriticalNotificationsTest extends | |||||
CriticalNotificationsTestBase { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "reindeer"; | |||||
} | |||||
} | |||||
public static class RunoCriticalNotificationsTest extends | |||||
CriticalNotificationsTestBase { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "runo"; | |||||
} | |||||
} | |||||
public static class ChameleonCriticalNotificationsTest extends | |||||
CriticalNotificationsTestBase { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "chameleon"; | |||||
} | |||||
} | |||||
public static class BaseCriticalNotificationsTest extends | |||||
CriticalNotificationsTestBase { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "base"; | |||||
} | |||||
} | |||||
public class CriticalNotificationsTest extends MultiBrowserThemeTest { | |||||
@Test | @Test | ||||
public void internalError() throws Exception { | public void internalError() throws Exception { |
import com.vaadin.testbench.elements.ButtonElement; | import com.vaadin.testbench.elements.ButtonElement; | ||||
import com.vaadin.testbench.parallel.BrowserUtil; | import com.vaadin.testbench.parallel.BrowserUtil; | ||||
import com.vaadin.testbench.parallel.TestCategory; | |||||
import com.vaadin.tests.tb3.CustomTestBenchCommandExecutor; | import com.vaadin.tests.tb3.CustomTestBenchCommandExecutor; | ||||
import com.vaadin.tests.tb3.MultiBrowserThemeTestWithProxy; | import com.vaadin.tests.tb3.MultiBrowserThemeTestWithProxy; | ||||
public abstract class ReconnectDialogUIThemeTest extends | |||||
MultiBrowserThemeTestWithProxy { | |||||
public static class ValoReconnectDialogTest extends | |||||
ReconnectDialogUIThemeTest { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "valo"; | |||||
} | |||||
} | |||||
public static class ReindeerReconnectDialogTest extends | |||||
ReconnectDialogUIThemeTest { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "reindeer"; | |||||
} | |||||
} | |||||
public static class RunoReconnectDialogTest extends | |||||
ReconnectDialogUIThemeTest { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "runo"; | |||||
} | |||||
} | |||||
public static class ChameleonReconnectDialogTest extends | |||||
ReconnectDialogUIThemeTest { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "chameleon"; | |||||
} | |||||
} | |||||
public static class BaseReconnectDialogTest extends | |||||
ReconnectDialogUIThemeTest { | |||||
@Override | |||||
protected String getTheme() { | |||||
return "base"; | |||||
} | |||||
} | |||||
@TestCategory("") | |||||
public class ReconnectDialogThemeTest extends MultiBrowserThemeTestWithProxy { | |||||
static By reconnectDialogBy = By.className("v-reconnect-dialog"); | static By reconnectDialogBy = By.className("v-reconnect-dialog"); | ||||
private void waitForReconnectDialogWithText(final String text) { | private void waitForReconnectDialogWithText(final String text) { | ||||
waitForReconnectDialogPresent(); | waitForReconnectDialogPresent(); | ||||
final WebElement reconnectDialog = findElement(ReconnectDialogUIThemeTest.reconnectDialogBy); | |||||
final WebElement reconnectDialog = findElement(ReconnectDialogThemeTest.reconnectDialogBy); | |||||
waitUntil(new ExpectedCondition<Boolean>() { | waitUntil(new ExpectedCondition<Boolean>() { | ||||
@Override | @Override | ||||
public Boolean apply(WebDriver input) { | public Boolean apply(WebDriver input) { | ||||
} | } | ||||
private void waitForReconnectDialogToDisappear() { | private void waitForReconnectDialogToDisappear() { | ||||
waitForElementNotPresent(ReconnectDialogUIThemeTest.reconnectDialogBy); | |||||
waitForElementNotPresent(ReconnectDialogThemeTest.reconnectDialogBy); | |||||
} | } | ||||
private void waitForReconnectDialogPresent() { | private void waitForReconnectDialogPresent() { | ||||
waitForElementPresent(ReconnectDialogUIThemeTest.reconnectDialogBy); | |||||
waitForElementPresent(ReconnectDialogThemeTest.reconnectDialogBy); | |||||
} | } | ||||
private WebElement getButton() { | private WebElement getButton() { |
/* | |||||
* Copyright 2000-2014 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.integration; | |||||
import java.lang.reflect.Method; | |||||
import java.lang.reflect.Modifier; | |||||
import java.util.ArrayList; | |||||
import java.util.Collection; | |||||
import java.util.LinkedHashMap; | |||||
import java.util.List; | |||||
import java.util.Map; | |||||
import org.junit.runners.Parameterized.Parameters; | |||||
import org.junit.runners.model.FrameworkMethod; | |||||
import org.junit.runners.model.InitializationError; | |||||
import com.vaadin.tests.tb3.TB3Runner; | |||||
/** | |||||
* TestBench test runner which supports static @Parameters annotated methods | |||||
* providing parameters for the corresponding setter. | |||||
* <p> | |||||
* {@code @Parameters public static Collection<String> getThemes() } creates one | |||||
* permutation for each value returned by {@code getThemes()}. The value is | |||||
* automatically assigned to the test instance using {@code setTheme(String)} | |||||
* before invoking the test method | |||||
* | |||||
* @author Vaadin Ltd | |||||
*/ | |||||
public class ParameterizedTB3Runner extends TB3Runner { | |||||
public ParameterizedTB3Runner(Class<?> klass) throws InitializationError { | |||||
super(klass); | |||||
} | |||||
@Override | |||||
protected List<FrameworkMethod> computeTestMethods() { | |||||
List<FrameworkMethod> methods = super.computeTestMethods(); | |||||
Map<Method, Collection<String>> parameters = new LinkedHashMap<Method, Collection<String>>(); | |||||
// Find all @Parameters methods and invoke them to find out permutations | |||||
for (Method m : getTestClass().getJavaClass().getMethods()) { | |||||
Parameters p = m.getAnnotation(Parameters.class); | |||||
if (p == null) { | |||||
continue; | |||||
} | |||||
if (!m.getName().startsWith("get") || !m.getName().endsWith("s")) { | |||||
throw new IllegalStateException( | |||||
"Method " | |||||
+ m.getName() | |||||
+ " is annotated with @Parameter but is not named getSomeThings() as it should"); | |||||
} | |||||
if (m.getParameterTypes().length != 0) { | |||||
throw new IllegalStateException( | |||||
"Method " | |||||
+ m.getName() | |||||
+ " annotated with @Parameter should not have any arguments"); | |||||
} | |||||
if (!Modifier.isStatic(m.getModifiers())) { | |||||
throw new IllegalStateException("Method " + m.getName() | |||||
+ " annotated with @Parameter must be static"); | |||||
} | |||||
// getThemes -> setTheme | |||||
String setter = "set" + m.getName().substring("get".length()); | |||||
setter = setter.substring(0, setter.length() - 1); | |||||
// property = property.substring(0, 1).toLowerCase() | |||||
// + property.substring(1); | |||||
Method setterMethod; | |||||
try { | |||||
setterMethod = getTestClass().getJavaClass().getMethod(setter, | |||||
String.class); | |||||
} catch (Exception e) { | |||||
throw new IllegalStateException("No setter " + setter | |||||
+ " found in " | |||||
+ getTestClass().getJavaClass().getName(), e); | |||||
} | |||||
Collection<String> values; | |||||
try { | |||||
values = (Collection<String>) m.invoke(null); | |||||
if (!values.isEmpty()) { | |||||
// Ignore any empty collections to allow e.g. intergration | |||||
// tests to use "/demo" path by default without adding that | |||||
// to the screnshot name | |||||
parameters.put(setterMethod, values); | |||||
} | |||||
} catch (Exception e) { | |||||
e.printStackTrace(); | |||||
} | |||||
} | |||||
// Add method permutations for all @Parameters | |||||
for (Method setter : parameters.keySet()) { | |||||
List<FrameworkMethod> newMethods = new ArrayList<FrameworkMethod>(); | |||||
for (FrameworkMethod m : methods) { | |||||
if (!(m instanceof TBMethod)) { | |||||
System.err.println("Unknown method type: " | |||||
+ m.getClass().getName()); | |||||
newMethods.add(m); | |||||
continue; | |||||
} | |||||
// testFoo | |||||
// testBar | |||||
// -> | |||||
// testFoo[valo] | |||||
// testFoo[runo] | |||||
// testBar[valo] | |||||
// testBar[runo] | |||||
for (final String value : parameters.get(setter)) { | |||||
newMethods.add(new TBMethodWithBefore((TBMethod) m, setter, | |||||
value)); | |||||
} | |||||
} | |||||
// Update methods so next parameters will use all expanded methods | |||||
methods = newMethods; | |||||
} | |||||
return methods; | |||||
} | |||||
public static class TBMethodWithBefore extends TBMethod { | |||||
private Method setter; | |||||
private String value; | |||||
private TBMethod parent; | |||||
public TBMethodWithBefore(TBMethod m, Method setter, String value) { | |||||
super(m.getMethod(), m.getCapabilities()); | |||||
parent = m; | |||||
this.setter = setter; | |||||
this.value = value; | |||||
} | |||||
@Override | |||||
public Object invokeExplosively(Object target, Object... params) | |||||
throws Throwable { | |||||
setter.invoke(target, value); | |||||
return parent.invokeExplosively(target, params); | |||||
} | |||||
@Override | |||||
public String getName() { | |||||
return parent.getName() + "[" + value + "]"; | |||||
}; | |||||
} | |||||
} |
import org.apache.http.message.BasicHttpEntityEnclosingRequest; | import org.apache.http.message.BasicHttpEntityEnclosingRequest; | ||||
import org.junit.Assert; | import org.junit.Assert; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
import org.junit.rules.TestName; | |||||
import org.junit.runner.RunWith; | import org.junit.runner.RunWith; | ||||
import org.openqa.selenium.By; | import org.openqa.selenium.By; | ||||
import org.openqa.selenium.Dimension; | import org.openqa.selenium.Dimension; | ||||
@RunWith(TB3Runner.class) | @RunWith(TB3Runner.class) | ||||
public abstract class AbstractTB3Test extends ParallelTest { | public abstract class AbstractTB3Test extends ParallelTest { | ||||
@Rule | |||||
public TestName testName = new TestName(); | |||||
@Rule | @Rule | ||||
public RetryOnFail retry = new RetryOnFail(); | public RetryOnFail retry = new RetryOnFail(); | ||||
import java.util.Calendar; | import java.util.Calendar; | ||||
import java.util.List; | import java.util.List; | ||||
import org.junit.Rule; | |||||
import org.junit.rules.TestName; | |||||
import org.openqa.selenium.ie.InternetExplorerDriver; | import org.openqa.selenium.ie.InternetExplorerDriver; | ||||
import org.openqa.selenium.remote.DesiredCapabilities; | import org.openqa.selenium.remote.DesiredCapabilities; | ||||
*/ | */ | ||||
public abstract class MultiBrowserTest extends PrivateTB3Configuration { | public abstract class MultiBrowserTest extends PrivateTB3Configuration { | ||||
@Rule | |||||
public TestName testName = new TestName(); | |||||
protected List<DesiredCapabilities> getBrowsersSupportingWebSocket() { | protected List<DesiredCapabilities> getBrowsersSupportingWebSocket() { | ||||
// No WebSocket support in IE8-9 and PhantomJS | // No WebSocket support in IE8-9 and PhantomJS | ||||
return getBrowserCapabilities(Browser.IE10, Browser.IE11, | return getBrowserCapabilities(Browser.IE10, Browser.IE11, |
package com.vaadin.tests.tb3; | package com.vaadin.tests.tb3; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collection; | |||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.junit.runner.RunWith; | |||||
import org.junit.runners.Parameterized.Parameters; | |||||
import org.openqa.selenium.remote.DesiredCapabilities; | import org.openqa.selenium.remote.DesiredCapabilities; | ||||
import com.vaadin.tests.integration.ParameterizedTB3Runner; | |||||
/** | /** | ||||
* Test which uses theme returned by {@link #getTheme()} for running the test | * Test which uses theme returned by {@link #getTheme()} for running the test | ||||
*/ | */ | ||||
@RunWith(ParameterizedTB3Runner.class) | |||||
public abstract class MultiBrowserThemeTest extends MultiBrowserTest { | public abstract class MultiBrowserThemeTest extends MultiBrowserTest { | ||||
protected abstract String getTheme(); | |||||
private String theme; | |||||
public void setTheme(String theme) { | |||||
this.theme = theme; | |||||
} | |||||
@Parameters | |||||
public static Collection<String> getThemes() { | |||||
return Arrays.asList(new String[] { "valo", "reindeer", "runo", | |||||
"chameleon", "base" }); | |||||
} | |||||
@Override | @Override | ||||
protected boolean requireWindowFocusForIE() { | protected boolean requireWindowFocusForIE() { | ||||
@Override | @Override | ||||
protected void openTestURL(Class<?> uiClass, String... parameters) { | protected void openTestURL(Class<?> uiClass, String... parameters) { | ||||
Set<String> params = new HashSet<String>(Arrays.asList(parameters)); | Set<String> params = new HashSet<String>(Arrays.asList(parameters)); | ||||
params.add("theme=" + getTheme()); | |||||
params.add("theme=" + theme); | |||||
super.openTestURL(uiClass, params.toArray(new String[params.size()])); | super.openTestURL(uiClass, params.toArray(new String[params.size()])); | ||||
} | } | ||||
package com.vaadin.tests.tb3; | package com.vaadin.tests.tb3; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collection; | |||||
import java.util.HashSet; | import java.util.HashSet; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | import java.util.Set; | ||||
import org.junit.runner.RunWith; | |||||
import org.junit.runners.Parameterized.Parameters; | |||||
import org.openqa.selenium.remote.DesiredCapabilities; | import org.openqa.selenium.remote.DesiredCapabilities; | ||||
/** | |||||
* Test which uses theme returned by {@link #getTheme()} for running the test | |||||
*/ | |||||
import com.vaadin.tests.integration.ParameterizedTB3Runner; | |||||
@RunWith(ParameterizedTB3Runner.class) | |||||
public abstract class MultiBrowserThemeTestWithProxy extends | public abstract class MultiBrowserThemeTestWithProxy extends | ||||
MultiBrowserTestWithProxy { | MultiBrowserTestWithProxy { | ||||
protected abstract String getTheme(); | |||||
private String theme; | |||||
public void setTheme(String theme) { | |||||
this.theme = theme; | |||||
} | |||||
@Parameters | |||||
public static Collection<String> getThemes() { | |||||
return Arrays.asList(new String[] { "valo", "reindeer", "runo", | |||||
"chameleon", "base" }); | |||||
} | |||||
@Override | @Override | ||||
protected boolean requireWindowFocusForIE() { | protected boolean requireWindowFocusForIE() { | ||||
@Override | @Override | ||||
protected void openTestURL(Class<?> uiClass, String... parameters) { | protected void openTestURL(Class<?> uiClass, String... parameters) { | ||||
Set<String> params = new HashSet<String>(Arrays.asList(parameters)); | Set<String> params = new HashSet<String>(Arrays.asList(parameters)); | ||||
params.add("theme=" + getTheme()); | |||||
params.add("theme=" + theme); | |||||
super.openTestURL(uiClass, params.toArray(new String[params.size()])); | super.openTestURL(uiClass, params.toArray(new String[params.size()])); | ||||
} | } | ||||
* fails | * fails | ||||
*/ | */ | ||||
private String getScreenshotFailureName() { | private String getScreenshotFailureName() { | ||||
return getScreenshotBaseName() + "_" | |||||
+ getUniqueIdentifier(getDesiredCapabilities()) | |||||
return getScreenshotBaseName() + "_" + getUniqueIdentifier(null) | |||||
+ "-failure.png"; | + "-failure.png"; | ||||
} | } | ||||
*/ | */ | ||||
private String getScreenshotReferenceName(String identifier, | private String getScreenshotReferenceName(String identifier, | ||||
Integer versionOverride) { | Integer versionOverride) { | ||||
String uniqueBrowserIdentifier; | |||||
if (versionOverride == null) { | |||||
uniqueBrowserIdentifier = getUniqueIdentifier(getDesiredCapabilities()); | |||||
} else { | |||||
uniqueBrowserIdentifier = getUniqueIdentifier( | |||||
getDesiredCapabilities(), "" + versionOverride); | |||||
} | |||||
// WindowMaximizeRestoreTest_Windows_InternetExplorer_8_window-1-moved-maximized-restored.png | |||||
return getScreenshotReferenceDirectory() + File.separator | return getScreenshotReferenceDirectory() + File.separator | ||||
+ getScreenshotBaseName() + "_" + uniqueBrowserIdentifier + "_" | |||||
+ identifier + ".png"; | |||||
+ getScreenshotBaseName() + "_" | |||||
+ getUniqueIdentifier(versionOverride) + "_" + identifier | |||||
+ ".png"; | |||||
} | } | ||||
/** | |||||
* Returns a string which uniquely (enough) identifies this browser. Used | |||||
* mainly in screenshot names. | |||||
* | |||||
* @param capabilities | |||||
* @param versionOverride | |||||
* | |||||
* @return a unique string for each browser | |||||
*/ | |||||
private String getUniqueIdentifier(DesiredCapabilities capabilities, | |||||
String versionOverride) { | |||||
return getUniqueIdentifier(BrowserUtil.getPlatform(capabilities), | |||||
BrowserUtil.getBrowserIdentifier(capabilities), versionOverride); | |||||
} | |||||
private String getUniqueIdentifier(Integer versionOverride) { | |||||
String testNameAndParameters = testName.getMethodName(); | |||||
// runTest-wildfly9-nginx[Windows_Firefox_24][/buffering/demo][valo] | |||||
/** | |||||
* Returns a string which uniquely (enough) identifies this browser. Used | |||||
* mainly in screenshot names. | |||||
* | |||||
* @param capabilities | |||||
* | |||||
* @return a unique string for each browser | |||||
*/ | |||||
private String getUniqueIdentifier(DesiredCapabilities capabilities) { | |||||
return getUniqueIdentifier(BrowserUtil.getPlatform(capabilities), | |||||
BrowserUtil.getBrowserIdentifier(capabilities), | |||||
capabilities.getVersion()); | |||||
} | |||||
String parameters = testNameAndParameters.substring( | |||||
testNameAndParameters.indexOf("[") + 1, | |||||
testNameAndParameters.length() - 1); | |||||
// Windows_Firefox_24][/buffering/demo][valo | |||||
parameters = parameters.replace("][", "_"); | |||||
// Windows_Firefox_24_/buffering/demo_valo | |||||
private String getUniqueIdentifier(String platform, String browser, | |||||
String version) { | |||||
return platform + "_" + browser + "_" + version; | |||||
parameters = parameters.replace("/", ""); | |||||
// Windows_Firefox_24_bufferingdemo_valo | |||||
if (versionOverride != null) { | |||||
// Windows_Firefox_17_-buffering-demo_valo | |||||
parameters = parameters.replaceFirst("_" | |||||
+ getDesiredCapabilities().getVersion(), "_" | |||||
+ versionOverride); | |||||
} | |||||
return parameters; | |||||
} | } | ||||
/** | /** |