shenku
shenku

Reputation: 12458

Using SpecFlow, Selenium and FluentAutomation causing problems

I am currently using Specflow with Selenium and FluentAutomation, and am running into significant problems with maintaining state between steps in specflow.

See my example code below:

[Binding]
public class RegistrationSteps : FluentTest
{

    [Given(@"I create an account")]
    public void GivenICreateAnAccount()
    {
        new HomePage(this)
            .Go()
            .StartRegistration()
            .EnterDetailsAndClickSubmit(); // takes me to deposit page
    }

    [When(@"Deposit '(.*)' dollars in my account")]
    public void GivenDepositMoneyInMyAccount(int amount)
    {
        new DepositPage(this)
            .EnterDetailsAndClickSubmit(amount);
    }
}

My problem is:

So my question is, how can I use one browser session and several PageObjects across multiple Specflow tests?

Upvotes: 0

Views: 203

Answers (1)

AutomatedChaos
AutomatedChaos

Reputation: 7490

According to the FluentAutomation doc, you should do something like this:

[Binding]
public class RegistrationSteps : FluentTest
{
    private PageObject _currentPage;

    [Given(@"I create an account")]
    public void GivenICreateAnAccount()
    {
        _currentPage = new HomePage(this)
            .Go()
            .StartRegistration()
            .EnterDetailsAndClickSubmit(); // takes me to deposit page
    }

    [When(@"Deposit '(.*)' dollars in my account")]
    public void GivenDepositMoneyInMyAccount(int amount)
    {
        _currentPage = _currentPage
            .EnterDetailsAndClickSubmit(amount);
    }
}

Provided that you return the page object that is switched to in the EnterDetailsAndClickSubmit method of your concrete page object like:

Public PageObject EnterDetailsAndClickSubmit() {

    // [.. enter details here and click submit ..]
    return this.Switch();
}

Upvotes: 0

Related Questions