Отвечая исключительно на вопрос, вы можете использовать @TestPropertySource(locations="...")
& @RunWith(SpringRunner.class)
, ниже вы можете найти полный (наивный) образец (также небольшое вступление ).
Однако, в зависимости от вашей конечной цели (модульное тестирование, регрессия, система, стресс и т. Д.), Вы можете пересмотреть свой подход, например, иметь начальную секцию «setup» , которая снабжает систему необходимыми даннымизапустить весь пакет, возможно, включая создание и авторизацию выделенных учетных записей пользователей.
1) Код
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) Результат