Check angular ui route state using protractor

我的梦境 提交于 2019-12-06 14:13:32
alecxe

Sure, the idea is to use browser.executeAsyncScript() to:

Sample working test using the UI router demo page:

describe("Current Angular UI router state", function () {
    beforeEach(function () {
        browser.get("https://angular-ui.github.io/ui-router/sample/#/");
    });

    it("should get the current state", function (){
        var currentStateName = browser.executeAsyncScript(function(callback) {
            var el = document.querySelector("html");  // ng-app is defined on html element in this case
            var injector = angular.element(el).injector();
            var service = injector.get('$state');

            callback(service.current.name);
        });

        expect(currentStateName).toEqual("home");
    });
});

Heavily inspired by this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!