运行在多个浏览器的Selenium测试陆续从C#的NUnit [英] Run Selenium tests in multiple browsers one after another from C# NUnit
问题描述
我要找推荐/最好的方法,使Selenium测试在几个浏览器中执行此起彼伏。该网站我测试并不大,所以我并不需要一个并行解决方案呢。
I'm looking for the recommended/nicest way to make Selenium tests execute in several browsers one after another. The website I'm testing isn't big, so I don't need a parallel solution yet.
我和平时的测试设置方法 [设置]
, [TearDown中]
和 [测试]
。安装程序之一,当然,实例化与任何浏览器我想测试一个新的 ISelenium
对象。
I have the usual test set-up methods with [SetUp]
, [TearDown]
, and [Test]
. The SetUp one, of course, instantiates a new ISelenium
object with whatever browser I want to test with.
所以,我想要做的是编程的说:这个测试将在Chrome,IE和Firefox顺序运行。我该怎么做呢?
So what I want to do is programmatically say: this test will be run on Chrome, IE, and Firefox in sequence. How do I do that?
编辑:
这可能会有点帮助。我们使用CruiseControl.NET启动成功构建后NUnit的测试。有没有什么办法来传递参数给NUnit的可执行文件,然后使用该参数在测试?这样,我们可以有NUnit的不同浏览器的参数运行了好几次。
This might help a bit. We're using CruiseControl.NET to start the NUnit tests after a successful build. Is there any way to pass a parameter to the NUnit executable, and then use that parameter in the test? This way we could have NUnit run several times with different browser parameters.
推荐答案
NUnit的2.5+现在支持通用测试夹具这使得测试在多个浏览器非常简单。
<一href=\"http://www.nunit.org/index.php?p=testFixture&r=2.5\">http://www.nunit.org/index.php?p=testFixture&r=2.5
NUnit 2.5+ now supports Generic Test Fixtures which make testing in multiple browsers very straightforward. http://www.nunit.org/index.php?p=testFixture&r=2.5
运行下面的例子将执行GoogleTest两次,一次在Firefox和曾经在IE浏览器。
Running the following example will execute the GoogleTest twice, once in Firefox and once in IE.
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using System.Threading;
namespace SeleniumTests
{
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
private IWebDriver driver;
[SetUp]
public void CreateDriver () {
this.driver = new TWebDriver();
}
[Test]
public void GoogleTest() {
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Bread" + Keys.Enter);
Thread.Sleep(2000);
Assert.AreEqual("bread - Google Search", driver.Title);
driver.Quit();
}
}
}
这篇关于运行在多个浏览器的Selenium测试陆续从C#的NUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!