From a37423b74aa785622bd745555ba418cee9f35f54 Mon Sep 17 00:00:00 2001 From: Eugenio Romano Date: Mon, 8 Jun 2020 23:59:36 +0100 Subject: [PATCH] add drop actions utils --- .../src/lib/core/actions/drop.actions.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/testing/src/lib/core/actions/drop.actions.ts b/lib/testing/src/lib/core/actions/drop.actions.ts index 1e5c2524ee..27b76abfaa 100644 --- a/lib/testing/src/lib/core/actions/drop.actions.ts +++ b/lib/testing/src/lib/core/actions/drop.actions.ts @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { browser } from 'protractor'; +import { browser, ElementFinder } from 'protractor'; import * as path from 'path'; import * as fs from 'fs'; import * as remote from 'selenium-webdriver/remote'; +import { BrowserActions } from '../utils/browser-actions'; const JS_BIND_INPUT = function(target) { const input = document.createElement('input'); @@ -97,4 +98,22 @@ export class DropActions { const input: any = await browser.executeScript(JS_BIND_INPUT_FOLDER, elem); return input.sendKeys(absolutePath); } + + protected async dragAndDrop(elementToDrag: ElementFinder, locationToDragTo: ElementFinder, locationOffset = { x: 230, y: 280 }) { + await BrowserActions.click(elementToDrag); + await browser.actions().mouseDown(elementToDrag).mouseMove(locationToDragTo, locationOffset).mouseUp().perform(); + await browser.actions().doubleClick(locationToDragTo).perform(); + } + + async dragAndDropNotClickableElement(elementToDrag: ElementFinder, locationToDragTo: ElementFinder) { + await browser.actions().mouseMove(elementToDrag).perform(); + await browser.actions().mouseDown(elementToDrag).perform(); + await browser.actions().mouseMove({ x: 10, y: 100 }).perform(); + await browser.actions().mouseMove(locationToDragTo).perform(); + return browser.actions().mouseUp().perform(); + } + + async dropElement(locationToDragTo: ElementFinder) { + await browser.actions().mouseDown(locationToDragTo).perform(); + } }