fix inputs not being cleared

This commit is contained in:
Björn Dalfors
2024-05-29 22:03:38 +02:00
parent e19178780f
commit e009940530
4 changed files with 10 additions and 10 deletions

View File

@@ -14,7 +14,7 @@ export async function publishTopic(browser: Page) {
const topicInput = await browser.locator('//input[contains(@value,"kitchen/lamp/state")][1]') const topicInput = await browser.locator('//input[contains(@value,"kitchen/lamp/state")][1]')
await clickOn(topicInput) await clickOn(topicInput)
await deleteTextWithBackspaces(topicInput, 120, 5) await deleteTextWithBackspaces(topicInput, 120, 5)
await writeText('set', topicInput, 300) await writeText('set', topicInput)
const payloadInput = await browser.locator('//*[contains(@class, "ace_text-input")]') const payloadInput = await browser.locator('//*[contains(@class, "ace_text-input")]')
await writeTextPayload(payloadInput, 'off') await writeTextPayload(payloadInput, 'off')
@@ -34,5 +34,6 @@ export async function publishTopic(browser: Page) {
} }
async function writeTextPayload(payloadInput: Locator, text: string) { async function writeTextPayload(payloadInput: Locator, text: string) {
await payloadInput.fill(text) await clickOn(payloadInput)
await writeText(text, payloadInput)
} }

View File

@@ -4,7 +4,7 @@ import { clickOn, deleteTextWithBackspaces, showText, sleep, writeText } from '.
export async function searchTree(text: string, browser: Page) { export async function searchTree(text: string, browser: Page) {
const searchField = await browser.locator('//input[contains(@placeholder, "Search")]') const searchField = await browser.locator('//input[contains(@placeholder, "Search")]')
await clickOn(searchField, 1) await clickOn(searchField, 1)
await writeText(text, searchField, 100) await writeText(text, searchField)
await sleep(1500) await sleep(1500)
} }

View File

@@ -1,5 +1,5 @@
import { Page } from 'playwright' import { Page } from 'playwright'
import { moveToCenterOfElement, clickOn, clickOnHistory, expandTopic, sleep, writeText } from '../util' import { moveToCenterOfElement, clickOn, clickOnHistory, expandTopic, sleep } from '../util'
export async function showNumericPlot(browser: Page) { export async function showNumericPlot(browser: Page) {
await expandTopic('kitchen/coffee_maker', browser) await expandTopic('kitchen/coffee_maker', browser)

View File

@@ -19,15 +19,14 @@ export function sleep(ms: number, required = false) {
}) })
} }
export async function writeText(text: string, element: Locator, delay = 0) { export async function writeText(text: string, element: Locator, delay = 30) {
return element.fill(text) element.pressSequentially(text, { delay })
} }
export async function deleteTextWithBackspaces(element: Locator, delay = 0, count = 0) { export async function deleteTextWithBackspaces(element: Locator, delay = 30, count = 0) {
// @ts-ignore const length = count > 0 ? count : (await element.inputValue()).length
const length = count > 0 ? count : (await element.textContent()).length
for (let i = 0; i < length; i += 1) { for (let i = 0; i < length; i += 1) {
await element.press('Backspace') await element.press('Backspace', { delay: 30 })
await sleep(delay) await sleep(delay)
} }
} }