From 903e6b4685ecf3f0247612daf0cfd560c0a134df Mon Sep 17 00:00:00 2001 From: Jevgenijus Marinuskinas Date: Mon, 23 Nov 2020 14:05:33 +0200 Subject: [PATCH] Added new method. Added test. --- example/tests/elementActions.test.js | 14 ++++++++++++++ framework/Element.js | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/example/tests/elementActions.test.js b/example/tests/elementActions.test.js index 6ac4668..8c3eca9 100644 --- a/example/tests/elementActions.test.js +++ b/example/tests/elementActions.test.js @@ -272,6 +272,20 @@ describe("Element Actions", () => { expect(await inputElement.value()).toEqual(inputNumber); }); + it("should clear element's text value", async () => { + //Arrange + await page.goto("http://the-internet.herokuapp.com/inputs"); + const inputElement = new Element("input[type=number]"); + const inputNumber = "456"; + await inputElement.enterText(inputNumber); + + //Act + await inputElement.clearText(); + + //Assert + expect(await inputElement.value()).toEqual(""); + }); + xit("should cover element", async () => { //TODO: Test should be added and unxit`ed when DTAF-78 is implemented. }); diff --git a/framework/Element.js b/framework/Element.js index 9fdcc2a..8bd63f7 100644 --- a/framework/Element.js +++ b/framework/Element.js @@ -141,6 +141,15 @@ export default class Element { await elementHandle.type(text); } + async clearText() { + console.log(`Clearing the text value for ${this.selector} ...`); + await this.click(); + await page.keyboard.down("Control"); + await page.keyboard.press("A"); + await page.keyboard.up("Control"); + await page.keyboard.press("Backspace"); + } + async takeScreenshot() { console.log(`Taking the screenshot for ${this.selector} ...`); const elementHandle = await this.wait();