Guest User

Untitled

a guest
Jan 12th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. public class LoginTests
  2. {
  3. [TestInitialize]
  4. public void Init()
  5. {
  6. Driver.Initialize();
  7. }
  8.  
  9. [TestMethod]
  10. public void Admin_User_Can_Login()
  11. {
  12.  
  13. LoginPage.GoTo();
  14. LoginPage.LoginAs("admin").WithPassword("1234").Login();
  15.  
  16. }
  17. [TestCleanup]
  18. public void Clean()
  19. {
  20. Driver.Instance.Close();
  21. }
  22. }
  23.  
  24. namespace JuiceShopAutomation
  25. {
  26. public class LoginPage
  27. {
  28. public static void GoTo()
  29. {
  30.  
  31. Driver.Instance.Navigate().GoToUrl("www.google.com");
  32. //var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(60));
  33. //wait.Until(d => d.SwitchTo().ActiveElement().GetAttribute("id") == "userEmail");
  34. }
  35.  
  36. public static LoginCommand LoginAs(string userName)
  37. {
  38. return new LoginCommand(userName);
  39. }
  40. }
  41.  
  42. public class LoginCommand
  43. {
  44. private readonly string userName;
  45. private string password;
  46.  
  47. public LoginCommand(string userName)
  48. {
  49. this.userName = userName;
  50. }
  51.  
  52. public LoginCommand WithPassword(string password)
  53. {
  54. this.password = password;
  55. return this;
  56. }
  57.  
  58. public void Login()
  59. {
  60. var loginInput = Driver.Instance.FindElement(By.Id("userEmail"));
  61. loginInput.SendKeys(userName);
  62.  
  63. var passwordInput = Driver.Instance.FindElement(By.Id("userPassword"));
  64. passwordInput.SendKeys(password);
  65.  
  66. var loginButton = Driver.Instance.FindElement(By.Id("loginButton"));
  67. loginButton.Click();
  68. }
  69. }
  70. }
Add Comment
Please, Sign In to add comment