NUnit、Selenium、Selenium Grid 和 Specflow 之间的关系以及每个的 role/purpose

Relationship between NUnit, Selenium, Selenium Grid and Specflow and the role/purpose of each

使用 selenium 网格将测试代码(C#、Selenium + Specflow VS 2017 项目)修改为 运行 并在我的机器上设置 selenium 服务器后,并行测试成功 运行。

当我关闭 selenium 服务器并将测试代码修改回仅使用 webDriver 而不是 RemoteWebDriver 时,我很困惑地看到测试仍然 运行 并行......但是,我没有从 AssemblyInfo.cs 文件中删除了以下代码行:

[assembly: Parallelizable(ParallelScope.Fixtures)]

注释掉上面这行代码后,再次连续测试运行。

问题 1:Selenium 和 Specflow 都有自己的工具(不仅仅是 selenium)允许并行测试 运行,这是否正确?这是在花时间阅读试图找出 why/how 这个魔法正在发生 (specflow parallel) 后得出的结论。在出现这种意外行为之前,我没有阅读过有关 specflow 并行工具的任何内容(总是 selenium grid)。

问题2:哪个最好用?我猜测虽然 运行ning 与 Selenium 服务器并行工具 (Selenium Grid) 的并行性更高,但从长远来看,Selenium Grid 可能是最好的 运行。看起来像使用 Selenium Grid 一样,您可以一次 运行 多线程,因为您可以创建任意数量的节点,并且每个节点可以处理多个线程(浏览器)。


在 JimEvans 之后编辑 评论:

嗨,吉姆·埃文。在测试世界中阅读信息时,我经常看到你的名字。非常感谢提供信息。您在下面的陈述重定向了我的阅读和信息搜索。在详细阅读了您所说的内容之后,这就是我现在的理解。我想知道这离正确有多近……尤其是第 4 条陈述。

  1. AssemblyInfo.cs 中的语句 [assembly: ... ] 被 NUnit 测试框架读取和理解。如果 NUnit 不存在,语句 [assembly: ...] 将不存在。
  2. Specflow 和 Selenium 都可以置于(与)不同的测试框架之上;其中之一是 NUnit。 Specflow 和 Selenium 都致力于确保它们的库(NUnit 之上的代码)不会阻止使用 NUnits 并行功能。
  3. 似乎 specflow 可能对线程设置了一些限制。看起来 Specflow 架构可能最适合并行 运行 特性(固定装置 ... ParallelScope.Fixtures),但不允许特性中的场景并行 运行(ParallelScope.All 可能在 Specflow 中不起作用,但 需要进一步研究 )。
  4. 这是正确的说法吗:Selenium Grid 将 NUnit 并行执行提升到一个新的水平...它允许测试 运行几个节点......节点要么在一台机器上,要么 spaced 分布在多台机器上(获得更多的处理能力)。我猜测如果没有 Selenium Grid,NUnit 由于硬件限制只能创建这么多线程。 Selenium Grid 充当可用 space(大部分时间跨越多台机器)的管理器,用于 运行ning 测试。 Selenium webdriver 与浏览器和浏览器交互(打开和关闭浏览器)紧密相关;每个线程一个浏览器; NUnit 控制和管理线程; Selenium Grid 知道有多少资源(处理器和机器)可用于 运行ning 允许 NUnit 继续旋转新线程的线程,然后 selenium webdriver 可以在该线程上打开 Web 浏览器并开始测试。

在了解到 Selenium 没有可并行执行的特殊代码后,我开始对下图中的信息进行不同的解释(这是对 Selenium Grid 的一个很好的描述)。

Location the above text came from

SpecFlow 是 C# 的行为驱动开发测试框架

SpecFlow 确实适用于各种测试 运行ners - 在你的情况下,Nunit 充当 运行ners。 [Nunit也可以作为没有specflow的框架]

The statement [assembly: ... ] within the AssemblyInfo.cs is read and understood by the NUnit testing framework. If NUnit didn't exist the statement [assembly: ...] would not exist.

-- 正确。 [assembly: Parallelizable(ParallelScope.Fixtures)] [Parallelizable 属性来自 Nunit]1

Both Specflow and Selenium can be laid on top of (work with) different testing framework's; one of them being NUnit. Both Specflow and Selenium work to make sure their libraries (code on top of NUnit) does not block the use of the NUnits parallel capabilities.

-- SpecFlow 是 C# 的行为驱动开发测试框架,Nunit 充当 runner.There 和其他 运行ner,例如xUnit,MsTest V2。 Specflow 正在使用 Nunit 来并行 运行 特征。将 Selenium 视为与并行执行无关的独立库。

It appears that specflow might have placed some restrictions on threading. It looks like the Specflow architecture might be best suited to run features (fixtures ... ParallelScope.Fixtures) in parallel but doesn't allow scenarios within a feature to run in parallel (ParallelScope.All might not work in Specflow but need to look into this more).

-- 如果在 Assembly 中添加 Parallelizable(ParallelScope.Fixtures),则 Specflow+NUnit 运行s 功能并行。

参考:Specflow+NUnit just run features in parallel not scenarios

Is this a correct statement: Selenium Grid takes NUnit parallel execution to the next level ... it makes it even more powerful by allowing tests to run on several nodes ... the nodes either being on 1 machine or spaced out across several machines (access to more processing power). I am guessing that without Selenium Grid, NUnit could only create so many threads due to hardware limitations. Selenium Grid acts as a sort of manager of available space (most of the time across several machines) for running tests. The Selenium webdriver is closely tied to the browser and browser interaction (opening and closing of the browser); one browser per thread; NUnit is in control of and manages the threading; Selenium Grid knows how many resources (processors and machines) are available for running the threads on which allows NUnit to keep spinning out new threads and selenium webdriver can then open a web browser on that thread and start testing.

假设我们有两个特征文件。 功能文件 1 - 场景 A 功能文件 2 - 场景 B

假设我们在一项功能(一个线程)中创建一个 Chromedriver 实例。

如果两个功能 运行 并行,那么我们有两个 chromedriver 实例。当我们创建 chromedriver(远程)实例时,请求将转到 Selenium Grid hub。 根据功能,Selenium Hub 会将请求转发给有能力的节点。 Node 将创建会话(浏览器)并将会话 ID 发送回客户端(这里是 C# Selenium)。 所有未来的通信都将使用这个唯一的会话 ID 进行。由于我们运行同时使用两个功能,因此我们将有两个会话 ID。一个线程一个会话 ID。

对于 运行 在本地计算机上并行执行场景,您可能不需要您已经弄清楚的网格(RemoteWebDriver),如所讨论的那样。

Selenium hub 没有关于处理器/机器的信息。 Hub 只知道注册的节点。

以上信息以 Selenium Grid 3 为背景

您可能想了解 Selenium Grid 4 Selenium Grid 4 运行 新 Grid

的三种方式
  1. "standalone"
  2. "hub" 和 "node"
  3. "router","distributor","sessions", 和 "node"