Replying solely to the question, you can use @TestPropertySource(locations="...")
& @RunWith(SpringRunner.class)
, below you can find a full (naive nonetheless) sample (also a small intro).
However, depending on your end goal (unit testing, regression, system, stress, etc) you may want to reconsider your approach, like having an initial "setup" section that provisions the system with whatever data is required to run the whole suite, possibly including the creation and authorization of dedicated user accounts to be used.
1) Code
package com.example;
import com.vaadin.testbench.TestBenchTestCase;
import com.vaadin.testbench.elements.TextFieldElement;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@RunWith(SpringRunner.class)
@TestPropertySource(locations = "my-custom-config.properties")
public class SpringTestbenchTest extends TestBenchTestCase {
@Value("${input.text:unknown}")
private String text;
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "D:\\Kit\\Selenium\\chromedriver_win32\\chromedriver.exe");
setDriver(new ChromeDriver());
}
@After
public void tearDown() throws Exception {
getDriver().quit();
}
@Test
public void shouldTypeTextInInputBox() {
// open the browser
getDriver().get("https://demo.vaadin.com/sampler/#ui/data-input/text-input/text-field");
// wait till the element is visible
WebDriverWait wait = new WebDriverWait(getDriver(), 5);
TextFieldElement textBox = (TextFieldElement) wait.until(ExpectedConditions.visibilityOf($(TextFieldElement.class).first()));
// set the value and check that its caption was updated accordingly
textBox.setValue(text);
assertThat(textBox.getCaption(), is(Math.min(text.length(), 10) + "/10 characters"));
}
}
2) src/test/resources/com/example/my-custom-config.properties
input.text=vaadin
3) Result
