0

Background: Automating Sitecore Content Editor. Tools Used:SpecFlow,Selenium C#

Issue:Unable to send the Selenium WebDriver instance between SpecFlow Scenarios.

Eg: Helper Class - Creates the instance of Webdriver for every scenario. UtlilityClass - Utility Class inherits from Helper Class .Has Login Scenario which is used by other scenarios in different feature files. Multicolumn Class - Contains scenario - Runs Login functionality from Utility Class and does further steps .

******************CODE******************************* ****Helper Class has only WebDriver and creation of Browser instance ****

Helper Class { protected WebDriverHelper WebDriver { get; private set; } [BeforeScenario] public void BeforeScenario(){WebDriver = WebDriverHelper.Create("SiteCoreAdminPage");}

[AfterScenario] public void AfterScenario(){WebDriver.Dispose(); } }


UtilityFeature-

Scenario:Login Functionality Given Login

UtilityDefinitionFile

Utility Class has all the common functions to be utilised across scenarios. UtilityClass:Helper Class { public void Login() { /Perform all activities to log in/ } }


Multicolumn Feature File-

Scenario: Given Login Then CreateMulticolumnPage

Multicolumn Definition File-

Multicolumn:HelperClass { public void CreateMulticolumnPage() { /*When code reaches this point , another instance of Webdriver is created.I don't want the instance to be created but instead continue the actions in already existing instance of webdriver. } } ****************CODE ENDS********************

1 Answer 1

1

SpecFlow will generate tests for each of your scenario.

[Test]
public void A()
{
     // runs Scenario A
}

[Test]
pubic void B()
{
    // runs Scenario B
}

Tests will be executed by test runner (VS Test Explorer, Resharper, TestDriven.NET, etc.). There is no strict order how this tests will be executed. Test B can be executed separately, can be executed sententiously with A. You can not guarantee that order will be always A=>B. That is why it is not good idea to continue running B after A.

What you can do: move common part test A and B to separate method:

IWebDriver WebDriver;

[Test]
public void A()
{
     CommonPart();
     // runs Scenario A
}

[Test]
pubic void B()
{
    CommonPart();
    // runs Scenario B
}

private void CommonPart()
{
    WebDriver = WebDriverHelper.Create("SiteCoreAdminPage");
    //login
}
2
  • I have added classes and how I have done the coding .Please review and let me know how I can pass the WebDriver instance from 1 scenario to other so that I don't get new instance created every scenario .
    – Smitha
    Jun 1, 2018 at 5:13
  • Smitha, on this site we actually prefer votes over "thank you" comments :-)
    – Mark Cassidy
    Jul 31, 2018 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.