0

I was trying to automate some test cases for an angular booking app I was working on ,where I wanted to write a test case that was to be integrated with bitbucket pipeline. I found casperjs easy to start with.

There came a stage when I had to change the $scope values of the app . Here is how I did it .

32teeths
  • 1,079
  • 1
  • 11
  • 29

1 Answers1

0

CasperJS (also phantomjs) comes with an evaluate() method that takes a function inside which we could access the current page DOM context . It is recently that I understood how eval works wherever it be. Angular also comes with the angular.element(<element>).scope() that lets you access the scope of that particular element . In my case I wanted to change the start_time and end_time of a booking before clicking submit .

  casper.evaluate(function () {
    var scope = angular.element('booking-element').scope()
    var bookingForm = scope.booking;
    bookingForm.start_time = "2017-09-05 12:00";
    bookingForm.end_time = "2017-09-05 16:00"
    scope.$apply();
  });

A casper.click('.submit-button') should be submit the button for you with the updated values .

32teeths
  • 1,079
  • 1
  • 11
  • 29