Testing AngularJS with Selenium

后端 未结 12 768
梦毁少年i
梦毁少年i 2020-11-27 04:56

I have a SPA application on stack ASP MVC + AngularJS and I\'d like to test the UI. For now I\'m trying Selenium with PhantomJS and WebKit drivers.

This is a sample

12条回答
  •  广开言路
    2020-11-27 05:25

    You may just mine protractor for useful code snippets. This function blocks until Angular is done rendering the page. It is a variant of Shahzaib Salim's answer, except that he is polling for it and I am setting a callback.

    def wait_for_angular(self, selenium):
        self.selenium.set_script_timeout(10)
        self.selenium.execute_async_script("""
            callback = arguments[arguments.length - 1];
            angular.element('html').injector().get('$browser').notifyWhenNoOutstandingRequests(callback);""")
    

    Replace 'html' for whatever element is your ng-app.

    It comes from https://github.com/angular/protractor/blob/71532f055c720b533fbf9dab2b3100b657966da6/lib/clientsidescripts.js#L51

提交回复
热议问题