diff --git a/Baseclass.Contrib.SpecFlow.Selenium.NUnit/Baseclass.Contrib.SpecFlow.Selenium.NUnit/SeleniumNUnitTestGeneratorProvider.cs b/Baseclass.Contrib.SpecFlow.Selenium.NUnit/Baseclass.Contrib.SpecFlow.Selenium.NUnit/SeleniumNUnitTestGeneratorProvider.cs
index a197d74..c5b6002 100644
--- a/Baseclass.Contrib.SpecFlow.Selenium.NUnit/Baseclass.Contrib.SpecFlow.Selenium.NUnit/SeleniumNUnitTestGeneratorProvider.cs
+++ b/Baseclass.Contrib.SpecFlow.Selenium.NUnit/Baseclass.Contrib.SpecFlow.Selenium.NUnit/SeleniumNUnitTestGeneratorProvider.cs
@@ -35,45 +35,117 @@ public SeleniumNUnitTestGeneratorProvider(CodeDomHelper codeDomHelper)
this.codeDomHelper = codeDomHelper;
}
+ ///
+ /// Initialization Methods to Generate. MethodName => List of Argument Names
+ ///
+ private Dictionary> initializeMethodsToGenerate = new Dictionary>();
+ ///
+ /// List of unique field Names to Generate
+ ///
+ private HashSet fieldsToGenerate = new HashSet();
+ bool hasBrowser = false;
+
public void SetTestMethodCategories(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, System.CodeDom.CodeMemberMethod testMethod, IEnumerable scenarioCategories)
{
- this.codeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories.Where(cat => !cat.StartsWith("Browser:")));
+ this.codeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories.Where(cat => !cat.StartsWith("Browser:") && !cat.Contains(":")));
+
+ Dictionary> categoryTags = new Dictionary>();
- bool hasBrowser = false;
+ bool hasTags = false;
+
+ foreach(var tag in scenarioCategories.Where(cat => cat.Contains(":")).Select(cat => cat.Split(':')))
+ {
+ if (tag.Length != 2)
+ continue;
+ hasTags = true;
+ if (tag[0].Equals("Browser",StringComparison.OrdinalIgnoreCase))
+ {
+ hasBrowser = true;
+ }
+ testMethod.UserData.Add(tag[0] + ":" + tag[1], tag[1]);
+ List tagValues = null;
+ if (!categoryTags.TryGetValue(tag[0],out tagValues))
+ {
+ tagValues = new List();
+ categoryTags[tag[0]] = tagValues;
+ }
+ tagValues.Add(tag[1]);
+ }
- foreach(var browser in scenarioCategories.Where(cat => cat.StartsWith("Browser:")).Select(cat => cat.Replace("Browser:", "")))
+ if (hasTags)
{
- testMethod.UserData.Add("Browser:" + browser, browser);
+ //TestName and TestCategory Building
+ //List of list of tags different values
+ List> values = new List>();
+ foreach (var kvp in categoryTags)
+ {
+ values.Add(kvp.Value);
+ }
+ List> combinations = new List>();
+ //Generate an exhaustive list of values combinations
+ GeneratePermutations(values, combinations, 0, new List());
- var withBrowserArgs = new[] { new CodeAttributeArgument(new CodePrimitiveExpression(browser)) }
+ foreach (var combination in combinations)
+ {
+ //Each combination is a different TestCase
+ var withTagArgs = combination.Select(s => new CodeAttributeArgument(new CodePrimitiveExpression(s))).ToList()
.Concat(new[] {
- new CodeAttributeArgument("Category", new CodePrimitiveExpression(browser)),
- new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} on {1}", testMethod.Name, browser)))
+ new CodeAttributeArgument("Category", new CodePrimitiveExpression(String.Join(",",combination))),
+ new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} with {1}", testMethod.Name, String.Join(",",combination))))
})
.ToArray();
- this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withBrowserArgs);
+ this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withTagArgs);
+ }
+
- hasBrowser = true;
- }
+ List parameters = new List();
+ int i = 0;
- if (hasBrowser)
- {
- if (!scenarioSetupMethodsAdded)
+ List orderedTags = new List();
+ foreach (var kvp in categoryTags)
{
- generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.driver != null)"));
- generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Driver\", this.driver);"));
- generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.container != null)"));
- generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Container\", this.container);"));
- scenarioSetupMethodsAdded = true;
+ //Add the category name to category list
+ orderedTags.Add(kvp.Key);
+ //Mark the field to be generated
+ fieldsToGenerate.Add(kvp.Key);
+ //Add a parameter to the testMethod
+ testMethod.Parameters.Insert(i, new System.CodeDom.CodeParameterDeclarationExpression("System.String", kvp.Key.ToLowerInvariant()));
+ i = i + 1;
}
-
- testMethod.Statements.Insert(0, new CodeSnippetStatement(" InitializeSelenium(browser);"));
- testMethod.Parameters.Insert(0, new System.CodeDom.CodeParameterDeclarationExpression("System.string" , "browser"));
+
+ string methodName = "InitializeSelenium"+String.Join("",orderedTags);
+ string initializeSeleniumArgs = String.Join(",",orderedTags).ToLowerInvariant();
+ //Create the call to the initialization Method
+ testMethod.Statements.Insert(0, new CodeSnippetStatement(methodName+"(" + initializeSeleniumArgs + ");"));
+ List nothing = null;
+ if (!initializeMethodsToGenerate.TryGetValue(methodName, out nothing))
+ {
+ //Mark the initialization method to be generated
+ initializeMethodsToGenerate[methodName] = orderedTags.Select(s => s.ToLowerInvariant()).ToList();
+ }
+ }
+ }
+
+ private void GeneratePermutations(List> Lists, List> result, int depth, List current)
+ {
+ //TODO rajouter les CodePrimitiveExpression
+ if (depth == Lists.Count)
+ {
+ result.Add(current);
+ return;
+ }
+
+ for (int i = 0; i < Lists[depth].Count; i++)
+ {
+ var newList = new List(current);
+ newList.Add(Lists[depth][i]);
+ GeneratePermutations(Lists, result, depth + 1, newList);
}
}
- public void SetRow(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, System.CodeDom.CodeMemberMethod testMethod, IEnumerable arguments, IEnumerable tags, bool isIgnored)
+ public void SetRow(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, System.CodeDom.CodeMemberMethod testMethod
+ , IEnumerable arguments, IEnumerable tags, bool isIgnored)
{
var args = arguments.Select(
arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();
@@ -88,32 +160,59 @@ public void SetRow(TechTalk.SpecFlow.Generator.TestClassGenerationContext genera
if (isIgnored)
args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true)));
+
+ var categories = testMethod.UserData.Keys.OfType()
+ .Where(key => key.Contains(":"));
+
+
var browsers = testMethod.UserData.Keys.OfType()
.Where(key => key.StartsWith("Browser:"))
.Select(key => (string) testMethod.UserData[key]).ToArray();
- if (browsers.Any())
+ if (categories.Any())
{
- foreach (var codeAttributeDeclaration in testMethod.CustomAttributes.Cast().Where(attr => attr.Name == ROW_ATTR && attr.Arguments.Count == 3).ToList())
+ //List of list of tags different values
+ Dictionary> values = new Dictionary>();
+ foreach (var userDataKey in categories)
+ {
+ string catName = userDataKey.Substring(0, userDataKey.IndexOf(':'));
+ List val = null;
+ if (!values.TryGetValue(catName, out val))
+ {
+ val = new List();
+ values[catName] = val;
+ }
+ val.Add((string)testMethod.UserData[userDataKey]);
+ }
+
+ List> combinations = new List>();
+ //Generate an exhaustive list of values combinations
+ GeneratePermutations(values.Values.ToList(), combinations, 0, new List());
+
+ //Remove TestCase attributes
+ foreach (var codeAttributeDeclaration in testMethod.CustomAttributes.Cast()
+ .Where(attr => attr.Name == ROW_ATTR && attr.Arguments.Count == 2+values.Keys.Count).ToList())
{
testMethod.CustomAttributes.Remove(codeAttributeDeclaration);
}
- foreach (var browser in browsers)
+ foreach (var combination in combinations)
{
var argsString = string.Concat(args.Take(args.Count - 1).Select(arg => string.Format("\"{0}\" ,", ((CodePrimitiveExpression)arg.Value).Value)));
argsString = argsString.TrimEnd(' ', ',');
- var withBrowserArgs = new[] { new CodeAttributeArgument(new CodePrimitiveExpression(browser)) }
+ //Each combination is a different TestCase
+ var withTagArgs = combination.Select(s => new CodeAttributeArgument(new CodePrimitiveExpression(s))).ToList()
.Concat(args)
- .Concat(new [] {
- new CodeAttributeArgument("Category", new CodePrimitiveExpression(browser)),
- new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} on {1} with: {2}", testMethod.Name, browser, argsString)))
+ .Concat(new[] {
+ new CodeAttributeArgument("Category", new CodePrimitiveExpression(String.Join(",",combination))),
+ new CodeAttributeArgument("TestName", new CodePrimitiveExpression(string.Format("{0} with {1} and {2}", testMethod.Name, String.Join(",",combination),argsString)))
})
.ToArray();
- this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withBrowserArgs);
+ this.codeDomHelper.AddAttribute(testMethod, ROW_ATTR, withTagArgs);
}
+
}
else
{
@@ -132,17 +231,29 @@ public void SetTestClass(TechTalk.SpecFlow.Generator.TestClassGenerationContext
generationContext.TestClass.Members.Add(new CodeMemberField("OpenQA.Selenium.IWebDriver", "driver"));
generationContext.TestClass.Members.Add(new CodeMemberField("IContainer", "container"));
- CreateInitializeSeleniumMethod(generationContext);
}
- private static void CreateInitializeSeleniumMethod(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext)
+ private void CreateInitializeSeleniumMethod(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext)
{
- var initializeSelenium = new CodeMemberMethod();
- initializeSelenium.Name = "InitializeSelenium";
- initializeSelenium.Parameters.Add(new CodeParameterDeclarationExpression("System.String", "browser"));
- initializeSelenium.Statements.Add(new CodeSnippetStatement(" this.driver = this.container.ResolveNamed(browser);"));
-
- generationContext.TestClass.Members.Add(initializeSelenium);
+ foreach (var kvp in initializeMethodsToGenerate)
+ {
+ var initializeSelenium = new CodeMemberMethod();
+ initializeSelenium.Name = kvp.Key;
+ foreach (var paramName in kvp.Value)
+ {
+ initializeSelenium.Parameters.Add(new CodeParameterDeclarationExpression("System.String", paramName));
+ if (paramName.Equals("browser", StringComparison.OrdinalIgnoreCase))
+ {
+ initializeSelenium.Statements.Add(new CodeSnippetStatement(" this.driver = this.container.ResolveNamed(" + paramName + ");"));
+ }
+ else
+ {
+ initializeSelenium.Statements.Add(new CodeSnippetStatement(" this._"+paramName+" = "+paramName+";"));
+ }
+ }
+
+ generationContext.TestClass.Members.Add(initializeSelenium);
+ }
}
public void SetTestClassCategories(TechTalk.SpecFlow.Generator.TestClassGenerationContext generationContext, IEnumerable featureCategories)
@@ -208,6 +319,36 @@ public void FinalizeTestClass(TechTalk.SpecFlow.Generator.TestClassGenerationCon
generationContext.TestCleanupMethod.Statements.Add(new CodeSnippetStatement(" this.driver = null;"));
generationContext.TestCleanupMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Remove(\"Driver\");"));
generationContext.TestCleanupMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Remove(\"Container\");"));
+
+ foreach (var field in fieldsToGenerate)
+ {
+ if (!field.Equals("Browser", StringComparison.OrdinalIgnoreCase))
+ {
+ generationContext.TestClass.Members.Add(new CodeMemberField("System.String", "_" + field.ToLowerInvariant()));
+ generationContext.TestCleanupMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Remove(\"" + field + "\");"));
+ }
+ }
+ CreateInitializeSeleniumMethod(generationContext);
+
+ if (!scenarioSetupMethodsAdded)
+ {
+ if (hasBrowser)
+ {
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.driver != null)"));
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Driver\", this.driver);"));
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this.container != null)"));
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"Container\", this.container);"));
+ }
+ foreach (var field in fieldsToGenerate)
+ {
+ if (!field.Equals("Browser", StringComparison.OrdinalIgnoreCase))
+ {
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" if(this._" + field.ToLowerInvariant() + " != null)"));
+ generationContext.ScenarioInitializeMethod.Statements.Add(new CodeSnippetStatement(" ScenarioContext.Current.Add(\"" + field + "\", this._" + field.ToLowerInvariant() + ");"));
+ }
+ }
+ scenarioSetupMethodsAdded = true;
+ }
}
}
}
diff --git a/README.md b/README.md
index 55b5e3c..e497d82 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ Example using SauceLabs as remote web driver: http://www.baseclass.ch/blog/Lists
- Adds the browser name as TestCategory
- Just run the tests with the categories for the browser you actually have on the environment. Example: Don't run Android browser test as I don't have an android device attached to my machine.
+- Annotate scenarios with whatever you want (@Key:Value)
+ - You may have a multilingual site, just annotate your tests with the language and get it back in the ScenarioContext! Your Language is also added as a category so you can run all test for one site.
Get it from Nuget.org:
diff --git a/TestApplication.UiTests/CalculatorFeature.feature b/TestApplication.UiTests/CalculatorFeature.feature
index d0c60b4..1b92c61 100644
--- a/TestApplication.UiTests/CalculatorFeature.feature
+++ b/TestApplication.UiTests/CalculatorFeature.feature
@@ -9,11 +9,14 @@
Scenario: Basepage is Calculator
Given I navigated to /
Then browser title is Calculator
-
-@Browser:IE
+
+@Browser:Firefox
@Browser:Chrome
+@Language:FR
+@Language:COM
+@Language:DE
Scenario Outline: Add Two Numbers
- Given I navigated to /
+ Given I went to /
And I have entered into summandOne calculator
And I have entered into summandTwo calculator
When I press add
diff --git a/TestApplication.UiTests/CalculatorFeature.feature.cs b/TestApplication.UiTests/CalculatorFeature.feature.cs
index 82dd34c..81963e1 100644
--- a/TestApplication.UiTests/CalculatorFeature.feature.cs
+++ b/TestApplication.UiTests/CalculatorFeature.feature.cs
@@ -3,7 +3,7 @@
// This code was generated by SpecFlow (http://www.specflow.org/).
// SpecFlow Version:1.9.0.77
// SpecFlow Generator Version:1.9.0.0
-// Runtime Version:4.0.30319.18033
+// Runtime Version:4.0.30319.18408
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -31,6 +31,8 @@ public partial class CalculatorFeatureFeature
private static TechTalk.SpecFlow.ITestRunner testRunner;
+ private string _language;
+
#line 1 "CalculatorFeature.feature"
#line hidden
@@ -62,6 +64,11 @@ public virtual void TestInitialize()
public virtual void ScenarioTearDown()
{
testRunner.OnScenarioEnd();
+ try { System.Threading.Thread.Sleep(50); this.driver.Quit(); } catch (System.Exception) {}
+ this.driver = null;
+ ScenarioContext.Current.Remove("Driver");
+ ScenarioContext.Current.Remove("Container");
+ ScenarioContext.Current.Remove("Language");
}
public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
@@ -71,30 +78,23 @@ public virtual void ScenarioSetup(TechTalk.SpecFlow.ScenarioInfo scenarioInfo)
ScenarioContext.Current.Add("Driver", this.driver);
if(this.container != null)
ScenarioContext.Current.Add("Container", this.container);
+ if(this._language != null)
+ ScenarioContext.Current.Add("Language", this._language);
}
public virtual void ScenarioCleanup()
{
- try { System.Threading.Thread.Sleep(50); this.driver.Quit(); } catch (System.Exception) {}
- this.driver = null;
- ScenarioContext.Current.Remove("Driver");
- ScenarioContext.Current.Remove("Container");
testRunner.CollectScenarioErrors();
}
- private void InitializeSelenium(string browser)
- {
- this.driver = this.container.ResolveNamed(browser);
- }
-
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Basepage is Calculator")]
- [NUnit.Framework.TestCaseAttribute("Chrome", Category="Chrome", TestName="BasepageIsCalculator on Chrome")]
- [NUnit.Framework.TestCaseAttribute("IE", Category="IE", TestName="BasepageIsCalculator on IE")]
- [NUnit.Framework.TestCaseAttribute("Firefox", Category="Firefox", TestName="BasepageIsCalculator on Firefox")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", Category="Chrome", TestName="BasepageIsCalculator with Chrome")]
+ [NUnit.Framework.TestCaseAttribute("IE", Category="IE", TestName="BasepageIsCalculator with IE")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", Category="Firefox", TestName="BasepageIsCalculator with Firefox")]
public virtual void BasepageIsCalculator(string browser)
{
- InitializeSelenium(browser);
+InitializeSeleniumBrowser(browser);
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Basepage is Calculator", new string[] {
"Browser:Chrome",
"Browser:IE",
@@ -111,36 +111,58 @@ public virtual void BasepageIsCalculator(string browser)
[NUnit.Framework.TestAttribute()]
[NUnit.Framework.DescriptionAttribute("Add Two Numbers")]
- [NUnit.Framework.TestCaseAttribute("IE", "50", "70", "120", null, Category="IE", TestName="AddTwoNumbers on IE with: \"50\" ,\"70\" ,\"120\"")]
- [NUnit.Framework.TestCaseAttribute("Chrome", "50", "70", "120", null, Category="Chrome", TestName="AddTwoNumbers on Chrome with: \"50\" ,\"70\" ,\"120\"")]
- [NUnit.Framework.TestCaseAttribute("IE", "1", "10", "11", null, Category="IE", TestName="AddTwoNumbers on IE with: \"1\" ,\"10\" ,\"11\"")]
- [NUnit.Framework.TestCaseAttribute("Chrome", "1", "10", "11", null, Category="Chrome", TestName="AddTwoNumbers on Chrome with: \"1\" ,\"10\" ,\"11\"")]
- public virtual void AddTwoNumbers(string browser, string summandOne, string summandTwo, string result, string[] exampleTags)
+ [NUnit.Framework.TestCaseAttribute("Firefox", "FR", "50", "70", "120", null, Category="Firefox,FR", TestName="AddTwoNumbers with Firefox,FR and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", "COM", "50", "70", "120", null, Category="Firefox,COM", TestName="AddTwoNumbers with Firefox,COM and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", "DE", "50", "70", "120", null, Category="Firefox,DE", TestName="AddTwoNumbers with Firefox,DE and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "FR", "50", "70", "120", null, Category="Chrome,FR", TestName="AddTwoNumbers with Chrome,FR and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "COM", "50", "70", "120", null, Category="Chrome,COM", TestName="AddTwoNumbers with Chrome,COM and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "DE", "50", "70", "120", null, Category="Chrome,DE", TestName="AddTwoNumbers with Chrome,DE and \"50\" ,\"70\" ,\"120\"")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", "FR", "1", "10", "11", null, Category="Firefox,FR", TestName="AddTwoNumbers with Firefox,FR and \"1\" ,\"10\" ,\"11\"")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", "COM", "1", "10", "11", null, Category="Firefox,COM", TestName="AddTwoNumbers with Firefox,COM and \"1\" ,\"10\" ,\"11\"")]
+ [NUnit.Framework.TestCaseAttribute("Firefox", "DE", "1", "10", "11", null, Category="Firefox,DE", TestName="AddTwoNumbers with Firefox,DE and \"1\" ,\"10\" ,\"11\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "FR", "1", "10", "11", null, Category="Chrome,FR", TestName="AddTwoNumbers with Chrome,FR and \"1\" ,\"10\" ,\"11\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "COM", "1", "10", "11", null, Category="Chrome,COM", TestName="AddTwoNumbers with Chrome,COM and \"1\" ,\"10\" ,\"11\"")]
+ [NUnit.Framework.TestCaseAttribute("Chrome", "DE", "1", "10", "11", null, Category="Chrome,DE", TestName="AddTwoNumbers with Chrome,DE and \"1\" ,\"10\" ,\"11\"")]
+ public virtual void AddTwoNumbers(string browser, string language, string summandOne, string summandTwo, string result, string[] exampleTags)
{
- InitializeSelenium(browser);
+InitializeSeleniumBrowserLanguage(browser,language);
string[] @__tags = new string[] {
- "Browser:IE",
- "Browser:Chrome"};
+ "Browser:Firefox",
+ "Browser:Chrome",
+ "Language:FR",
+ "Language:COM",
+ "Language:DE"};
if ((exampleTags != null))
{
@__tags = System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Concat(@__tags, exampleTags));
}
TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Add Two Numbers", @__tags);
-#line 15
+#line 18
this.ScenarioSetup(scenarioInfo);
-#line 16
- testRunner.Given("I navigated to /", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
-#line 17
+#line 19
+ testRunner.Given("I went to /", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given ");
+#line 20
testRunner.And(string.Format("I have entered {0} into summandOne calculator", summandOne), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
-#line 18
+#line 21
testRunner.And(string.Format("I have entered {0} into summandTwo calculator", summandTwo), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And ");
-#line 19
+#line 22
testRunner.When("I press add", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When ");
-#line 20
+#line 23
testRunner.Then(string.Format("the result should be {0} on the screen", result), ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then ");
#line hidden
this.ScenarioCleanup();
}
+
+ private void InitializeSeleniumBrowser(string browser)
+ {
+ this.driver = this.container.ResolveNamed(browser);
+ }
+
+ private void InitializeSeleniumBrowserLanguage(string browser, string language)
+ {
+ this.driver = this.container.ResolveNamed(browser);
+ this._language = language;
+ }
}
}
#pragma warning restore
diff --git a/TestApplication.UiTests/CalculatorFeatureSteps.cs b/TestApplication.UiTests/CalculatorFeatureSteps.cs
index 135196b..617b889 100644
--- a/TestApplication.UiTests/CalculatorFeatureSteps.cs
+++ b/TestApplication.UiTests/CalculatorFeatureSteps.cs
@@ -5,6 +5,7 @@
using TechTalk.SpecFlow;
using Baseclass.Contrib.SpecFlow.Selenium.NUnit;
using Baseclass.Contrib.SpecFlow.Selenium.NUnit.Bindings;
+using System.Configuration;
namespace TestApplication.UiTests
{
@@ -53,5 +54,18 @@ public void ThenBrowserTitleIs(string title)
Assert.AreEqual(title, result);
}
+ [Given(@"I went to (.*)")]
+ public void GivenIWentTo(string url)
+ {
+ string absoluteUrl = ConfigurationManager.AppSettings["seleniumBaseUrl"];
+ string language = null;
+ if (ScenarioContext.Current.TryGetValue("Language", out language))
+ {
+ url += "?Language=" + language;
+ }
+ Browser.Current.Navigate().GoToUrl(url);
+ }
+
+
}
}
diff --git a/TestApplication/Controllers/CalculatorController.cs b/TestApplication/Controllers/CalculatorController.cs
index cbd1487..5699ec5 100644
--- a/TestApplication/Controllers/CalculatorController.cs
+++ b/TestApplication/Controllers/CalculatorController.cs
@@ -13,6 +13,17 @@ public class CalculatorController : Controller
public ActionResult Index()
{
+ if (HttpContext.Request.QueryString.AllKeys.Contains("Language"))
+ {
+ string language = HttpContext.Request.QueryString["Language"];
+ ViewBag.Language = language;
+ ViewBag.Title = (language.Equals("FR", StringComparison.OrdinalIgnoreCase) ? "Calculatrice" : "Calculator");
+ }
+ else
+ {
+ ViewBag.Language = "Unknown";
+ ViewBag.Title = "Calculator";
+ }
return View();
}
@@ -22,5 +33,7 @@ public ActionResult Index(int summandOne, int summandTwo)
return View(summandOne + summandTwo);
}
+
+
}
}
diff --git a/TestApplication/Views/Calculator/Index.cshtml b/TestApplication/Views/Calculator/Index.cshtml
index 742c735..c70b0e6 100644
--- a/TestApplication/Views/Calculator/Index.cshtml
+++ b/TestApplication/Views/Calculator/Index.cshtml
@@ -1,9 +1,8 @@
@{
- ViewBag.Title = "Calculator";
Layout = "~/Views/Shared/_layout.cshtml";
}
-Calculator
+@ViewBag.Title
@using (Html.BeginForm())
{