Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 量角器+;角度+;安魂曲_Javascript_Angularjs_Requirejs_Protractor - Fatal编程技术网

Javascript 量角器+;角度+;安魂曲

Javascript 量角器+;角度+;安魂曲,javascript,angularjs,requirejs,protractor,Javascript,Angularjs,Requirejs,Protractor,我想用protracor测试我的应用程序,但测试失败,出现以下错误: Failed: Error while waiting for Protractor to sync with the page: "root element (html) has no injector. this may mean it is not inside ng-app." angular似乎没有完全加载,而且browser.waitForAngular()不工作。 如何设置量角器以在RequireJs负载依赖项

我想用protracor测试我的应用程序,但测试失败,出现以下错误:

Failed: Error while waiting for Protractor to sync with the page: "root element (html) has no injector. this may mean it is not inside ng-app."
angular似乎没有完全加载,而且
browser.waitForAngular()不工作。
如何设置量角器以在RequireJs负载依赖项之后继续测试

还添加了以下内容:

onPrepare:function(){
        browser.manage().timeouts().pageLoadTimeout(40000);
        browser.manage().timeouts().implicitlyWait(25000);
    }
到ocnfig文件(如上所述)导致此错误:

Failed: Error while waiting for Protractor to sync with the page: "angular could not be found on the window"

我遇到了一些类似的问题,可能是因为我们的应用程序的加载方式,但您可以尝试进行一些自定义等待:

browser.driver.wait(function() {
    return browser.driver.isElementPresent(by.css('.ng-scope'));
            }, 50000);//                           ^^or some other locator for your angular
});
例如,在您的
beforeach()中

编辑: 对于某些人来说,更改浏览器窗口大小也有帮助:

browser.manage().window().setSize(1280, 1024);

onPrepare()。

但这不是正确的解决方案。

您需要手动方式来知道Angular已从您的规范中引导。下面是我如何使用Angular、RequireJS和量角器进行设置的基本概述。这适用于我的
茉莉花2
和老茉莉花

我们想在引导的元素中添加一类
ngapp
。例如:

index.html


但是,我们不想将其放在HTML文件中,而是想使用手动引导Angular应用程序的同一个RequireJS模块添加该类。例如:

ng bootstrap.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});
检查页面是否在引导后添加此类。然后设置
量角器.conf
导出以运行
onprepare
测试。每次启动量角器时都会执行此规范,我们将使用它检查您在ng-bootstrap.js模块中添加的类

量角器-conf.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});
exports.config={
//每次启动量角器时:
onPrepare:'onPrepare.e2e.js',
};
onprepare.e2e.js
spec文件中,可以触发主页的加载。然后让量角器等待,直到在根元素上找到类
.ng app
,即:Angular已启动并准备运行量角器测试

onprepare.e2e.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});
描述(“准备时”,功能(){
//替换为您自己的URL
var baseUrl=http://127.0.0.1:8001/#/';
//开始获取页面
browser.driver.get(baseUrl);
//等待在根元素上找到“.ng app”
browser.driver.wait(函数(){
返回browser.driver.getCurrentUrl().then(函数(url){
返回browser.driver.isElementPresent(by.className('ng-app'))。然后返回(function(){
返回true;
});
});
});
});
请记住,如果您同时运行大量规范文件,则在新测试开始时可能会重新加载页面。如果您的Angular router正在使用
reload:true
param,则您的页面也可能正在重新加载

这意味着应用程序必须再次引导;在使用量角器之前,您需要再次等待引导类

为此添加一个帮助程序,并将其包含在
grandor-conf.js

helpers.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});
module.exports={
获取:函数(url){
browser.driver.get(url);
browser.driver.wait(函数(){
返回browser.driver.getCurrentUrl().then(函数(url){
返回browser.driver.isElementPresent(by.className('ng-app'))。然后返回(function(){
返回true;
});
});
});
},
};
量角器-conf.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});
helpers=require('helpers.js');
exports.config={
onPrepare:'onPrepare.e2e.js',
规格:[
“my-spec.js”
]
};
现在您的助手对您的规范是全局可见的,您可以使用新的
helper.get(url)
方法,而不是
browser.driver.get(url)
。例如:

my-spec.js

require(['angular'], function (angular, otherdeps) {

  // Start the Angular App
  angular.bootstrap(document, ['MyApp']);

  // Set the ng-app class for Angular Protractor tests
  var root = document.documentElement;

  angular.element(root).addClass('ng-app');
});
describe("Users", function() {

  it('should login', function () {

    // Wait for Angular and RequireJS to finish
    helpers.get('http://127.0.0.1:8001/#/login');

    // ...tests here...

  });

});

你能给我们看一些测试代码吗?这只是第一个镜头——这个链接是否有帮助:你在使用requireJS时是否正确引导了你的应用程序?此链接可能会有帮助是的,当使用浏览器手动加载时,应用程序可以正常工作。Tnx@cvakeitho,我尝试过,但没有帮助:(.还是同样的错误。你的angular应用程序中有
ng scope
类吗?你可以尝试其他定位器,因为睡眠有效,这意味着你只需等待angular应用程序加载,因为量角器本身有一些问题。