/*
 * Copyright 2000-2017 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.test.osgi;

import com.vaadin.testbench.TestBenchTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;

import static org.junit.Assert.assertEquals;

public class KarafIntegrationIT extends TestBenchTestCase {

    private static final String URL_PREFIX = "http://localhost:8181/";
    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
        WebElement element = getDriver().findElement(By.className("v-button"));
        String buttonColor = element.getCssValue("color");
        assertEquals("rgba(255, 128, 128, 1)", buttonColor);
    }

    @Test
    public void testApp2() {
        runBasicTest(APP2_URL, "foo");
    }

    private void runBasicTest(String app1Url, String text) {
        getDriver().navigate().to(app1Url);
        getDriver().findElement(By.className("v-textfield")).sendKeys(text);
        getDriver().findElement(By.className("v-button")).click();
        String foundText = getDriver().findElement(By.className("v-label")).getText();
        assertEquals("Thanks " + text + ", it works!", foundText);
    }


    @Before
    public void setup() {
        setDriver(new PhantomJSDriver());
    }

    @After
    public void teardown() {
        getDriver().quit();
    }
}

@@ -631,47 +631,46 @@
 ort 
-com.vaadin.testbench.TestBenchTestCase;
+static org.junit.Assert.assertEquals;%0A
 %0Aimp
@@ -769,16 +769,54 @@
 ium.By;%0A
+import org.openqa.selenium.WebDriver;%0A
 import o
@@ -904,52 +904,203 @@
 er;%0A
-%0A
 import 
-static org.junit.Assert.assertEquals
+org.openqa.selenium.support.ui.WebDriverWait;%0A%0Aimport com.google.common.base.Predicate;%0Aimport com.vaadin.testbench.TestBenchTestCase;%0Aimport com.vaadin.testbench.elements.TextFieldElement
 ;%0A%0Ap
@@ -1363,17 +1363,16 @@
 app2%22;%0A%0A
-%0A
     @Tes
@@ -1451,16 +1451,17 @@
       //
+ 
 App them
@@ -1885,16 +1885,183 @@
 p1Url);%0A
+        Predicate%3CWebDriver%3E isTrue = driver -%3E isElementPresent(%0A                TextFieldElement.class);%0A        new WebDriverWait(getDriver(), 5000).until(isTrue);%0A
         
@@ -2271,16 +2271,33 @@
 label%22))
+%0A                
 .getText
@@ -2374,17 +2374,16 @@
 %0A    %7D%0A%0A
-%0A
     @Bef

Add wait for UI load to test