Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 usernamestring 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
You can’t perform that action at this time.