JavaScript Protractor test fails, but manually testing the same thing works (possibly related to $httpBackend) protractor test fails,protractor test failed element not visible,protractor

Alright, so my protractor test works if I'm not using a mock backend, and everything works as expected when I manually test the functionality (even with a mock backend). The only thing that doesn't work is the protractor test with $httpBackend.

I have the following test:

it("should navigate to add employee and add an employee.", function () {
    var tableRowsBeforeAdd = element.all(by.repeater("employee in ec.employees")).count();

    var button = element(by.className("btn"));
    button.click();

    expect(browser.getCurrentUrl()).toContain('add');

    var jmbgInput = element(by.model("ec.employee.jmbg"));
    jmbgInput.sendKeys("9988776655000");
    var nameInput = element(by.model("ec.employee.name"));
    nameInput.sendKeys("Test name");
    var surnameInput = element(by.model("ec.employee.surname"));
    surnameInput.sendKeys("Test surname");

    var submit = element(by.buttonText("Save"));
    submit.click();

    expect(browser.getCurrentUrl()).not.toContain('add');

    ...

Now, the browser opens (the default url points to a list view of employees), click on the correct button and opens the add/edit form for an employee. It enters the correct information into the input boxes, and it clicks on the button, but at that moment it crashes. The expect statement listed at the end of the code above, as well as all other expect blocks after that one fail, since it acts as if the list view didn't load, which it should, according to my service:

employee.$update().then(function() {
    employees.push(employee);
    $location.path('/');
});

My employee is a $resource service, and I'd avoid listing all the other code, as it's the same code that works when I use a real backend as well as when I manually use the app.

Now, one thing I'd like to add is the function which I run in the appe2e module:

function appe2ePrep($httpBackend, $location) {
    $httpBackend.whenGET("app/components/employee/employee-list.html").passThrough();
    $httpBackend.whenGET("app/components/employee/employee-detail.html").passThrough();
    var employees = [
        {jmbg:"1", name: "Mirko", surname: "Ivovkić"},
        {jmbg:"2", name: "Nikola", surname: "Tešić"},
        {jmbg:"3", name: "Robert", surname: "Stefanović"},
        {jmbg:"4", name: "Aleksa", surname: "Trifković"}
    ];
    // All employees
    $httpBackend.whenGET(dbEndpoint + "?apiKey=" + appKey).respond(employees);

    // adds a new employee
    $httpBackend.whenPUT(dbEndpoint + "/9988776655440?apiKey=" + appKey).respond(function (method, url, data) {
        return [200];
    });
}

From what I can tell there is a problem with the $location, or at least with the route as the page that should load after the click doesn't.

Answer:1

I am calling a callback function after ajax call as shown below. var mypage= {}; var mypagebox = { somefunction: function() { var self = this; self.createID(obj, function(resp) ...

I am calling a callback function after ajax call as shown below. var mypage= {}; var mypagebox = { somefunction: function() { var self = this; self.createID(obj, function(resp) ...

I have a markup that looks like the following: <div class="accordion is-open"> <h3 class="accordion-header"> HADER <span class="accordion-indicator"></span>...

I have a markup that looks like the following: <div class="accordion is-open"> <h3 class="accordion-header"> HADER <span class="accordion-indicator"></span>...

  1. click remove class jquery
  2. click remove class
  3. click anywhere remove class jquery
  4. click add remove class jquery
  5. body click remove class
  6. click outside remove class
  7. on click remove class javascript
  8. click outside remove class jquery
  9. body click remove class jquery
  10. click function remove class
  11. ng-click remove class
  12. js click remove class
  13. document click remove class
  14. window click remove class
  15. click button remove class
  16. vue click remove class
  17. if click remove class
  18. double click remove class jquery
  19. on click remove class from parent div
  20. second click remove class

I'm using vuejs in my project and noticed that when a page is in loading state, I see something like this {{ user.id }} {{ user.name }} which is very annoying. And after the page is fully loaded, I ...

I'm using vuejs in my project and noticed that when a page is in loading state, I see something like this {{ user.id }} {{ user.name }} which is very annoying. And after the page is fully loaded, I ...

I have a rectangle on an SVG element. I then want to draw another rectangle over the whole SVG area except the rect I've already drawn. I thought masks might be a solution but they seem to act just ...

I have a rectangle on an SVG element. I then want to draw another rectangle over the whole SVG area except the rect I've already drawn. I thought masks might be a solution but they seem to act just ...