mass jobs
mass jobs

Reputation: 11

If statement to call next step

I have a method in my step def that checks to see if cost centre 11111 is present

If it is I want it to move to the next step in the feature file (book a train).

If it's not there then I want it to add cost centre 1111.

Now when it's not there the logic works as expected, but when it is there I can't get it to move onto the next step in the feature, it just moves on to the "Add cost centre" commands

What am I doing wrong?

CostCentreAdminPage.CostCentreSectionClick();
IWebElement check = null;
if (DriverContext.Driver.TryFindElement(By.XPath("//*[contains(text(),'11111')]"), out check))
{
    GivenAUserInOnTheBookATrainPage();
}
else
    CostCentreAdminPage.AddCostCentreClick();
    CostCentreAdminPage.AddCostCentreInput("11111");
    CostCentreAdminPage.AddCostCentresClick();
}

Upvotes: 0

Views: 226

Answers (1)

Moe Ghafari
Moe Ghafari

Reputation: 2267

Reason is your code inside the else block is not inside the curly brackets

So else should look like this:

else
{
        CostCentreAdminPage.AddCostCentreClick();
        CostCentreAdminPage.AddCostCentreInput("11111");
        CostCentreAdminPage.AddCostCentresClick();
}

In the case you do not include the bracket only the first statement after else will be executed. which is CostCentreAdminPage.AddCostCentreClick(); Then after you exit your else if block, both statements

CostCentreAdminPage.AddCostCentreInput("11111");
CostCentreAdminPage.AddCostCentresClick();

will be executed regardless

Upvotes: 3

Related Questions