From 3b495615c29e0121457c453607556da0ac466cc5 Mon Sep 17 00:00:00 2001 From: ephung01 Date: Fri, 15 Jan 2021 15:26:27 -0500 Subject: [PATCH] test: add new test 'Element Handle Type' and 'Element Handle Press' (#211) --- .../playwright/TestElementHandlePress.java | 53 +++++++++++++++++++ .../playwright/TestElementHandleType.java | 53 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 playwright/src/test/java/com/microsoft/playwright/TestElementHandlePress.java create mode 100644 playwright/src/test/java/com/microsoft/playwright/TestElementHandleType.java diff --git a/playwright/src/test/java/com/microsoft/playwright/TestElementHandlePress.java b/playwright/src/test/java/com/microsoft/playwright/TestElementHandlePress.java new file mode 100644 index 00000000..905beb34 --- /dev/null +++ b/playwright/src/test/java/com/microsoft/playwright/TestElementHandlePress.java @@ -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(""); + page.press("input", "h"); + assertEquals("h", page.evalOnSelector("input", "input => input.value")); + } + + @Test + void shouldNotSelectExistingValue() { + page.setContent(""); + page.press("input", "w"); + assertEquals("whello", page.evalOnSelector("input", "input => input.value")); + } + + @Test + void shouldResetSelectionWhenNotFocused() { + page.setContent("
text
"); + 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(""); + 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(""); + page.press("input", "1"); + assertEquals("12", page.evalOnSelector("input", "input => input.value")); + } +} diff --git a/playwright/src/test/java/com/microsoft/playwright/TestElementHandleType.java b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleType.java new file mode 100644 index 00000000..092a1f2c --- /dev/null +++ b/playwright/src/test/java/com/microsoft/playwright/TestElementHandleType.java @@ -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(""); + page.type("input", "hello"); + assertEquals("hello", page.evalOnSelector("input", "input => input.value")); + } + + @Test + void shouldNotSelectExistingValue() { + page.setContent(""); + page.type("input", "world"); + assertEquals("worldhello", page.evalOnSelector("input", "input => input.value")); + } + + @Test + void shouldResetSelectionWhenNotFocus() { + page.setContent("
text
"); + 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(""); + 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(""); + page.type("input", "13"); + assertEquals("132", page.evalOnSelector("input", "input => input.value")); + } +}