0
  • I have AngularJS application I need to test
  • I can't modify it.
  • I write my test in Selenide/Java, using JavascriptExecutor for JS execution
  • I need to click checkbox from javascript (it's necessary) in my test

The checkbox:

<input class="ng-pristine ng-valid" type="checkbox" ng-model="row.selected">

Question:

How I fire an event which updates row.selected variable in Angular's model?

Note: The AngularJS application works perfectly when clicked by human hand on a mouse. There isn't probably nothing wrong with it.

What I have tried:

jsExecutor.executeScript(""
    + "angular.element(arguments[0]).trigger('click'); "
    + "return 'doesnt matter what';",proxy);
  • proxy is WebElement
  • this approach works when clicking on the links in other test cases

Result: The checkbox has been un/checked after the javascript run but model's row.selected variable hasn't.

nnitramm
  • 1
  • 2
  • 1
    You need to update the model directly instead of using click method. See http://stackoverflow.com/questions/15424910/angularjs-access-scope-from-outside-js-function for example. In your case set model to true. – Navaneet Mar 03 '16 at 15:23
  • Isn't there a general way? Different ng-model would mean specific script to write for each page in the application e.g. – nnitramm Mar 03 '16 at 17:19

1 Answers1

0

Triggering click twice solves the problem for the automated testing purposes.

That means the checkbox ends up visually in the initial state because it is clicked twice (checked and unchecked or unchecked and checked).

The model is updated as if the checkbox was clicked only once.

There is probably an issue in AngularJS related to https://github.com/angular/angular.js/issues/3470

nnitramm
  • 1
  • 2