Browse Source

Add wait for UI load to test

tags/8.2.0.alpha1
Teemu Suo-Anttila 6 years ago
parent
commit
7206862fa4

+ 13
- 6
test/servlet-containers/karaf/karaf-run/src/test/java/com/vaadin/test/osgi/KarafIntegrationIT.java View File

*/ */
package com.vaadin.test.osgi; package com.vaadin.test.osgi;


import com.vaadin.testbench.TestBenchTestCase;
import static org.junit.Assert.assertEquals;

import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver; 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 { public class KarafIntegrationIT extends TestBenchTestCase {


private static final String APP1_URL = URL_PREFIX + "myapp1"; private static final String APP1_URL = URL_PREFIX + "myapp1";
private static final String APP2_URL = URL_PREFIX + "myapp2"; private static final String APP2_URL = URL_PREFIX + "myapp2";



@Test @Test
public void testApp1() { public void testApp1() {
runBasicTest(APP1_URL, "bar"); 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")); WebElement element = getDriver().findElement(By.className("v-button"));
String buttonColor = element.getCssValue("color"); String buttonColor = element.getCssValue("color");
assertEquals("rgba(255, 128, 128, 1)", buttonColor); assertEquals("rgba(255, 128, 128, 1)", buttonColor);


private void runBasicTest(String app1Url, String text) { private void runBasicTest(String app1Url, String text) {
getDriver().navigate().to(app1Url); 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-textfield")).sendKeys(text);
getDriver().findElement(By.className("v-button")).click(); 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); assertEquals("Thanks " + text + ", it works!", foundText);
} }



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

Loading…
Cancel
Save