- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用karibu-testing测试Vaadin流组件。在此组件中,我正在使用UI.getCurrent().access {}
更新此组件,但是在运行测试时,不会执行access
中的代码。当我尝试在测试本身中使用UI.getCurrent().access {}
时,结果相同...一些想法吗?
pom.xml
<dependency>
<groupId>com.github.mvysny.kaributesting</groupId>
<artifactId>karibu-testing-v10</artifactId>
<version>1.1.4</version>
</dependency>
class MyUITest {
@BeforeAll
fun init() {
MockVaadin.setup()
}
@BeforeEach
fun setup() {
UI.getCurrent().removeAll()
}
@Test
fun testSometing() {
UI.getCurrent().access {
print("foo") // this line is not reachable
}
}
}
最佳答案
希望我不要误会你的问题。我尝试使用组件使用UI.getCurrent().access {}
更改UI中的某些内容来创建一个最小示例。
在这里,我有一个带有单个TextField且值为“hallo”的组件。该组件内部有一个方法,可将TextField的值更改为“嘿”。
该组件看起来像
package com.example.test;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.server.Command;
@Tag(value = "myComponent")
public class MyComponent extends Component {
private TextField textField = new TextField();
public MyComponent() {
textField.setValue("hallo");
}
public void changeValueToHey() {
UI.getCurrent().access((Command) () -> {
textField.setValue("hey");
});
}
public String getTextFieldValue() {
return textField.getValue();
}
}
@Test
public void test() {
MyComponent myComponent = new MyComponent();
UI.getCurrent().add(myComponent);
assertEquals("hallo", myComponent.getTextFieldValue());
MockVaadin.INSTANCE.runUIQueue(true);
myComponent.changeValueToHey();
MockVaadin.INSTANCE.runUIQueue(true);
assertEquals("hey", myComponent.getTextFieldValue());
}
runUIQueue
:
The thing is that Karibu Testing runs the test with the UI lock held. That simplifies testing very much, but that also prevents async updates by another thread, simply because the test is holding the lock!
The solution is to briefly let loose of the UI lock in the testing thread, allowing UI.access() tasks posted from a background thread to be processed. Then the testing thread will re-obtain the lock and continue testing.
关于kotlin - Vaadin 10+,如何在kaributesting中触发UI.getCurrent()。access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56643753/
我是一名优秀的程序员,十分优秀!