2016-06-24 34 views
5

我正在使用量角器来测试Angular代码。当我通过chrome驱动运行它时,测试运行正常,默认情况下使用webdriver-manager。现在我想用phantomjs(无头浏览器)运行相同的测试,因为我需要通过服务器运行此测试。但通过phantomjs运行测试,而我得到的错误:无法使用phantomjs运行量角器测试

Failed: Angular could not be found on the page URL : retries looking for angular exceeded

的conf文件是:

exports.config = { 
framework: 'jasmine', 
seleniumAddress: 'http://localhost:4444/wd/hub', 
specs: ['demo-test.js'], 
capabilities: { 
    browserName: 'phantomjs', 
    version: '', 
    platform: 'ANY' 
}; 

演示test.js文件看起来像:

// demo-test.js 
describe('Protractor Demo App', function() { 
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000; 

beforeEach(function() { 
    browser.driver.manage().window().setSize(1280, 1024); 
}); 
it('should have a title', function() { 
    browser.get('URL'); 

    expect(browser.getTitle()).toEqual('Title'); 

}); 

请帮助我。我以官方site和安装phantomjs指令通过

sudo apt-get install phantomjs

+1

我不会用量角器推荐phantomJS。请尝试在您的服务器上使用带有铬的XVFB,以虚拟显示器运行浏览器。 – martin770

+0

嘿@ martin770感谢您的建议,你能提供任何文件链接,我可以找到如何做到这一点? –

回答

1

安装量角器您增加超时错误:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000; 

此超时茉莉花测试不运行的时间过长。如果你想等待页面加载和角度上页长 - 添加这量角器配置文件:

getPageTimeout: timeout_in_millis //default 10 sec 
allScriptsTimeout: timeout_in_millis //default 11 sec 

此处详细了解超时 - http://www.protractortest.org/#/timeouts

也检查你指向正确的根元素:

// CSS Selector for the element housing the angular app - this defaults to 
    // body, but is necessary if ng-app is on a descendant of <body>. 
    rootElement: 'body', 

我不会推荐在phantomJS捉迷藏量角器测试中,它的作品真的不同于真正的浏览器,有时你可能会跳过真正的bug,或者找到与特定phantomJS东西。

+0

谢谢@ Xotabu4,你会推荐什么呢? –

+0

如果你的大部分用户都使用chrome或firefox。 – Xotabu4

相关问题