1

I just learn how to create angular.js directives.
I write simple directive for input with two-way binded selectionRange control.
When scope variable changes - selection range inside the input changes too.

How this behavior can be tested with Protractor.js?
I can not to find any method to get input current selectionRange/cursor position or even selected text.


You can found&playWith my directive here: Demo
Todo with what I want to achive here: github

When you change $scope data with form below, input selection changes.
I want just cover this behavior with test, and don't know how to get current selectionRange in the protractor environment.

vp_arth
  • 14,461
  • 4
  • 37
  • 66

1 Answers1

1

Referring to the problem I've recently solved with the help of @trincot:

expect(browser.executeScript("return arguments[0].value.substring(arguments[0].selectionStart, arguments[0].selectionEnd);", elm.getWebElement())).toEqual("selected part of the input text");

Here selectionStart and selectionEnd are used to get the currently selected text in an input.

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Explain please about `getWebElement`. It returns usual `HTMLElement`? – vp_arth Nov 11 '15 at 15:18
  • @vp_arth `elm` in this case is an `ElementFinder` instance - what is returned by `element()` call. `getWebElement()` now is required to be called if we are passing an element to the script - it basically returns a regular `HTMLElement` out of a `ElementFinder`. Hope it makes sense. – alecxe Nov 11 '15 at 15:19
  • @vp_arth I've also made an [issue](https://github.com/angular/protractor/issues/2290) so that there would be no need to explicitly call `getWebElement()` when passing an element into `executeScript()` as an argument. The issue is still open though. – alecxe Nov 11 '15 at 15:20
  • protractor test-cases reading - it can be more useful than docs :) – vp_arth Nov 11 '15 at 15:28