Site Loader
Auckland, New Zealand
In the last post we saw how we can write our code using Page Object Model of Selenium with BDD and Specflow, and in this post we are going to extend the previous topic and start working with Page Navigation of Selenium. In this post we are going to create two feature files and will with two different scenarios like Login and EA form update. Here is how the feature file looks like EA Page Feature Login Feature Please find below the complete video of the above discussion Here is the complete code from the above video Login Page Steps
        IWebDriver currentDriver = null;


        [Given(@"I have navigated to my application")]
        public void GivenIHaveNavigatedToMyApplication()
        {
            Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]);
            currentDriver = Browser.Current;
            PropertiesCollection.currentPage = new LoginPage();
        }

        [Given(@"I typed the admin and admin")]
        public void GivenITypedTheAdminAndAdmin(string userName, string password)
        {
            PropertiesCollection.currentPage.As().Login(userName, password);
        }

        [When(@"I click login button")]
        public void WhenIClickLoginButton()
        {
            PropertiesCollection.currentPage = PropertiesCollection.currentPage.As().ClickLogin();
        }

        [Then(@"I should see the EA page")]
        public void ThenIShouldSeeTheEAPage()
        {
            PropertiesCollection.currentPage.As().IsLoggedIn();
        }
EA Page Steps
   class EASteps
    {

        [Given(@"I typed the UserName and Password")]
        public void GivenITypedTheUserNameAndPassword(Table table)
        {
           dynamic values = table.CreateDynamicInstance();
           PropertiesCollection.currentPage.As().Login(values.UserName, values.Password);
        }

        [When(@"I enter all the details to EA Page and Click Save")]
        public void WhenIEnterAllTheDetailsToEAPageAndClickSave(Table table)
        {
            dynamic values = table.CreateDynamicInstance();

            PropertiesCollection.currentPage.As().FillDetails(values.Initial, values.FirstName, values.MiddleName);
        }

        [Then(@"I should see my details saved")]
        public void ThenIShouldSeeMyDetailsSaved(Table table)
        {
            dynamic values = table.CreateDynamicInstance();
            PropertiesCollection.currentPage.As().GetFilledDetails(values.Initial, values.FirstName, values.MiddleName);
        }
    }
Thanks for watching the video and reading the post !!! Please leave your comments and let me know if there is anything need to be improved in this post. Thanks, Karthik KK

Post Author: Karthik kk

24 Replies to “BDD with Selenium POM Page Navigation and Specflow”

  1. I want to know more about the EA page step def.

    Please guide me .. I am still unable to understand how you pass Data table .

    pleas help me.

  2. Hi Karthik ,

    Is it possible to give me the project code. I followed your tutorial but have error in my project.

    Thank you

  3. Hi Karthik ,

    My scenario is use the browser that open to execute the next test, instead of opening a new browser on each test. How will i initialise the driver fr this scenario.

    Thanks

    1. Ofcourse anything is possible in programming world 🙂

      All you have to do is not to close the browser at the end of every test and try to run the next scenario.

      Make sure you dont open browser for every scenarios as well, open browser only one time in your test execution life-cycle.

      Hope it makes sense !!!

      If you are very interested in how big frameworks are developed, here is the link for you just to see how I designed it https://www.udemy.com/framework-development-with-selenium-csharp-advanced/

      Thanks,
      Karthik KK

  4. Hi Karthik, I looked at your course on UDEMY and noticed that you do not have a tutorial on how to upload the project to git and do continuous integration with Jenkins. Thats the reason decided not to go for this course.

  5. Hi Karthik ,

    When changing from currentPage.as to a new page in a different given in the same scenario it is not being located.
    ex.

    [Given(@”test question”)]
    public void test()
    {
    Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings[“seleniumBaseUrl”]);
    Browser.Current.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
    _CurrentPage = GetInstance();

    //Navigate to page

    _CurrentPage.As().Autologin.Click();
    _CurrentPage = GetInstance();
    _CurrentPage.As().PractitionerList.Click();
    _CurrentPage.As().QuickSearchValueFirstName.Clear();
    _CurrentPage.As().QuickSearchValueLastName.Clear();

    [Given(@”test question 2″)]
    public void testanothergiven()
    {
    _CurrentPage = GetInstance(); —> after 1st given is complete and I go to change page. Nothing happens, it return back to the initial page
    _CurrentPage.As().QuickSearchValueFirstName.Clear();
    }

    Can you explain what is happening ?, I have your videos from uademy. but dont see how you handle changing current page going into the next test method. the steps change find.

    thanks,

    1. May I please know which course you purchased in Udemy and the lecture number so that I can help.

      I dont remember where I told about this code.

      Thanks

  6. Hi Karthik,

    I have one scenario where i need to verify multiple links so i am passing links as parameters
    Examples
    |links| |Validate|
    |link1| |link1|
    |link2| |link2|
    as on..
    I wanted verify these links i am not getting how to do.Please suggest me on this.

  7. Hi Karthik,

    I want to buy Automation framework development with Selenium C# (Advanced), Can I have any coupon code please.

    Thanks,
    Deepa

  8. Hi,
    First of all I would like to say big thanks about things you are doing. I have learned form you a lot. Especially C# Specflow. Also I relay enjoy weekly videos on YouTube. I am planning to buy your advanced course C# Selenium on Udemy. It would be great if you could share coupon code.
    Armands

  9. Is there any way to not repeat feature file steps in next feature file and open in same browser instance . Below is my code i am using DI.

    Hooks Class Code…

    using BoDi;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using TechTalk.SpecFlow;

    namespace SepecFlowParallelTest
    {
    [Binding]
    public class Hooks
    {
    private readonly IObjectContainer _Iobject;
    private IWebDriver _driver;
    public Hooks(IObjectContainer Iobject)
    {
    _Iobject = Iobject;

    }

    [BeforeScenario]
    public void Initialize()
    {
    _driver = new ChromeDriver();
    _Iobject.RegisterInstanceAs(_driver);

    }

    [AfterScenario]
    public void Cleanup()
    {

    _driver.Quit();
    }
    }
    }
    LoginSteps.cs Code…

    using NUnit.Framework;
    using OpenQA.Selenium;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using TechTalk.SpecFlow;
    using TechTalk.SpecFlow.Assist;

    namespace SepecFlowParallelTest.Steps
    {
    [Binding]
    public class LoginSteps
    {
    private IWebDriver _driver;
    public LoginSteps(IWebDriver driver)
    {
    _driver = driver;
    }
    [Given(@”I navigate to application”)]
    public void GivenINavigateToApplication()
    {
    _driver.Navigate().GoToUrl(“https://contractorcentralapp.azurewebsites.net/login”);
    }

    [Given(@”I enter username and password”)]
    public void GivenIEnterUsernameAndPassword(Table table)
    {
    dynamic data = table.CreateDynamicInstance();
    _driver.FindElement(By.XPath(“//input[@id=’txtLogin’]”)).SendKeys((string)data.UserName);
    _driver.FindElement(By.XPath(“//input[@id=’txtPasword’]”)).SendKeys((string)data.Password);
    }

    [Given(@”I click login”)]
    public void GivenIClickLogin()
    {
    _driver.FindElement(By.XPath(“//button[contains(text(),’Login’)]”)).Click();
    }

    [Then(@”I should see the user logged into the application”)]
    public void ThenIShouldSeeTheUserLoggedIntoTheApplication()
    {
    if (_driver != null)
    {
    var a = _driver.PageSource;
    var url = _driver.Url;
    }

    var element = _driver.FindElement(By.XPath(“//h2[contains(text(),’Application Types’)]”));
    Assert.That(element.Text, Is.Not.Null, “Header text not found !!!”);
    // return new UserForm (_driver);
    }

    }
    }
    UserForm.cs code…

    using OpenQA.Selenium;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using TechTalk.SpecFlow;

    namespace SepecFlowParallelTest.Steps
    {
    [Binding]
    public class UserForm
    {
    private IWebDriver _driver;
    public UserForm(IWebDriver driver)
    {
    _driver = driver;
    }

    [Given(@”I Check CheckBoxes”)]
    public void GivenICheckCheckBoxes()
    {

    var url = _driver.Url;
    var selectcheckbox = _driver.FindElements(By.XPath(“//kendo-panelbar-item”));
    if (selectcheckbox.Count > 0)
    {

    }
    }

    }
    }

    Login Feature File…
    Feature: Login
    Check if login functionality works

    Scenario: Login user as administartor
    Given I navigate to application
    And I enter username and password
    | UserName | Password |
    | vivek.sharma@xyz.com | abc |
    And I click login
    Then I should see the user logged into the application

    User Feature File…

    Feature: UserForm

    @mytag
    Scenario: I am logged in
    Given I navigate to application
    And I enter username and password
    | UserName | Password |
    | vivek.sharma@xyz.com | abc|
    And I click login
    And I Check CheckBoxes

    My question is i do not want to repeat login Feature step in User feature File I only want “I check checkbox step” and i want to run in same browser instance that i have logged in but the problem is if i removed duplicate steps from User feature file , it is unable to find elements of next page i am using parallel execution in AssemblyInfo.cs

    i want when i logged in to the application using Login feature, then open user form page in the same browser instance.

    Any help would be greatly appreciated!

Leave a Reply to Abu Cancel reply

Your email address will not be published. Required fields are marked *