I am breaking down the testing on this so that I have feature files for areas like Login, ResetPassword, ForgotPassword etc. Let's say I have the below example. I have an automation step creating a brand new user in CreateAccount.feature. That step is used multiple times within that Feature/Step Class without issue. But now I want the user to change their password so I create a new Feature File MyAccount.feature. When I copy the Given Statement in, it is found immediately. Then I add the code to click the reset password and continue on with the rest of the steps.
When I run the ResetPassword test, the automation creates the new user but when it get's to step 2, "When I Click Reset Password" it fails because it can't find the element. Since bindings are global, this strikes me odd. So what I did was take step "Given I have created my account" and renamed it and added to the other feature file/steps class and ran it again. It worked fine.
I am not sure why I can't share between steps. Any ideas?
Some updates showing more code...
CreateAccount.feature
scenario: Feature Create Account
Given I have created my account
-----------
CreateAccountsteps.cs
namespace Project
{
[Binding]
public class CreateAccount: BaseTestObject
{
[Given]
public void Given_I_have_created_my_account()
{
ConfigProperties.Environment = "Test";
TestDriver.goToUrl(ConfigProperties.StartUrl);
TestDriver.goToUrl(ConfigProperties.StartUrl + "Create/Account");
[followed by input for creating a user acct]
-------------------------------------------------
MyAccount.feature
scenario: Feature Change Password
Given I have created my account
When I Click Reset Password
...........
MyAccountSteps.cs
namespace Project
{
[Binding]
public class MyAccountSteps: BaseTestObject
{
[When]
public void When_I_click_Reset_Password()
{
On.MyHeaderPage.BtnResetPassword.Click();
}
[followed by rest of steps to change password]
BaseTestObject.cs
namespace Project
{
public class BaseTestObject
{
private IWebDriver seleniumDriver;
private IDriver testDriver;
[TestInitialize]
public virtual void Setup()
{
TestDriver.goToUrl(ConfigProperties.StartUrl);
}
[AfterScenario]
public void CleanUp()
{
if (seleniumDriver != null)
{
SeleniumDriver.Dispose();
seleniumDriver = null;
}
}
public IWebDriver SeleniumDriver
{
get
{
if (seleniumDriver == null)
{
seleniumDriver = GetDriver();
}
return seleniumDriver;
}
}
public IDriver TestDriver
{
get
{
if (testDriver == null)
{
testDriver = new UiDriver(SeleniumDriver);
}
return testDriver;
}
}
public CurrentPageObjectScope On
{
get
{
return new CurrentPageObjectScope(TestDriver);
}
}
public static String GetTimestamp()
{
return DateTime.Now.ToString("yyyyMMddhhmmssfff");
}
public static String GetTimestamp2()
{
return DateTime.Now.ToString("M/d/yyyy");
}
private IWebDriver GetDriver()
{
switch (ConfigProperties.Browser.ToLower())
{
case "firefox":
return new FirefoxDriver();
case "chrome":
ChromeOptions options = new ChromeOptions();
ChromeDriverService service = ChromeDriverService.CreateDefaultService(@"../Chrome/");
service.SuppressInitialDiagnosticInformation = true;
service.HideCommandPromptWindow = true;
options.AddArguments("test-type");
options.AddArgument("--start-maximized");
return new ChromeDriver(service, options);
case "ie":
case "internetexplorer":
return new InternetExplorerDriver(@"../IE/");
default:
throw new NotImplementedException("Unknown browser string in Config properties " + ConfigProperties.Browser);
}
}
MySteps
andMyTestTest
) for each scenario so any objects that they use may be different – Sam Holder