将量角器与 PhantomJS 一起使用

Using Protractor with PhantomJS(将量角器与 PhantomJS 一起使用)

本文介绍了将量角器与 PhantomJS 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对我的 AngularJS 应用程序进行 E2E 测试,Protractor 似乎是正确的方法.设置相当简单,它就像 Chrome 中的魅力一样.但是我需要使用无头浏览器并一直在研究如何将 Protractor 与 PhantomJS 一起使用,我发现了这一点:

I need to E2E test my AngularJS Application an Protractor seems like the right way to do it. Setup was fairly straightforward and it works like a charm in Chrome. I need however use headless browser and been researching on how to use Protractor with PhantomJS and I found this:

注意:我们建议不要使用 PhantomJS 进行 Protractor 测试.PhantomJS 崩溃和行为有许多报告的问题不同于真正的浏览器.

Note: We recommend against using PhantomJS for tests with Protractor. There are many reported issues with PhantomJS crashing and behaving differently from real browsers.

以上来自 https://github.com/angular/protractor/blob/master/docs/browser-setup.md

所以我的问题是:

  1. 情况仍然如此,Proractor 仍然存在 PhantomJS 的问题吗?

  1. Is this still the case and Proractor still having issues with PhantomJS?

如果是这样,它有多糟糕,有没有更好的选择?

If so how bad is it and is there any better option?

当我的应用部署到服务器时,我将如何进行 E2E 测试?

How would I do E2E testing when my app is being deployed to server?

推荐答案

情况仍然如此,Protractor 仍然存在 PhantomJS 问题吗?

Is this still the case and Protractor still having issues with PhantomJS?

这是真的.

如果是这样,它有多糟糕,有没有更好的选择?

If so how bad is it and is there any better option?

很难回答它有多糟糕,但是关于挂起 phantomjs、垂死 phantomjs、执行缓慢的 phantomjs 存在多个问题,例如:

It's difficult to answer how bad is it, but there are multiple issues about hanging phantomjs, dying phantomjs, performing slow phantomjs e.g.:

  • PhantomJS 有时会崩溃(开放问题超过一年)
  • PhantomJS sometimes crashes (open issue for more than a year)

根据问题,您使用 protractor 的主要原因是端到端测试.您应该尝试模仿真实世界的用例,模仿在您的应用程序中工作的真实用户.真正的用户会使用什么浏览器?幻影JS?答案可能是否定的. 使用您的应用程序设计的浏览器,以及您的真实用户使用的浏览器.

According to the question, the main reason for you to use protractor is end-to-end testing. You should try to imitate real-world use cases, imitate a real user working in your application. What browser would a real user use? PhantomJS? The answer is probably "no". Use the browsers which your application is designed to work in, and the browsers your real users use.

当我的应用部署到服务器时,我将如何进行 E2E 测试?

How would I do E2E testing when my app is being deployed to server?

最自然"的方法是使用提供不同功能(浏览器和平台)的远程 selenium 服务器.您可以启动和配置自己的 selenium 服务器,也可以使用 BrowserStackSauce Labs 做得很好,为您提供了一种在广泛的应用程序中测试您的应用程序的方法各种不同的浏览器和系统.

The most "natural" approach is to use a remote selenium server that provides different capabilities - browsers and platforms. You can start up and configure your own selenium server, or you can use BrowserStack or Sauce Labs which are doing a great job providing you a way to test your application among a wide variety of different browsers and systems.

您还可以在没有真实显示但虚拟显示 (xvfb) 的无头环境"中运行量角器,查看更多 这里.

You can also run protractor in a headless "environment" with no real, but virtual display (xvfb), see more here.

这篇关于将量角器与 PhantomJS 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将量角器与 PhantomJS 一起使用

基础教程推荐