1

I am trying to run a test on multiple browsers using WebDriver, Nunit and C#. It's working, but I am getting that annoying security warning in Chrome. In an effort to fix it, I need to re-create the driver using ".AddArguments("--test-type"); ". But I only want to do this if this iterations browser = Chrome. Here is my code. It works, but it launches an un-needed browser window first. Anybody have any idea's around this?

 namespace SeleniumTests { [TestFixture(typeof(FirefoxDriver))] [TestFixture(typeof(InternetExplorerDriver))] [TestFixture(typeof(ChromeDriver))] public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new() { private IWebDriver driver; [SetUp] public void CreateDriver() { this.driver = new TWebDriver(); //Creates a window that needs to be closed and re-constructed if(driver is ChromeDriver) { driver.Quit(); //This kills the un-needed driver window created above var chromeOptions = new ChromeOptions(); chromeOptions.AddArguments("--test-type"); driver = new ChromeDriver(chromeOptions); } } 
1
  • You've instantly hit a code structure problem. Your being generic and specific at the same time. Pick one! Commented Jun 3, 2015 at 21:53

2 Answers 2

3

Why do not you simpley create the chromedriver in the base class well? you can also use the chromoptions there to pass necessary arguments. Then use

[TestFixture(typeof(FirefoxDriver))] [TestFixture(typeof(InternetExplorerDriver))] [TestFixture(typeof(ChromeDriver))] 

That will save you unncessary code duplication and confusion as well.

I have a full implementation of driver instances here

Sign up to request clarification or add additional context in comments.

Comments

0

I think you are invoking chrome twice in your code. Here is a sample code which might help you.

using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.IE; using OpenQA.Selenium.Chrome; namespace MultipleBrowserTesting { [TestFixture(typeof(FirefoxDriver))] [TestFixture(typeof(ChromeDriver))] [TestFixture(typeof(InternetExplorerDriver))] public class BlogTest<TWebDriver> where TWebDriver : IWebDriver, new() { private IWebDriver _driver; [Test] public void Can_Visit_Google() { _driver = new TWebDriver(); // Navigate _driver.Manage().Window.Maximize(); _driver.Navigate().GoToUrl("http://www.google.com/"); } [TestFixtureTearDown] public void FixtureTearDown() { if (_driver != null) _driver.Close(); } } } 

Here is a link to the Github project. GitHub Link to solution

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.