1

I would like to ask you if is it possible to set up Firefox Driver with profile - using Specflow / Autofac. Here is declaration of my drivers from App.config file:

<autofac>
  <components>
    <component name="IE" type="OpenQA.Selenium.IE.InternetExplorerDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
    </component>
    <component name="Chrome" type="OpenQA.Selenium.Chrome.ChromeDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
    </component>
    <component name="Firefox" type="OpenQA.Selenium.Firefox.FirefoxDriver, WebDriver" service="OpenQA.Selenium.IWebDriver, WebDriver" instance-scope="per-dependency">
    </component>

    <!-- Example of using an injected RemoteDriver:
    <component
          name="IE"
          type="Baseclass.Contrib.SpecFlow.Selenium.NUnit.RemoteWebDriver, Baseclass.Contrib.SpecFlow.Selenium.NUnit.SpecFlowPlugin"
          service="OpenQA.Selenium.IWebDriver, WebDriver"
          instance-scope="per-dependency">
        <parameters>
          <parameter name="url" value="http://127.0.0.1:4444/wd/hub" />
          <parameter name="browser" value="InternetExplorer">
        </parameter>
      </parameters>
  </component>-->

 </components>
</autofac>

In commented part of code, there is an example of setting some parameters for driver, but I couldn't find the way, to set a profile. Do you know how to do it? Or maybe there is another way to set up profile directly from Specflow?

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
Matt
  • 11
  • 2
  • I don't believe this question has anything to do with specflow. you might be using specflow, but the configuration of the driver instance is actually to do with selenium, and the answer will be the same when using specflow or any other testing solution. Once you know how to configure selenium correctly (either through code or through config), if you have questions about how to correctly call that code using Specflow then you should ask another question about that. – Sam Holder Jun 30 '15 at 07:45
  • The main goal for me is to run firefox driver always with specific profile. I tried a lot of options but none of them works for me. Could you please explain me how to do it using Specflow? – Matt Jun 30 '15 at 08:03
  • I don't know how to run firefox with a specific profile using selenium, but how ever you do it, it will be the same in specflow. – Sam Holder Jun 30 '15 at 08:26

1 Answers1

0

After a quick search on the web I found this page which gives some information about starting with a profile:

ProfilesIni profile = new ProfilesIni();     
FirefoxProfile myprofile = profile.getProfile("profileToolsQA");     
WebDriver driver = new FirefoxDriver(myprofile)

so wherever you are creating your webdriver instance in Specflow now, you can use this to create it with a profile instead. I assume that the profile has to exist first.

If the profile doesn't exist then maybe you can use the information in this answer to help you.

Community
  • 1
  • 1
Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • The problem is that I have no idea where put it, to have profile for each firefox driver instance. There is some code under specflow features like this: public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo) { testRunner.OnScenarioStart(scenarioInfo); if(this.driver != null) ScenarioContext.Current.Add("Driver", this.driver); if(this.container != null) ScenarioContext.Current.Add("Container", this.container); } But there is no sense to edit each .cs for feature file. – Matt Jun 30 '15 at 09:10
  • I also tried to put (code with setting the profile) into the BeforeScenario hook and assing new driver to ScenarioContext with ["Driver"] key, but scenario context couldn't exists at this level. So I came up with idea that it should have been something with autofac inside app.config – Matt Jun 30 '15 at 09:15
  • I think you need to understand a bit more about how specflow works. Please see [this answer](http://stackoverflow.com/questions/26392380/nunit-specflow-how-to-share-a-class-instance-for-all-tests/26402692#26402692) for how you can setup specflow to inject a context which contains your web driver. This example shows how to share the same instance between features but if you create a new webdriver instance each time in the BeforeScenario method, each pointing at a different profile then it should work ok – Sam Holder Jun 30 '15 at 09:50
  • My advice would be to leave AutoFac out of this completely and do 2 things. 1. Get it working without AutoFac using just Specflow and no profiles. 2. Then add support for profiles. And please don't edit the feature.cs files. These are generated by Specflow and any changes to the feature files qwill cause them to be regenerated and you will lose any changes you made. – Sam Holder Jun 30 '15 at 09:52