ExecuteAutomation

Writing BDD Code using Selenium POM and Specflow

In the last post we discussed writing a simple code for BDD with Selenium and Specflow, but in this part we will start to leverage the power of Page Object Model in Selenium, again Page Object Model is already discussed many of our post, you can find POM with C# as well Here are some of the links Since we have already discussed a lot about POM, I am not going to touch anything regarding POM, hence we will directly jump into the feature file we got and will start working from there. Here is the complete video for the above discussion Here is the code for the above discussion Login Page Object
    class LoginPage : BasePage
    {
        public LoginPage()
        {
            PageFactory.InitElements(Browser.Current, this);
        }

        [FindsBy(How = How.Name, Using = "UserName")]
        public IWebElement txtUserName;

        [FindsBy(How = How.Name, Using = "Password")]
        public IWebElement txtPassword;

        [FindsBy(How = How.Name, Using = "Login")]
        public IWebElement btnLogin;
}
Step Definition file
    [Binding]
    class LoginSteps
    {

        IWebDriver currentDriver = null;



        LoginPage page = new LoginPage();

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

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

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

        [Then(@"I should see the EA page")]
        public void ThenIShouldSeeTheEAPage()
        {
            ((EAPage)PropertiesCollection.currentPage).IsLoggedIn();
        }
    }
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