Refactored LayoutTesterApplicationTest.
Refactored SliderDisableTest.
Change-Id: I038fedb9d234656b85359ce7fb778b001e6f4402
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
public void disableSlider() throws IOException {
openTestURL();
- assertSliderHandlePositionIs(38);
+ String originalPosition = getSliderHandlePosition();
- // Move slider handle from 38px to 150px
moveSlider(112);
+ String expectedPosition = getSliderHandlePosition();
+ assertThat(expectedPosition, is(not(originalPosition)));
- assertSliderHandlePositionIs(150);
- driver.findElement(By.id("disableButton")).click();
+ hitButton("disableButton");
assertSliderIsDisabled();
- assertSliderHandlePositionIs(150);
+ assertThat(getSliderHandlePosition(), is(expectedPosition));
}
private void assertSliderIsDisabled() {
testBench().waitForVaadin();
}
- private void assertSliderHandlePositionIs(int position) {
+ private String getSliderHandlePosition() {
WebElement handle = driver.findElement(By.className("v-slider-handle"));
- assertThat(handle.getCssValue("margin-left"), is(position + "px"));
+ return handle.getCssValue("margin-left");
}
}
\ No newline at end of file
import org.junit.Test;
import org.openqa.selenium.By;
-import org.openqa.selenium.JavascriptExecutor;
-import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
+import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
import com.vaadin.tests.tb3.MultiBrowserTest;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
DesiredCapabilities cap = new DesiredCapabilities(
super.getDesiredCapabilities());
cap.setCapability("nativeEvents", false);
+
return cap;
}
new Select(vaadinElementById("layoutSelect").findElement(
By.xpath("select")))
.selectByVisibleText(layoutClass.toString());
- focusElementWithId("nextButton");
for (String subTest : LayoutTesterApplication.layoutGetters) {
compareScreen(subTest);
clickAndCompareScreen(subTest, "testButton" + i);
}
}
- getNextButton().click();
+
+ hitButton("nextButton");
}
}
- /**
- * @param elementId
- * the id of the element to focus
- */
- private void focusElementWithId(String elementId) {
- // This should really be in TestBench
- ((JavascriptExecutor) getDriver())
- .executeScript("document.getElementById('" + elementId
- + "').focus()");
- }
-
/**
* Clicks the button with the given id and compares the result to a
* screenshot named 'screenshotPrefix'-buttonCaption.
*/
private void clickAndCompareScreen(String screenshotPrefix, String buttonId)
throws Exception {
- WebElement button = vaadinElementById(buttonId);
- button.click();
+ hitButton(buttonId);
+
if (needsDelayToStabilize(screenshotPrefix)) {
// Table does some extra layout phase and TestBench does not always
// take this into account, grabbing screenshots before the layout
// phase is done (see #12866).
- sleep(200);
+ sleep(350);
}
- compareScreen(screenshotPrefix + "-" + sanitize(button.getText()));
+ compareScreen(screenshotPrefix + "-"
+ + sanitize(driver.findElement(By.id(buttonId)).getText()));
}
private boolean needsDelayToStabilize(String screenshotPrefix) {
private String sanitize(String text) {
return text.replace("%", "pct").replaceAll("[^a-zA-Z0-9]", "-");
}
-
- private WebElement getNextButton() {
- return vaadinElementById(LayoutTesterApplication.NEXT_BUTTON_ID);
- }
}
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
+import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
import com.vaadin.server.LegacyApplication;
import com.vaadin.server.UIProvider;
import com.vaadin.testbench.TestBench;
return ((HasInputDevices) getDriver()).getKeyboard();
}
+ public void hitButton(String id) {
+ WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver,
+ driver.getCurrentUrl());
+
+ selenium.keyPress("id=" + id, "\\13");
+ }
+
}
File mainReference = getScreenshotReferenceFile(identifier);
- List<File> alternativeFiles = findReferenceAlternatives(mainReference);
- List<File> failedReferenceAlternatives = new ArrayList<File>();
+ List<File> referenceFiles = findReferenceAndAlternatives(mainReference);
+ List<File> failedReferenceFiles = new ArrayList<File>();
- for (File file : alternativeFiles) {
- if (testBench(driver).compareScreen(file)) {
+ for (File referenceFile : referenceFiles) {
+ if (testBench(driver).compareScreen(referenceFile)) {
+ // There might be failure files because of retries in TestBench.
+ deleteFailureFiles(referenceFile);
break;
} else {
- failedReferenceAlternatives.add(file);
+ failedReferenceFiles.add(referenceFile);
}
}
File referenceToKeep = null;
- if (failedReferenceAlternatives.size() != alternativeFiles.size()) {
- // Matched one comparison but not all, remove all error images +
- // HTML files
- } else {
+ if (failedReferenceFiles.size() == referenceFiles.size()) {
// Ensure we use the correct browser version (e.g. if running IE11
// and only an IE 10 reference was available, then mainReference
// will be for IE 10, not 11)
// Remove all PNG/HTML files we no longer need (failed alternative
// references or all error files (PNG/HTML) if comparison succeeded)
- for (File failedAlternative : failedReferenceAlternatives) {
+ for (File failedAlternative : failedReferenceFiles) {
File failurePng = getErrorFileFromReference(failedAlternative);
if (failedAlternative != referenceToKeep) {
// Delete png + HTML
- File failureHtml = htmlFromPng(failurePng);
-
- failurePng.delete();
- failureHtml.delete();
+ deleteFailureFiles(failurePng);
}
}
}
+ private void deleteFailureFiles(File failurePng) {
+ File failureHtml = htmlFromPng(failurePng);
+
+ failurePng.delete();
+ failureHtml.delete();
+ }
+
/**
* Returns a new File which points to a .html file instead of the given .png
* file
* @return all references which should be considered when comparing with the
* given files, including the given reference
*/
- private List<File> findReferenceAlternatives(File reference) {
+ private List<File> findReferenceAndAlternatives(File reference) {
List<File> files = new ArrayList<File>();
files.add(reference);