使用量角器测试AngularJS应用时btstrpd错误 [英] btstrpd Error when testing AngularJS app with Protractor

查看:75
本文介绍了使用量角器测试AngularJS应用时btstrpd错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Protractor对AngularJS应用进行一些E2E测试,并且遇到了 btstrpd 错误。我是AngularJS的新手(我只是项目中的测试自动化人员),因此,我非常感谢任何有关如何使其运行的指针。

I’m currently trying to do some E2E testing of an AngularJS app using Protractor and I’m stuck with the btstrpd error. I'm new to AngularJS (I'm just the test automation guy in the project), so I’d really appreciate any pointers on how to make it run.

基本上,我只是从Protractor教程中复制并粘贴了示例配置和规范,并针对我的项目对其进行了修改:

Basically I just copied and pasted the sample configuration and specification from the Protractor tutorial and adapted it for my project:

// conf.js
exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js'],
    rootElement: 'html'
}

// spec.js
describe('Protractor Demo App', function() {

    it('should have a title', function() {
    browser.get('http://myapp.abc.de/ext/#/login');
        expect(browser.getTitle()).toEqual('My App');
    });

});

当我修改它并在网络上运行一些随机的AngularJS网站时,此方法很好用。在我当前的项目中运行它时,出现以下错误:

This works fine when I adapt it and run for some random AngularJS sites on the web. When running it for my current project I receive the following error:


1) Protractor Demo App should have a title
 Message:
 UnknownError: unknown error: [ng:btstrpd] http://errors.angularjs.org/1.3.15/ng/btstrpd?p0=document
  (Session info: chrome=43.0.2357.132)
  (Driver info: chromedriver=2.15.322448 (52179c1b310fec1797c81ea9a20326839860b7d3),platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 9 milliseconds

完整的堆栈跟踪此处

我们使用AngularJS v1.3.0和Protractor v2.1.0。该站点是自动引导的;根元素是html标记。路由提供商会导致此错误吗?配置如下:

We use AngularJS v1.3.0 and Protractor v2.1.0. The site is auto-bootstrapped; the root element is the html tag. Could the route provider be cause this error? The configuration is as followed:

var myApp = angular.module('myApp', [ 'ngRoute' ]);

myApp.config([ '$routeProvider', function($routeProvider) {

    $routeProvider.when('/', {
        templateUrl : 'app/tmpl/start.html'
    }).when('/login', {
        templateUrl : 'app/tmpl/login.html',
        controller : 'LoginController'
    }).when('/logout', {
        templateUrl : 'app/tmpl/logout.html',
        controller : 'LogoutController'
    });
} ]);

myApp.config([ '$httpProvider', function($httpProvider) {
    $httpProvider.interceptors.push("myInterceptor");
} ]);

myApp.run([ '$rootScope', function($rootScope) {
    $rootScope.$apply(function() {
        $rootScope.tokenString = "Bearer _";
    });
} ]);

index.html:

index.html:

<!doctype html>
<html ng-app="myApp"> 
<head>
    <script src="lib/jquery/jquery-2.1.1.min.js"></script>
    <script src="lib/bootstrap/js/bootstrap.js"></script>
    <script src="lib/angular/angular.min.js"></script>
    <script src="lib/angular/angular-route.min.js"></script>    

    <script src="app/app.js"></script>
    <script src="app/controller/LoginController.js"></script>
    <script src="app/controller/LogoutController.js"></script>
    <script src="app/controller/NavbarController.js"></script>
    <script src="app/services/AuthService.js"></script>
    <script src="app/services/UserService.js"></script>
    <script src="app/factories/Configurations.js"></script>
    <script src="app/factories/myInterceptor.js"></script>

    <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.css">
</head>
<body>
    <nav class="navbar navbar-default" role="navigation" ng-controller="NavbarController as navbar">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed"
                    data-toggle="collapse" data-target="#navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span> <span
                        class="icon-bar"></span> <span class="icon-bar"></span> <span
                        class="icon-bar"></span>
                </button>
                <a class="navbar-brand" ng-href="navbar.root()">myApp</a>
            </div>
            <div class="collapse navbar-collapse"
                id="navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a ng-href="#/customers">Customers</a></li> 
                    <li ng-show="!navbar.showLogout()"><a ng-href="#/login">Login</a></li>
                    <li ng-show="navbar.showLogout()"><a ng-href="#/logout">Logout</a></li> 
                </ul>
            </div>
        </div>
    </nav>
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div ng-view></div>
            </div>
        </div>
    </div>
</body>
</html>

我已经在其他线程中阅读并且已经尝试过的东西,但是到目前为止没有用:

Stuff I've read in other threads and already tried, but didn't work so far:


  • 将框架更改为 jasmine2

  • onPrepare 函数中使用 browser.driver.get

  • 使用<$ beforeEach 函数中的c $ c> browser.waitForAngular

  • 降级至量角器1.8

  • allScriptsTimeout 添加到 conf.js

  • Changing the framework to jasmine2
  • Use browser.driver.get in the onPrepare function
  • Use browser.waitForAngular in a beforeEach function
  • Downgrading to Protractor 1.8
  • Add an allScriptsTimeout to conf.js



编辑:我刚刚发现了一件有趣的事情。我可以与元素互动并执行多种方案。执行后,测试仍然失败,并显示 btstrpd 错误。

推荐答案

以下为我解决了问题

我正在使用硒webdriver在chrome浏览器上进行测试。我更新到最新的chrome浏览器,并在chrome的默认文件夹之外的以下文件夹中添加了最新的chromedriver

I am testing on chrome browser using selenium webdriver. I updated to latest chrome browser and I added the latest chromedriver in below folder apart from the default folder of chrome

C:\Program Files\nodejs\node_modules\ \量角器\node_modules\webdriver-manager\Selenium

C:\Program Files\nodejs\node_modules\protractor\node_modules\webdriver-manager\selenium

我还在上述文件夹中添加了chromedriver的zip文件。

I also added zip file of chromedriver in the above folder.

我还向环境路径变量中添加了chromedriver。

I also added the chromedriver to environmental path variable.

现在硒webdriver正在运行,我能够成功测试该项目。

Now the selenium webdriver is running and I am able to successfully test the project.

这篇关于使用量角器测试AngularJS应用时btstrpd错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆