针对使用Nunit在C#并行执行中的SeleniumGrid和c#numeric这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展c#–是否可以在不安装SeleniumServer的情况下使用
针对使用Nunit在C#并行执行中的Selenium Grid和c# numeric这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、FireFox中的Selenium OpenQA.Selenium.DriverServiceNotFoundException、HtmlUnit +生产中的selenium、Nunit 3和Selenium C#的报告工具等相关知识,希望可以帮助到你。
本文目录一览:- 使用Nunit在C#并行执行中的Selenium Grid(c# numeric)
- c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?
- FireFox中的Selenium OpenQA.Selenium.DriverServiceNotFoundException
- HtmlUnit +生产中的selenium
- Nunit 3和Selenium C#的报告工具
使用Nunit在C#并行执行中的Selenium Grid(c# numeric)
我刚刚为selenium网格2进行了设置。集线器和节点已启动并正在运行。我正在使用Selenium Webdriver + C#+
Nunit来运行测试,我现在想执行以下操作:
1) 将测试用例分布在不同的节点之间(并行),例如,节点1运行测试x,节点2运行测试y
2)
我需要能够为每个节点配置浏览器和平台类型,我现在要做的就是我做一个设置功能,并且所有节点都使用相同的平台和浏览器,那么如何我通过分配每个节点所需的功能来实现这一目标。
问题是当我运行即将到来的代码时,我发现测试同时运行而不是并行运行。
我的代码快照:
using System;using OpenQA.Selenium;using OpenQA.Selenium.Firefox;using OpenQA.Selenium.Chrome;using OpenQA.Selenium.Safari;using OpenQA.Selenium.Edge;using OpenQA.Selenium.IE;using OpenQA.Selenium.Support.UI;using OpenQA.Selenium.Remote;using NUnit;using NUnit.Framework;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Threading.Tasks;namespace GridTest{ [TestFixture] [Parallelizable] public class Test_Grid { IWebDriver driver; [SetUp] public void Setup() { /////IE Setup///////// var capabilities = new DesiredCapabilities("internet explorer", string.Empty, new Platform(PlatformType.Any)); capabilities.SetCapability("ignoreProtectedModeSettings", true); driver = new RemoteWebDriver(new Uri("http://localhost:4445/wd/hub"),capabilities); } //Search google test [Test] [Parallelizable] public void GoogleSearch() { string homepage = "http://www.google.com"; //Navigate to the site driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); driver.Navigate().GoToUrl(homepage); } [Test] [Parallelizable] public void BingSearch() { //var driver = new FirefoxDriver(); driver.Navigate().GoToUrl("http://www.bing.com"); } [TearDown] public void Teardown() { driver.Quit(); } }}
答案1
小编典典简单一个…但是您不喜欢答案。:-(
NUnit尚不支持在夹具中并行运行测试方法。它仅并行运行单个灯具。
因此,您需要使用OneTimeSetUp选择正确的浏览器来对要在灯具级别并行运行的事物进行建模。
更新-2019年9月27日
我在三年前写了以上答案,当时的确如此!人们,请仔细阅读这些问题和答案的日期,因为除非删除,否则他们将永远留在这里。
发布答案几个月后,NUnit增加了并行运行单个测试用例(方法)的功能。有关受支持功能的最新信息的最佳来源是NUnit文档,而不是SO!大多数工具都是如此。
c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?
这是DefaultSelenium的构造函数:
ISelenium sele = new DefaultSelenium(**serveraddr**,**serverport**,browser,url2test); sele.Start(); sele.open(); ...
似乎我必须在创建ISelenium对象之前安装Selenium Server.
我的情况是,我正在尝试使用C#Selenium构建一个.exe应用程序,它可以在不同的PC上运行,并且不可能在所有PC上安装Selenium Server(你永远不知道哪个是下一个运行应用程序).
有没有人知道如何在不安装服务器的情况下使用ISelenium / DefaultSelenium?
谢谢!
解决方法
1)对于selenium浏览器启动:
DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setbrowserName("safari"); CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"),new URL("http://www.google.com/"),capabilities); WebDriver driver = new RemoteWebDriver(executor,capabilities);
2)对于selenium命令:
// You may use any WebDriver implementation. Firefox is used here as an example WebDriver driver = new FirefoxDriver(); // A "base url",used by selenium to resolve relative URLs String baseUrl = "http://www.google.com"; // Create the Selenium implementation Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl); // Perform actions with selenium selenium.open("http://www.google.com"); selenium.type("name=q","cheese"); selenium.click("name=btnG"); // Get the underlying WebDriver implementation back. This will refer to the // same WebDriver instance as the "driver" variable above. WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver(); //Finally,close the browser. Call stop on the WebDriverBackedSelenium instance //instead of calling driver.quit(). Otherwise,the JVM will continue running after //the browser has been closed. selenium.stop();
描述于此:http://seleniumhq.org/docs/03_webdriver.html
谷歌在C#中有类似的东西.没有其他方法可以实现这一目标.
FireFox中的Selenium OpenQA.Selenium.DriverServiceNotFoundException
我正在尝试开始编写Selenium测试,并且我编写的第一个非常基本的测试因exception失败OpenQA.Selenium.DriverServiceNotFoundException
。
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
namespace WebDriverDemo
{
class Program
{
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://www.google.com";
}
}
}
调试器说我需要下载geckodriver.exe并将其设置在我的PATH变量上,这已经完成,但仍然会出现相同的异常。当我对进行相同的操作时ChromeDriver
,效果很好。
同样,根据MDN,如果我使用的是Selenium
3.0或更高版本,则应默认启用它。我在Windows 10计算机上使用Selenium 3.0.1。
HtmlUnit +生产中的selenium
我目前在生产代码中使用HtmlUnit和Selenium来驱动它(WebDriver)。
我使用这些库通过编程与各种网站进行交互,并取得了一些成功,并且没有遇到内存问题(确保始终清理会话)。
我想知道这些库是否适合生产环境或不建议使用。由于存在大量有关自动化测试的信息,而不是我的使用方式,因此很难通过Google进行查找。
我意识到这是一个相当普遍的问题,但是我正在寻求有关这些库以及可能更好的替代方法的建议。
答案1
小编典典WebDriver和Selenium非常适合生产环境。我在一个多机/多数据中心的分布式网格上使用它们已有2年的时间,并且在性能和稳定性方面绝对没有我们无法解决的问题。
我们首选的驱动程序是Firefox(比HTMLUnit重,并且更难配置),并且我们不得不调整网格以了解可以运行多少个实例。我们的最高稳定性是每个核心1个
我们的selenium / webdriver实例已经运行24/7了2年(使用硒1的情况下为1年,其他迁移selenium 2 /
WebDriver的状态为1年),并且具有适当的监视(您应该监视内存使用情况/
CPU使用情况)和负载测试,我们达到了良好的水平,我们经历了几个月的时间而没有重新启动流程
我们也广泛使用了HTMLUnit,并且对该库同样满意
我的帖子的重点是:是的,这些库已经可以投入生产了。但是,作为所有生产软件,您必须对它们的使用进行基准测试,以找到合适的配置以获得最佳稳定性。我建议您在生产中使用Selenium
Grid,这是使过程并行化的好方法
Nunit 3和Selenium C#的报告工具
我在C#中使用Selenium来创建自动化测试。现在,我必须使用某种报告工具来保存测试用例是否通过,失败…等。
我看过很多工具,例如Allure和Jenkins。但是它们需要一个XML文件。使用Visual 2013运行测试时找不到它。为什么?
如果我缺少某些内容,如何获取这些XML文件的详细信息 ?
我有什么办法可以用最少的努力实现这一目标?
编辑: 如何使用Nunit控制台运行程序运行测试?我在哪里可以找到它?我为nunit下载了.zip文件,但找不到运行程序?
关于使用Nunit在C#并行执行中的Selenium Grid和c# numeric的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、FireFox中的Selenium OpenQA.Selenium.DriverServiceNotFoundException、HtmlUnit +生产中的selenium、Nunit 3和Selenium C#的报告工具的相关信息,请在本站寻找。
本文标签: