NightwatchJS和WebdriverIO有什么区别? [英] What is the difference between NightwatchJS and WebdriverIO?

查看:95
本文介绍了NightwatchJS和WebdriverIO有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,Nightwatch.js和Webdriver.io有什么区别?

As the title states, what is the difference between Nightwatch.js and Webdriver.io?

似乎它们具有相同的语法,并且几乎可以完成相同的操作.它们有什么不同?

It seems like they have kind of the same syntax and do almost the same thing. How are they different?

我需要在它们之间进行选择.

I need to choose between them.

推荐答案

我已经多次使用这些工具编写了一个测试套件.

I've written a test suite using each of these tools a few times.

Webdriver.io允许您从头开始"编写测试用例,并且可以通过使用slack npm和其他软件包与slack集成来很好地控制报告.您需要了解或快速学习node.js.除了可以很好地与桌面浏览器配合使用之外,它还可以与Appium,Android Studio和Xcode很好地集成在一起,因此您可以在本地的Android模拟器和iOS模拟器上运行自动化测试.您将需要安装这些东西并编写一些代码来告诉Appium要使用哪些驱动程序,并选择功能等.

Webdriver.io allows you to write your test cases "from scratch" and have great control over reporting, by say, integrating with slack using slack npm, and other packages. You would need to know or quickly learn node.js. In addition to working very well with desktop browsers, it integrates well with Appium, Android Studio, and Xcode so you can run your automated tests on Android emulators and iOS simulators locally. You will need to install those things and write some code to tell Appium which drivers to use, and select capabilities, etc.

Nightwatch是一个相当广泛的解决方案,它使用迭代器在测试失败时自动重试多达三遍. Nightwatch对与SauceLabs等VM工具的集成提供了不错的支持,因此理论上您可以针对700多种不同平台/浏览器/版本组合运行测试用例,而无需编写代码来管理每个驱动程序. Nightwatch为您处理硒的启动和关闭.虽然这听起来很令人印象深刻,但实际上,要达到&保持测试覆盖率水平. Nightwatch还具有内置的关注点分离功能,使您可以定义自定义命令,并在基本测试用例或单个测试中要求它们.您可以将测试的某些部分模块化并导入它们,这样您就不必经常重写登录测试,以在多种情况下使用.此外,您可以使用自定义命令将选择器作为键值对导入.

Nightwatch is a fairly extensive solution that uses an iterator to automatically re-try tests up to three times when they fail. Nightwatch has decent support for integration with VM tools like SauceLabs so that you can theoretically run your test cases against 700+ different platform/browser/version combinations without writing code to manage each driver. Nightwatch handles starting and shutting down selenium for you. While this last sounds very impressive, in reality it's quite a lot of work to attain & maintain that level of test coverage. Nightwatch also has fairly built-in separation of concerns, allowing you to define custom commands and require them in your base test case or individual tests. You could modularize some portions of tests and import them so that you don't have to constantly re-write say, the login test for use in multiple cases. Additionally, you could use custom commands to import selectors as key value pairs.

使用完每一个,我都会这样总结:

webdriver.io::如果您正在寻找更多控制权,那么这是一个非常自定义的解决方案,不需要迭代器,并且您有足够的知识来编写用于选择代码的代码浏览器驱动程序,设置功能,并且您希望对报告进行自定义控制.

webdriver.io: If you're looking for more control, a very custom solution and you don't need an iterator, and you are confident that you know enough to write code for selecting your browser driver, setting capabilities and you want custom control of your reporting.

夜间监视:如果您只是想快速开始编写测试,则可以知道在特定平台/浏览器/版本上运行测试相对容易,并且仍将为您提供极大的灵活性来扩展您的测试通过编写自定义命令进行测试.

Nightwatch: if you want to just start writing tests quickly, to know that it will be relatively easy to run them against specific platforms/browsers/versions and will still allow you significant flexibility to extend your tests by writing custom commands.

Dalek.js现在是另一个选择,它可以轻松创建Nightwatch脚本,但没有所有麻烦.

Another option out there right now is Dalek.js, which has the easy script creation of Nightwatch but without all the bells and whistles.

在运行夜表之前,您可以在Magellan.json文件中配置浏览器,然后在运行测试时调用浏览器或一组浏览器(配置文件")作为命令行参数,因此:

Prior to running nightwatch, you can configure browsers in the Magellan.json file, and then when you run your test you call the browsers, or a set of browsers (a "profile") as command line arguments, thusly:

对于本地浏览器:

./node_modules/.bin/magellan --serial --browsers=chrome,firefox

假设您已经建立了一个saucelabs帐户并添加了用户名和访问密钥,则可以调用如下浏览器的配置文件:

Assuming you have setup a saucelabs account and added you username and access key, you could call a profile of browsers like this:

./node_modules/.bin/magellan --serial --profile=myBrowsers

这假定您已经在Magellan.json文件中设置了一个名为myBrowsers的配置文件,如下所示:

This assumes you have setup a profile called myBrowsers in the Magellan.json file like this:

{
    "profiles": {
        "myBrowsers": [
          { "browser": "chrome_46_OS_X_10_10_Desktop" },
          { "browser": "firefox_42_Windows_2012_R2_Desktop" },
          { "browser": "safari_8_OS_X_10_10_Desktop" },
          { "browser": "safari_7_OS_X_10_9_Desktop" }, 
          { "browser": "safari_9_OS_X_10_11_Desktop" }, 
          { "browser": "IE_10_Windows_2012_Desktop" }, 
          { "browser": "IE_11_Windows_2012_R2_Desktop" },
          { "browser": "chrome_45_OS_X_10_8_Desktop" },
          { "browser": "chrome_45_OS_X_10_9_Desktop" },
          { "browser": "chrome_45_OS_X_10_10_Desktop" },
          { "browser": "chrome_45_OS_X_10_11_Desktop" },
          { "browser": "chrome_46_OS_X_10_10_Desktop" }, 
          { "browser": "chrome_45_Windows_10_Desktop" },
          { "browser": "chrome_45_Windows_2003_Desktop" },
          { "browser": "chrome_45_Windows_2008_Desktop" },
          { "browser": "chrome_45_Windows_2012_Desktop" },
          { "browser": "chrome_45_Windows_2012_R2_Desktop" },
          { "browser": "chrome_46_Windows_10_Desktop" },
          { "browser": "chrome_46_Windows_2003_Desktop" },
          { "browser": "chrome_46_Windows_2008_Desktop" },
          { "browser": "chrome_46_Windows_2012_Desktop" },
          { "browser": "chrome_46_Windows_2012_R2_Desktop" }, 
          { "browser": "firefox_42_OS_X_10_9_Desktop" }, 
          { "browser": "firefox_42_Windows_2012_R2_Desktop" },
          { "browser": "android_4_4_Linux_Samsung_Galaxy_S4_Emulator", "orientation": "portrait" },
          { "browser": "ipad_8_4_iOS_iPad_Simulator", "orientation": "landscape"},
          { "browser": "ipad_8_4_iOS_iPad_Simulator", "orientation": "landscape"},
          { "browser": "ipad_9_0_iOS_iPad_Simulator", "orientation": "landscape"},
          { "browser": "ipad_9_0_iOS_iPad_Simulator", "orientation": "portrait"},
          { "browser": "ipad_9_1_iOS_iPad_Simulator", "orientation": "landscape"},
          { "browser": "ipad_9_1_iOS_iPad_Simulator", "orientation": "portrait"},
          { "browser": "iphone_9_1_iOS_iPhone_Simulator", "orientation": "portrait"},
          { "browser": "iphone_9_1_iOS_iPhone_Simulator", "orientation": "landscape"}

        ]
}

}

一些更有用的(可选)命令栏:

SOME OF THE MORE USEFUL (optional) COMMAND LINE ARGS:

切换--serial参数会导致测试执行序列化,并具有更详细的测试经验,您可以在其中查看运行期间返回的错误.等待测试完成还需要更长的时间.

toggling the --serial argument results in the test execution being serialized and with more verbose test experience where you can review the errors that have been returned during a run. It also take much longer to run as it wait for tests to complete.

在测试用例适用于本地计算机上存在的浏览器后,添加--sauce参数,您可以使用Sauce Labs支持的(当前)760个浏览器.继续将其粘贴到终端&点击返回:

adding the --sauce argument once your test cases work for browsers that exist on your local machine, you can tap into the (currently) 760 browsers supported by Sauce Labs. Go ahead an paste this into the terminal & hit return:

./node_modules/.bin/magellan --serial --list_browsers

对于要测试的每个设备/浏览器,只需将列表添加到 执行脚本时,在--browser =之后以逗号分隔的值形式复制粘贴命令行选项列.注意:在不使用--sauce的情况下运行时,您可以使用 --browser = chrome或--browser = chrome,firefox

For each device/browser you want to test you just add the listing in the Copy-Paste Command-Line Option column as comma separated values after --browser= when executing the script. NOTE: when running without --sauce you can just use --browser=chrome or --browser=chrome,firefox

BREAKING IT DOWN:

使用不带--sauce但带--serial的夜表是上手的好方法. 使用脚本,直到您验证了要检查的内容,并且确信可以通过酱料实验室和要测试的主要浏览器确定所有应该通过,执行和运行的测试.一旦您确信可以使用主要的浏览器,则可以不使用--serial来运行它,以减少运行时间(在Sauce Labs上有用,这会花费金钱).

Using nightwatch without the --sauce but with --serial is a great way to get started. Work on your script until you have validated the things you want to check and when you are confident that all tests that should pass, do, run it with sauce labs and the major browsers you want to test. Once you are confident that the major browsers are covered you can run it without --serial to reduce run time (useful on Sauce Labs, which will cost money).

但是,充分的介绍,您可以在这里找到有关Saucelabs的需求: https://wiki.saucelabs.com/display/DOCS/The + Sauce + Labs + Cookbook + Home

But enough proselytizing, you can find out what you need about Saucelabs here: https://wiki.saucelabs.com/display/DOCS/The+Sauce+Labs+Cookbook+Home

对于守夜人"的样例示例,它可以做一个经典的"hello world":尝试这个样例

And for a boilerplate example of Nightwatch to do the canonical hello world: try this boilerplater

更新:自发布此信息以来,人们提出了一些观点.

UPDATES: A few points that people are bringing up and that have occurred to me since posting this.

Webdriver.io: 由于没有迭代器,因此在测试执行期间从故障中恢复的能力较小,这意味着故障更具确定性.因为这纯粹是异步的,所以您可能会头疼地追踪失败的确切原因. 您可能还不得不为创建的任何数据创建单独的拆卸脚本,以免在执行过程中发生数据冲突.

Webdriver.io: Since there is no iterator, there is less ability to recover from failures during a test execution, this means failures are more definitive. Because this is purely async, you may have headaches tracing the exact origin of the failure. You may also end up having to create separate tear-down scripts for any data you create to avoid data collisions during execution.

Nightwatch.js: 由于迭代器允许您重试,因此您通常可以找到脚本失败的地方.这可能使您可以更快地找到缺陷,而不是着眼于脚本失败的原因.关闭各个脚本也更容易.

Nightwatch.js: Since the iterator allows you retries, you will often be able to find where your script is failing. This may allow you to more quickly find the defect instead of focusing on why your script is failing. It's also easier to toggle off your individual scripts.

更新2:

使用Nightwatch,可以进行更短的测试.因为迭代器在执行之前就将每次迭代的测试文件都读取到内存中,所以您可以从字面上编辑两次迭代执行之间的测试.让我说另一种方式: 您的Nightwatch套件:

With Nightwatch shorter tests are useful/encouraged. Because the iterator reads the test files into memory each and every iteration immediately before execution, you can very literally edit the tests between iteration execution. Let me say that a different way: Your Nightwatch suite:

test_1 starts
test_1 FAIL    // because you made a trivial error in your test case
test-2 starts  // while it is running, you make the change, save it
test-2 PASS
test_1 starts  // the iteration starts * with your change! *
test_1 PASS
============= Suite Complete =============

     Status: PASSED
    Runtime: 2m 48.3s
Total tests: 2
 Successful: 2 / 2
1 test(s) have retried: 1 time(s)

另一方面,使用node/webdriver.io设置Slack webhooks很容易.这意味着您可以设置节点/webdriver.io测试以在完成后向Slack报告.客户对此表示赞赏,因为在构建完成之后,他们很快就会看到自动化的结果,例如:

On the other hand, setting up Slack webhooks with node/webdriver.io is easy. What this means is that you can set up your node/webdriver.io tests to report to Slack when they complete. Clients appreciate this because after a build has completed they soon see the results of the automation, like:

✅使用OS X Firefox 59.0.2在[服务器URL或IP地址]上传递的[客户端/产品名称] Sprint ##.#.#的自动化测试

✅ Automated testing of [client/product name here] Sprint ##.#.# passed on [server URL or IP address] with OS X Firefox 59.0.2

❌使用OS X Firefox 59.0.2在[服务器URL或IP地址]上自动测试[此处的客户/产品名称] Sprint ##.#.#失败

❌ Automated testing of [client/product name here] Sprint ##.#.# failed on [server URL or IP address] with OS X Firefox 59.0.2

更新3(2017年8月6日)

我又花了一年半的时间每天与他们一起工作,所以我想补充以下几点.

Having spent another year and half working with both on a daily basis, I want to add the following points.

目前有数量相似的NPM软件包可以集成在一起,但是您会注意到关于Nightwatch(4x)的Stackoverflow问题更多.我相信这是因为Webdriver.io更像是一种自动测试的方法(这是我的看法,我欢迎反馈/回推).那些使用它的人不会对如何使用它有疑问,他们会对技术有特定的疑问.

There are similar numbers of NPM packages out there that integrate with each, but you'll note that there are far more Stackoverflow questions about Nightwatch (4x). I believe this is because Webdriver.io is more of a roll-your-own approach to automated testing [that's my opinion, and I welcome feedback/pushback]. Those who use it won't have questions about how to use it, they'll have specific questions about techniques.

对于拥有丰富Selenium IDE和扎实的javascript经验的人来说,Nightwatch将是一个更好的切入点.它提供了许多有用的解决方案.我对Dalek的一点经验表明,这同样是个不错的选择.

Nightwatch would be a better entry point for someone with extensive Selenium IDE and solid javascript experience. It has a lot of useful solutions out of the box. What little experience I have with Dalek suggests that would similarly be a good option.

具有更多javascript的人,也许还有一些面向对象的编程和UNIX的经验,可能会发现Webdriver.io更好.正如我目前所做的那样,这只是构建自己的自定义框架的绝佳选择.如果您可以设想自己希望初始化,流控制和报告如何工作,并愿意投入大量精力,那就很合适了.

Someone with more javascript and perhaps some Object Oriented Programming and unix experience would likely find Webdriver.io to be better. It's just a great option to build your own custom framework, as I am currently doing. If you can envision how you would like your initialization, flow control and reporting to work, and are willing to put in the sweat equity, it's apt.

在下面我被问到我更喜欢哪个,到目前为止,我更喜欢Webdriver.io进行广泛的e2e测试.虽然我经常使用个性化的Nightwatch存储库来构建基于我们平台的大多数客户端工作,但是随着我构建自己的Webdriver.io解决方案,这种情况可能会在不久的将来发生变化.

I was asked below which I prefer, and I prefer Webdriver.io for extensive e2e tests by far. While I often use a personalized Nightwatch repo for most client work built on top of our platform, that may change in the near future as I build my own Webdriver.io solution.

更新4(2018年5月2日)

已更新,以使控制硒和浏览器驱动程序清晰明了,并增加了一些有关使用Appium和Xcode/Android Studio的详细信息.

Updated for clarity about controlling Selenium and browser drivers as well as adding some details about using Appium and Xcode/Android Studio.

这篇关于NightwatchJS和WebdriverIO有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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