Skip to content

Instantly share code, notes, and snippets.

@testautomationtribe
Last active November 5, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save testautomationtribe/52a46d1282e597f3716ff1e6b36fcd1b to your computer and use it in GitHub Desktop.
Save testautomationtribe/52a46d1282e597f3716ff1e6b36fcd1b to your computer and use it in GitHub Desktop.
Binding with hooks
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using TechTalk.SpecFlow;
namespace TatAuto.Bindings.Steps
{
    [Binding]
    public class LoginSteps
    {
        private readonly IWebDriver _driver;
        public LoginSteps()
        {
            _driver = ScenarioContext.Current.Get<IWebDriver>("currentDriver");
        }
        [Given(@"I Navigate to the Login page")]
        public void GivenINavigateToTheLoginPage()
        {
           _driver.Navigate().GoToUrl("http://127.0.0.1:4001/wordpress/wp-login.php");            
        }
        
        [When(@"I Login with Username '(.*)' and Password '(.*)' on the Login Page")]
        public void WhenILoginWithUsernameAndPasswordOnTheLoginPage(string username, string password)
        {
            var usernameBox = _driver.FindElement(By.Id("user_login"));          
            var passwordBox = _driver.FindElement(By.Id("user_pass"));    
            var submitBtn = _driver.FindElement(By.Id("wp-submit"));
         
            usernameBox.SendKeys(username);
   Thread.Sleep(1000);
            passwordBox.SendKeys(password);
   Thread.Sleep(1000);
            submitBtn.Click();
   Thread.Sleep(1000);
        }   
        [Then(@"the User Name '(.*)' Should be seen on the Dashboard Page")]
        public void ThenTheUserNameShouldBeSeenOnTheDashboardPage(string expectedUser)
        {
            var actualUser = _driver.FindElement(By.CssSelector("#wp-admin-bar-my-account .ab-item")).Text;
            Assert.IsTrue(actualUser.Contains(expectedUser));
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment