4

I have some web ui tests in C# which are executed through selenium in browserstack. Currently these are just simple unit ms tests and they are executed againts different browsers. I want to port the test to specflow, but I don't really know how to do the multiple browser testing bit.

At the moment, to execute these tests in multiple browsers I am using a DataSource attribute, which basically takes different inputs for the same tests from an XML file

[TestMethod]
[Ignore]
[DeploymentItem("JLL.Specs\\Browsers.xml")]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\Browsers.xml", "Row", DataAccessMethod.Sequential)]
public void LoadHomePageAndFindSearchBox()
{    
   ...
}

The problem is that Specflow doesn't support the DataSource attribute. Any idea?

This is the XML file:

<?xml version="1.0" encoding="utf-8" ?>
<Rows>
  <Row>
    <browser>Firefox</browser>
    <browser_version>31.0</browser_version>
    <os>Windows</os>
    <os_version>7</os_version>
    <resolution>1280x1024</resolution>
    <browserName></browserName>
    <platform></platform>
    <device></device>
  </Row>
  <Row>
    <browser>Chrome</browser>
    <browser_version>36.0</browser_version>
    <os>Windows</os>
    <os_version>XP</os_version>
    <resolution>1024x768</resolution>
    <browserName></browserName>
    <platform></platform>
    <device></device>
  </Row>

...
Ben Smith
  • 19,589
  • 6
  • 65
  • 93
  • Best I could find is this: http://www.specflow.org/plus/excel/getting-started/ I'm not sure if that's the answer you're looking for though. – Richard Jan 05 '15 at 19:16
  • In a single test run, do you want to run all the Scenarios against all browsers? – Greg Burghardt Jan 07 '15 at 13:55
  • At the root of it, SpecFlow just generates unit tests that happen to use the SpecFlow API. I wonder if you could create a custom test generator that adds the appropriate attributes above the test methods. [This StackOverflow question](http://stackoverflow.com/questions/11009181/how-to-teach-specflow-to-add-additional-nunit-attributes-to-my-test-class) talks about creating custom attributes on NUnit tests in SpecFlow. I'm sure the same pattern applies to MS Tests generated by SpecFlow as well. – Greg Burghardt Jan 07 '15 at 14:01
  • Did my answer help? What did you end up doing? – Ben Smith Oct 28 '15 at 11:49
  • I am not working with this project any more and I don't access to it, so I can't really check if this works, sorry. – Asier Barrenetxea Oct 29 '15 at 19:18

2 Answers2

0

You could use a web driver abstraction framework to write driver agnostic test code. To do this I've used Coypu. Using this library you can easily switch between different web drivers (e.g. Selenium, Phantom JS, WaitN) without needing to write different driver code.

In a web driver factory class you could then use code like (see here for more information):

sessionConfiguration.Driver = Type.GetType("Coypu.Drivers.Selenium.SeleniumWebDriver, Coypu");
sessionConfiguration.Browser = Drivers.Browser.Parse("firefox");

to get an instance of Selenium for FireFox or you could replace "firefox" with "chrome" to get an instance of Chrome.

I've used this approach to run a suite of tests for different browsers and it worked well. However this has meant executing a suite of tests for one browser, and then upon completion running them for another.

Ben Smith
  • 19,589
  • 6
  • 65
  • 93
0

Best is to use Baseclass.Contrib.SpecFlow.Selenium.NUnit dll.

see the Example:

@Browser:IE

@Browser:Chrome

@Browser:Firefox

Scenario Outline: Add Two Numbers

You can use @Browser:.......... in your feature file. This attribute will list 3 tests in your test explorer for each browser and you can run whichever you wanted to use.

For detailed information , go here.

Kristijan Iliev
  • 4,901
  • 10
  • 28
  • 47
sunny bhatia
  • 41
  • 1
  • 9