Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Implementation of login steps
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using TechTalk.SpecFlow;
namespace TatAuto.Bindings.Steps
{
    [Binding]
    public class LoginSteps
    {
        private IWebDriver _driver;
        [Given(@"I Navigate to the Login page")]
        public void GivenINavigateToTheLoginPage()
        {
            _driver = new ChromeDriver();
            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            _driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(10);
            _driver.Manage().Window.Maximize();
            _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)
        {
//Locate the Web Elements
            var usernameBox = _driver.FindElement(By.Id("user_login"));            
            var passwordBox = _driver.FindElement(By.Id("user_pass"));           
            var submitBtn = _driver.FindElement(By.Id("wp-submit"));
          
//Perform Required action with the element
            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));
            _driver.Close();
            _driver.Quit();
        }
    }
}
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.