]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added a button hitting method to AbstractTB3Test.
authorSauli Tähkäpää <sauli@vaadin.com>
Mon, 31 Mar 2014 07:44:44 +0000 (10:44 +0300)
committerSauli Tähkäpää <sauli@vaadin.com>
Tue, 1 Apr 2014 09:55:31 +0000 (09:55 +0000)
Refactored LayoutTesterApplicationTest.
Refactored SliderDisableTest.

Change-Id: I038fedb9d234656b85359ce7fb778b001e6f4402

uitest/src/com/vaadin/tests/components/slider/SliderDisableTest.java
uitest/src/com/vaadin/tests/layouts/layouttester/LayoutTesterApplicationTest.java
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java
uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java

index f8fed28fac90e6c25b694a16d088dd350dcbea13..923d0f46abc1f41aac0e88e60b5520df5be5f700 100644 (file)
@@ -17,6 +17,7 @@ package com.vaadin.tests.components.slider;
 
 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;
@@ -33,16 +34,16 @@ public class SliderDisableTest extends MultiBrowserTest {
     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() {
@@ -56,9 +57,9 @@ public class SliderDisableTest extends MultiBrowserTest {
         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
index 8996e62503cce3e92debe5a049c077b4e4a7405f..6ba5109ce79ecf0765188b1b58991809625e7fbc 100644 (file)
@@ -22,11 +22,10 @@ import java.util.Set;
 
 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;
@@ -39,6 +38,7 @@ public class LayoutTesterApplicationTest extends MultiBrowserTest {
         DesiredCapabilities cap = new DesiredCapabilities(
                 super.getDesiredCapabilities());
         cap.setCapability("nativeEvents", false);
+
         return cap;
     }
 
@@ -86,7 +86,6 @@ public class LayoutTesterApplicationTest extends MultiBrowserTest {
         new Select(vaadinElementById("layoutSelect").findElement(
                 By.xpath("select")))
                 .selectByVisibleText(layoutClass.toString());
-        focusElementWithId("nextButton");
 
         for (String subTest : LayoutTesterApplication.layoutGetters) {
             compareScreen(subTest);
@@ -96,22 +95,12 @@ public class LayoutTesterApplicationTest extends MultiBrowserTest {
                     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.
@@ -122,15 +111,16 @@ public class LayoutTesterApplicationTest extends MultiBrowserTest {
      */
     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) {
@@ -140,8 +130,4 @@ public class LayoutTesterApplicationTest extends MultiBrowserTest {
     private String sanitize(String text) {
         return text.replace("%", "pct").replaceAll("[^a-zA-Z0-9]", "-");
     }
-
-    private WebElement getNextButton() {
-        return vaadinElementById(LayoutTesterApplication.NEXT_BUTTON_ID);
-    }
 }
index 55a2b809181b27440ea863f3bad437e987584078..ba5c81e8464a8602429122b166281c90d920319b 100644 (file)
@@ -42,6 +42,7 @@ import org.openqa.selenium.support.ui.ExpectedCondition;
 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;
@@ -928,4 +929,11 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
         return ((HasInputDevices) getDriver()).getKeyboard();
     }
 
+    public void hitButton(String id) {
+        WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver,
+                driver.getCurrentUrl());
+
+        selenium.keyPress("id=" + id, "\\13");
+    }
+
 }
index a51421d3d59bee452dd050955dd725efd9deb0f1..9f966d7973b5268c1ae31de76acbdef5d2c1d074 100644 (file)
@@ -101,22 +101,21 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
 
         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)
@@ -143,18 +142,22 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
 
         // 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
@@ -189,7 +192,7 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
      * @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);