简体   繁体   English

E2E 测试:Karma+JQuery 与量角器

[英]E2E testing: Karma+JQuery vs Protractor

Question

In terms of e2e testing, what can't we do with Karma and JQuery that is possible with Protractor ?在 e2e 测试方面,我们不能使用Protractor可以使用KarmaJQuery做什么?

Explanation解释

I'm currently building a testing framework for my JavaScript application.我目前正在为我的 JavaScript 应用程序构建一个测试框架。 I'm using Karma for Unit Testing and Protractor for E2E Testing as suggested by many people.正如许多人所建议的那样,我使用Karma进行单元测试,使用Protractor进行E2E 测试

I'm aware of the conceptual differences between unit testing and e2e testing, but, in the context of JavaScript, I don't clearly understand why we need framework like Protractor .我知道单元测试和 e2e 测试之间的概念差异,但是,在 JavaScript 的上下文中,我不清楚为什么我们需要像Protractor这样的框架。

As far as I know, the point of e2e testing is to use the application as a simple end-user.据我所知,e2e 测试的重点是将应用程序用作简单的最终用户。 For that, tools like Protractor use a webdriver to interact with a browser and let us simulate some user events (clicking on element, filling forms...).为此,像 Protractor 这样的工具使用webdriver与浏览器交互,让我们模拟一些用户事件(点击元素、填写表单......)。

The thing is, why can't we simply do this by using Karma and JQuery ?问题是,为什么我们不能简单地使用KarmaJQuery来做到这一点?

Indeed, JQuery comes with lots of methods to interact with a DOM element (trigger event, get/set element's property, set value to an input...).事实上, JQuery提供了许多与 DOM 元素交互的方法(触发事件、获取/设置元素的属性、将值设置为输入...)。 Furthermore, it provides selectors which make the selection of DOM element very easy.此外,它还提供了选择器,使选择 DOM 元素变得非常容易。

From my point of view, Karma and JQuery has (almost) everything needed for e2e testing (if we don't take care of the browser's window's operations available in Protractor which enable for example to set the window size or location).在我看来, KarmaJQuery拥有(几乎)e2e 测试所需的一切(如果我们不处理Protractor中可用的浏览器窗口操作,例如设置窗口大小或位置)。

I'm obviously missing something, any clarification will be helpful.我显然遗漏了一些东西,任何澄清都会有所帮助。

Using Jquery and Karma the way you would, is a behavior-driven-test but not an end-to-end test.按照您的方式使用 Jquery 和 Karma 是一种行为驱动的测试,而不是端到端的测试。

With Jquery and Karma, you can't detect cross-browser issues like you would in protractor.使用 Jquery 和 Karma,您无法像在量角器中那样检测跨浏览器问题。 Protractor on the other hand runs your tests as if it was an end-user.另一方面,Protractor 像最终用户一样运行您的测试。 It literally opens the browser you want and tests your application in that browser.它确实会打开您想要的浏览器并在该浏览器中测试您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM