javascript 除了 Karma 之外,Selenium 还涵盖哪些测试?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13964235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:20:01  来源:igfitidea点击:

What testing does Selenium cover over and above Karma?

javascriptseleniumfunctional-testingkarma-runnerbrowser-automation

提问by Jason Weden

I understand that Karmais a JavaScript test runner, which can run tests in real browsers. If that is the case, what kind of test coverage does Selenium provide over and above Karma.

我知道Karma是一个 JavaScript 测试运行器,它可以在真实浏览器中运行测试。如果是这种情况,Selenium 提供的测试覆盖范围是什么,超过 Karma。

回答by inf3rno

There is a huge difference between Karma and Selenium. Selenium has a built-in browser control mechanism, while Karma does not. So Selenium is more suited to end to end testing, for example with nightwatch.js. Karma is designed for unit tests, so it is much harder to achieve end to end tests on it, you can add for example a phantomjs launcher, but it will never be the same as real browser tests with Selenium... I think both of them can run any js testing framework if you have an adapter... Mocha, jasmine, qunit, etc...

Karma 和 Selenium 之间存在巨大差异。Selenium 有一个内置的浏览器控制机制,而 Karma 没有。所以 Selenium 更适合端到端的测试,例如nightwatch.js。Karma 是为单元测试而设计的,因此对其进行端到端测试要困难得多,您可以添加例如 phantomjs 启动器,但它永远不会与使用 Selenium 进行的真实浏览器测试相同......我认为两者都是如果您有适配器,它们可以运行任何 js 测试框架... Mocha、jasmine、qunit 等...

An eternity later:

永恒之后:

It is possible to write e2e tests with Karma. You need to create an iframe or open a new window and run a script, which does the navigation, fires the events, submits forms, etc. from the parent frame or window. The tested page needs to allow your Karma server with CORS or you need to disable browser security. I am working on an e2e testing library, which does exactly this.

可以使用 Karma 编写 e2e 测试。您需要创建一个 iframe 或打开一个新窗口并运行一个脚本,该脚本从父框架或窗口执行导航、触发事件、提交表单等。被测试的页面需要允许您的 Karma 服务器使用 CORS,或者您需要禁用浏览器安全性。我正在开发一个e2e 测试库,它正是这样做的。

回答by Nashibukasan

There are several versions of Selenium, the newest (I believe) of which is Selenium Web Driver which allows you to create a driver that will handle a browser for you by simulating actions that interact with the UI much like a user would (through a Json wire).

Selenium 有多个版本,最新的(我相信)是 Selenium Web Driver,它允许您创建一个驱动程序,通过模拟与用户交互的操作来为您处理浏览器(通过 Json金属丝)。

My current understanding of Karma (which may I add is very limited) is that it relies heavily on executing javascript. Because of this Karma would have to call change events on elements (as in, 'blur' and 'hover over') whereas Selenium would just click, tab out, move cursor to. Selenium's browsers are limited to those specified on their webpage here.

我目前对 Karma 的理解(我可以补充说非常有限)是它严重依赖于执行 javascript。因此,Karma 必须在元素上调用更改事件(如“模糊”和“悬停”),而 Selenium 只需单击、跳出、将光标移动到即可。Selenium 的浏览器仅限于其网页上指定的浏览器此处

回答by Steve Tomlin

It depends what you are testing. If you are using javascript to write unit tests - via jasmine/mocha/chai or equivalent then - the argument that karma relies heavily on javascript and selenium doesn't - is redundant.

这取决于你正在测试什么。如果您使用 javascript 编写单元测试 - 通过 jasmine/mocha/chai 或等效的那么 - karma 严重依赖于 javascript 而 selenium 不依赖的论点 - 是多余的。

In all my experience I have worked with very few dedicated automated testers, and while selenium language maybe their choice, the selenium library of methods is not as easy to memorise as an equivalent selector engine like jquery.

在我的所有经验中,我与很少有专门的自动化测试人员一起工作,虽然 selenium 语言可能是他们的选择,但 selenium 方法库不像 jquery 这样的等效选择器引擎那么容易记住。

The difficulty for dedicated automated testers to learn the language, and the lack of interest for developers to learn a lesser language perpetuates the lack of investment for companies to invest in more intricate automated testing

专门的自动化测试人员学习这门语言的难度,以及开发人员对学习较弱的语言缺乏兴趣,导致公司长期缺乏投资于更复杂的自动化测试

There have been a few augmentation implementations of jquery with selenium over the years, but none really have a huge following and most are written in java.

多年来,有一些使用 selenium 的 jquery 增强实现,但没有一个真正拥有大量追随者,而且大多数都是用 java 编写的。

Webdriverio has an npm package has some jquery features - https://www.npmjs.com/package/webdriverio-jquery

Webdriverio 有一个 npm 包,有一些 jquery 功能 - https://www.npmjs.com/package/webdriverio-jquery

Karma has a means to import the whole jquery engine - https://github.com/bessdsv/karma-jasmine-jquery

Karma 有一种方法可以导入整个 jquery 引擎 - https://github.com/bessdsv/karma-jasmine-jquery

It depends what is being tested. If you are testing the front end code, then it makes sense to use javascript, and it is easier to use jquery than the selenium language and currently karma supports jquery better than webdriver.

这取决于正在测试的内容。如果你在测试前端代码,那么使用javascript是有意义的,使用jquery比selenium语言更容易,目前karma比webdriver更好地支持jquery。

Using jquery for automated testing would empower transferable skills into development and vice versa for developers into automated testing.

使用 jquery 进行自动化测试可以将可转移的技能用于开发,反之亦然,开发人员可以进行自动化测试。