]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add wait for UI load to test
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 7 Sep 2017 13:15:25 +0000 (16:15 +0300)
committerHenri Sara <henri.sara@gmail.com>
Fri, 8 Sep 2017 06:44:40 +0000 (09:44 +0300)
test/servlet-containers/karaf/karaf-run/src/test/java/com/vaadin/test/osgi/KarafIntegrationIT.java

index d2d8e54a9c4f23ce642d5d67a2613f6657274f65..6cede7b3af664b71bfdc7337f2a0471839dcefb0 100644 (file)
  */
 package com.vaadin.test.osgi;
 
-import com.vaadin.testbench.TestBenchTestCase;
+import static org.junit.Assert.assertEquals;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.phantomjs.PhantomJSDriver;
+import org.openqa.selenium.support.ui.WebDriverWait;
 
-import static org.junit.Assert.assertEquals;
+import com.google.common.base.Predicate;
+import com.vaadin.testbench.TestBenchTestCase;
+import com.vaadin.testbench.elements.TextFieldElement;
 
 public class KarafIntegrationIT extends TestBenchTestCase {
 
@@ -31,11 +36,10 @@ public class KarafIntegrationIT extends TestBenchTestCase {
     private static final String APP1_URL = URL_PREFIX + "myapp1";
     private static final String APP2_URL = URL_PREFIX + "myapp2";
 
-
     @Test
     public void testApp1() {
         runBasicTest(APP1_URL, "bar");
-        //App theme should make a button pink
+        // App theme should make a button pink
         WebElement element = getDriver().findElement(By.className("v-button"));
         String buttonColor = element.getCssValue("color");
         assertEquals("rgba(255, 128, 128, 1)", buttonColor);
@@ -48,13 +52,16 @@ public class KarafIntegrationIT extends TestBenchTestCase {
 
     private void runBasicTest(String app1Url, String text) {
         getDriver().navigate().to(app1Url);
+        Predicate<WebDriver> isTrue = driver -> isElementPresent(
+                TextFieldElement.class);
+        new WebDriverWait(getDriver(), 5000).until(isTrue);
         getDriver().findElement(By.className("v-textfield")).sendKeys(text);
         getDriver().findElement(By.className("v-button")).click();
-        String foundText = getDriver().findElement(By.className("v-label")).getText();
+        String foundText = getDriver().findElement(By.className("v-label"))
+                .getText();
         assertEquals("Thanks " + text + ", it works!", foundText);
     }
 
-
     @Before
     public void setup() {
         setDriver(new PhantomJSDriver());