0

I have a question about referencing exe files for multiple browser testing in selenium NUnit with C#. I have added the additional code to get my tests to run in each browser but each time I run the tests, I get the error : OpenQA.Selenium.DriverServiceNotFoundException. My question is, is there anyway to add the reference without specifically laying out a path? I don't think that I would be able to add a path to the current code I have, without refactoring what I have. Thanks for your help in advance.

Test Fixture

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
    private IWebDriver driver;
    private string url;

    [TestFixtureSetUp]
    public void FixtureSetUp()
    {
        url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
        this.driver = new TWebDriver();
        driver.Navigate().GoToUrl(url);
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
    }

Using statements

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
DEnumber50
  • 239
  • 2
  • 5
  • 19

2 Answers2

0

I believe you can set the path with something like this;

  System.setProperty("webdriver.ie.driver", "C:\my\path\to\IEDriverServer.exe");
  System.setProperty("webdriver.firefox.driber", "C:\my\path\to\FFDriver.exe");  

Or, the better solution in my opinion is to add the drivers to your project and modify the build so that they end up in your drop folder. The code above is great for your local system but isn't portable. Most automation solutions are intended to 'work out of the box' which requires you to package your dependencies in the bin.

To package the drivers with your build; add a 'Drivers' folder to the project (right click the solution -> add -> new folder) then add the executables under there (right click the folder, add existing item). Now that you can see the driver exe in Solution Explorer right click and select properties, under Copy to Output Directory select 'Copy if Newer'.

evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
  • Great suggestion, how would you implement your suggestion? that is exactly what I want to do – DEnumber50 Apr 21 '15 at 15:59
  • @DEnumber50 putting comment in answer instead. – evanmcdonnal Apr 21 '15 at 16:05
  • I have placed the folder and changed the properties. What do I need to add to my code to recognize these exe files? I am getting the error "System.Reflection.TargetInvocationException". The same error from above is still relevant as well. – DEnumber50 Apr 21 '15 at 16:11
  • @DEnumber50 you may still need to use that setproperty bit but you can provide it with a relative path or just the exe name so it remains portable. I'm honestly not sure though because I don't have a selenium project in front of me to walk through things with. Also, what's up with this `TWebDriver();` ? Maybe if you used; `driver = new InternetExplorerDriver();` instead it would work. – evanmcdonnal Apr 21 '15 at 16:20
  • @DEnumber50 the normal thing is to use the `IWebDriver` interface in your code and determine which version you instantiate in the setup based on your config. Perhaps the statement I referenced above is actually your problem? – evanmcdonnal Apr 21 '15 at 16:21
  • So the TWebDriver(); is a method to include all forms of IE, chrome, and firefox. It's to make my tests run on each of them, your suggestion would definitely work; but I am not trying to run specifically Internet explorer. – DEnumber50 Apr 21 '15 at 16:23
  • http://stackoverflow.com/questions/5028926/run-selenium-tests-in-multiple-browsers-one-after-another-from-c-sharp-nunit This is what I am trying to accomplish – DEnumber50 Apr 21 '15 at 16:25
  • @DEnumber50 I'm not sure how much I can help you trouble shoot as I haven't done that. Last I implemented this was on an older version of NUnit and I had to do that logic myself. Anyway, check out the implementation of `SetUp` in the example, you're not really following it... Why didn't you just copy it verbatim then insert your test code? – evanmcdonnal Apr 21 '15 at 16:31
  • If I do copy it verbatim, it will run on chrome and IE but not on firefox. I cannot find the firefox driver because its in the .jar file. Do you know how to get that reference? so I can place it into my driver file. – DEnumber50 Apr 21 '15 at 19:12
0

After making some changed to the code I am able to run all tests on the big 3 browsers. I had to add the Chrome.exe and the IE.exe to the bin\Debug folder (The one with the WebDriver.dll's) Here are my changes to my code.

Test Fixtures

[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
[TestFixture(typeof(ChromeDriver))]
public class CustomerLogin<TWebDriver> where TWebDriver : IWebDriver, new()
{
    private IWebDriver driver;
    private string url;
    [SetUp]
    public void SetUp()
    {
        this.driver = new TWebDriver();
        url = System.Configuration.ConfigurationManager.AppSettings["homeUrl"];
        driver.Navigate().GoToUrl(url);
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
        //Finding the customer login link and clicking it
        driver.FindElement(By.Id("Homepage_r2_c14")).Click();
    }
    [TearDown]
    public void TearDown()
    {
        driver.Quit();
    }
}
DEnumber50
  • 239
  • 2
  • 5
  • 19