量角器未能找到角 [英] Protractor fails to find Angular

查看:104
本文介绍了量角器未能找到角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到量角器意识到角被加载并运行。当它完全打开Chrome成为我的应用程序加载在浏览器中,所以我知道角被加载并运行正常。

配置文件:

  exports.config = {
seleniumServerJar:C:/Dev/PrismWeb/selenium/selenium-server-standalone-2.35.0.jar',seleniumPort:空,chromeDriver:C:/Dev/PrismWeb/selenium/chromedriver.exe',seleniumArgs:[],seleniumAddress:空,allScriptsTimeout:110000规格:['C:为/ dev / prismweb /测试/ E2E / * JS'],功能:{'browserName':'铬'},的baseUrl:HTTP://本地主机:8080',rootElement的:HTML,jasmineNodeOpts:{
    的onComplete:空,
    isVerbose:真实,
    showColors:真实,
    includeStackTrace:真实,
    defaultTimeoutInterval:30000
}
};

我只带了一个测试,我试图运行和量角器,因为找不到角失败。

测试:

 描述('网页加载:',函数(){
VAR ptor;    ptor = protractor.getInstance();    beforeEach(函数(){
        ptor.get('/');
    });它('应该加载棱镜主页:',函数(){
    VAR usernameField = ptor.findElement(protractor.By.id(用户名));
    //预期(usernameField).toBeDefined();
});
});

这是我的错误:


  

不明错误:没有定义的角度(会话:JavaScript错误
  信息:铬= 30.0.1599.69)(驱动程序信息:
  chromedriver = 2.2,平台=的Windows NT 6.1 SP1的x86_64)(警告:
  服务器没有提供任何堆栈跟踪信息)命令持续时间或
  超时:19毫秒生成信息:版本:2.35.0,修订:
  c916b9d,时间:2013年8月12日15时42分01秒信息:os.name:'视窗
  7',os.arch:AMD64,os.version:'6.1',java.version:1.7.0_21
  会话ID:1ef7dcd7c5fc9c4e9e1dede050002adf驱动程序信息:
  org.openqa.selenium.chrome.ChromeDriver能力[{=平台XP,
  acceptSslCerts = TRUE,javascriptEnabled = TRUE,browserName =铬,
  铬= {chromedriverVersion = 2.2},旋转=假,
  locationContextEnabled = TRUE,版本= 30.0.1599.69,
  cssSelectorsEnabled = TRUE,databaseEnabled = TRUE,handlesAlerts = TRUE,
  browserConnectionEnabled =假,webStorageEnabled = TRUE,
  nativeEvents = TRUE,applicationCacheEnabled =假,
  takesScreenshot =真}]


我已经试过了NG-应用属性移动到body标签(并相应地改变配置),但我得到了同样的错误。我们也对HTML标签的NG-控制器属性,我试图移动的身体和离开NG-单独的应用程序属性的html标记,但结果是一样的。没有任何人有任何见解,为什么失败?

编辑:
只是一对夫妇的音符,这可能有助于。我已经更新上面的测试,包括手动引导力度。对角和所有模块的脚本标签位于页面底部的结束标记之前。 HTML标记仍然有NG-应用=对myApp属性加上NG控制器=baseController属性。如果我尝试手动引导应用程序的测试中,我得到如下:

 的ReferenceError:角没有定义

这让我担心的是,我们使用的模块之一是绝对有需要$映射到jQuery的,所以我们映射像这样一件事:

 <脚本类型=文/ JavaScript的>
    变种JQ $ = jQuery.noConflict();
    变量$ = jQuery.noConflict();
< / SCRIPT>

当NG-应用包括:

 <!DOCTYPE HTML>
< HTML NG-应用=prismAppNG控制器=baseController>
< HEAD>


解决方案

我不是太肯定做了 beforeEach()内,它(),但除此之外,你尝试等待一段时间?
显然,我的意思是 ptor.waitForAngular() ptor.wait()

尝试 ptor.sleep(10000)后您的 ptor.get()只是为了看它是否是定时的事情。

编辑:也看看在量角器API 如何的wait()

  ptor.wait(函数(){
  //返回的条件。 code将继续运行一次它是真实的
},10000); //只有做到这一点,持续10秒

编辑:尝试 ptor.driver.get('我的页面'); 而不是 ptor.get(我的页面) ;

编辑:量角器现在公开浏览器作为一个全球性,所以你可以只使用 browser.get('#的index.html /富') browser.wait()等。

I can't seem to get Protractor to realize that Angular is loaded and running. When it opens Chrome my app loads fully in the browser, so I know that Angular is loaded and running correctly.

The config file:

exports.config = {
seleniumServerJar: 'C:/Dev/PrismWeb/selenium/selenium-server-standalone-2.35.0.jar',

seleniumPort: null,

chromeDriver: 'C:/Dev/PrismWeb/selenium/chromedriver.exe',

seleniumArgs: [],

seleniumAddress: null,

allScriptsTimeout: 110000,

specs: ['c:/dev/prismweb/test/e2e/*.js'],

capabilities: {'browserName': 'chrome'},

baseUrl: 'http://localhost:8080',

rootElement: 'html',

jasmineNodeOpts: {
    onComplete: null,
    isVerbose: true,
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 30000
}
};

I've only got one test that I am trying to run and it fails because Protractor can't find Angular.

The Test:

describe('homepage loads: ', function(){
var ptor;

    ptor = protractor.getInstance();

    beforeEach(function(){
        ptor.get('/');
    });

it('should load the prism homepage: ', function(){
    var usernameField = ptor.findElement(protractor.By.id("username"));
    //expect(usernameField).toBeDefined();
});
});

This is the error I get:

UnknownError: javascript error: angular is not defined (Session info: chrome=30.0.1599.69) (Driver info: chromedriver=2.2,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 19 milliseconds Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01' System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_21' Session ID: 1ef7dcd7c5fc9c4e9e1dede050002adf Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={chromedriverVersion=2.2}, rotatable=false, locationContextEnabled=true, version=30.0.1599.69, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]

I've tried moving the ng-app attribute to the body tag (and changing the config accordingly) but I got the same error. We also have an ng-controller attribute on the html tag, and I tried moving that to the body and leaving the ng-app attribute alone on the html tag, but the result was the same. Does anybody have any insight as to why this fails?

EDIT: Just a couple of notes that might help. I've updated the test above to include the manual bootstrapping efforts. The script tags for Angular and all of the modules are located at the bottom of the page, right before the closing BODY tag. The HTML tag still has the ng-app="myApp" attribute plus the ng-controller="baseController" attribute. If I try to bootstrap the app manually in the test, I get the following:

ReferenceError: angular is not defined

One other thing that worries me is that one of the modules we use absolutely needs "$" to be mapped to jQuery, so we map it like this:

<script type="text/javascript">
    var $jq=jQuery.noConflict();
    var $=jQuery.noConflict();
</script>

Where the ng-app is included:

<!DOCTYPE html>
<html ng-app="prismApp" ng-controller="baseController">
<head>

解决方案

I'm not too sure about doing a beforeEach() within a, it() but that aside, have you tried waiting a while? Obviously by this i mean either a ptor.waitForAngular() or a ptor.wait()?

Try a ptor.sleep(10000) after your ptor.get() just to see if it is a timing thing.

Edit: also take a look at the protractor api and how wait() works:

ptor.wait(function () {
  // Return a condition. Code will continue to run once it is true      
}, 10000); // Only do this for 10 seconds

Edit: Try ptor.driver.get('my-page'); instead of ptor.get('my-page');

Edit: Protractor now exposes browser as a global so you can just use browser.get('index.html#/foo') or browser.wait() etc.

这篇关于量角器未能找到角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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