test: add new test 'Element Handle Type' and 'Element Handle Press' (#211)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestElementHandlePress extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldWork() {
|
||||
page.setContent("<input type='text' />");
|
||||
page.press("input", "h");
|
||||
assertEquals("h", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotSelectExistingValue() {
|
||||
page.setContent("<input type='text' value='hello' />");
|
||||
page.press("input", "w");
|
||||
assertEquals("whello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResetSelectionWhenNotFocused() {
|
||||
page.setContent("<input type='text' value='hello' /><div tabIndex=2>text</div>");
|
||||
page.evalOnSelector("input", "input => {\n" +
|
||||
" input.selectionStart = 2;\n" +
|
||||
" input.selectionEnd = 4;\n" +
|
||||
" document.querySelector('div').focus();\n" +
|
||||
" }");
|
||||
page.press("input", "w");
|
||||
assertEquals("whello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotModifySelectionWhenFocused() {
|
||||
page.setContent("<input type='text' value='hello' />");
|
||||
page.evalOnSelector("input", "input => {\n" +
|
||||
" input.focus();\n" +
|
||||
" input.selectionStart = 2;\n" +
|
||||
" input.selectionEnd = 4;\n" +
|
||||
" }");
|
||||
page.press("input", "w");
|
||||
assertEquals("hewo", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithNumberInput() {
|
||||
page.setContent("<input type='number' value=2 />");
|
||||
page.press("input", "1");
|
||||
assertEquals("12", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.microsoft.playwright;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestElementHandleType extends TestBase {
|
||||
|
||||
@Test
|
||||
void shouldWork() {
|
||||
page.setContent("<input type='text' />");
|
||||
page.type("input", "hello");
|
||||
assertEquals("hello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotSelectExistingValue() {
|
||||
page.setContent("<input type='text' value='hello' />");
|
||||
page.type("input", "world");
|
||||
assertEquals("worldhello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResetSelectionWhenNotFocus() {
|
||||
page.setContent("<input type='text' value='hello' /><div tabIndex=2>text</div>");
|
||||
page.evalOnSelector("input", "input => {\n" +
|
||||
" input.selectionStart = 2;\n" +
|
||||
" input.selectionEnd = 4;\n" +
|
||||
" document.querySelector('div').focus();\n" +
|
||||
" }");
|
||||
page.type("input", "world");
|
||||
assertEquals("worldhello", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotModifySelectionWhenFocus() {
|
||||
page.setContent("<input type='text' value='hello' />");
|
||||
page.evalOnSelector("input", "input => {\n" +
|
||||
" input.focus();\n" +
|
||||
" input.selectionStart = 2;\n" +
|
||||
" input.selectionEnd = 4;\n" +
|
||||
" }");
|
||||
page.type("input", "world");
|
||||
assertEquals("heworldo", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWorkWithNumberInput() {
|
||||
page.setContent("<input type='number' value=2 />");
|
||||
page.type("input", "13");
|
||||
assertEquals("132", page.evalOnSelector("input", "input => input.value"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user