Implementation of login steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 username, string 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