Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. [Binding]
  2. public class LoginStepDefinitions
  3. {
  4. public LoginStepDefinitions(IWebDriver _driver)
  5. {
  6. driver = _driver;
  7. }
  8.  
  9. static IWebDriver driver;
  10.  
  11. [Given(@"I browse to (.*)")]
  12. public void GivenINavigateTo(string url)
  13. {
  14. driver.Navigate().GoToUrl(url);
  15. }
  16.  
  17. [Given(@"I login as (.*?) with Password (.*)")]
  18. public void GivenILoginAs(string username, string password)
  19. {
  20. new LoginPom(driver, username, password);
  21. }
  22.  
  23. [Then(@"I should be logged in")]
  24. public void ThenIShouldBeLoggedIn()
  25. {
  26. Assert.DoesNotThrow(delegate { driver.FindElement(By.Id("logoutButton")); } );
  27.  
  28. }
  29.  
  30. [Given(@"I go to (.*?) within the (.*?) Menu")]
  31. [Then(@"I should have access to (.*?) within the (.*?) Menu")]
  32. public void ThenIShouldHaveAccess(string submenu, string menu)
  33. {
  34. Assert.DoesNotThrow(delegate {
  35. new HeaderPom(driver).selectMenuByName(menu).selectSubMenuByName(submenu);
  36. });
  37. }
  38. }
  39.  
  40. public class LoginPom : Pages
  41. {
  42. public class LoginCredentials
  43. {
  44. public string Username { get; set; }
  45. public string Password { get; set; }
  46. }
  47.  
  48. public static Dictionary<string, LoginCredentials> loginData = new Dictionary<string, LoginCredentials>
  49. {
  50. { "Admin",
  51. new LoginCredentials()
  52. {
  53. Username= "AdminUsername",
  54. Password= "AdminPassword"
  55. }
  56. }
  57. };
  58. [FindsBy(How = How.Id, Using = "ctl00_mainContent_userLogin_UserName")]
  59. private IWebElement UserNameTxt;
  60. [FindsBy(How = How.Id, Using = "ctl00_mainContent_userLogin_Password")]
  61. private IWebElement PasswordTxt;
  62. [FindsBy(How = How.Id, Using = "ctl00_mainContent_userLogin_loginButton")]
  63. private IWebElement LoginBtn;
  64.  
  65.  
  66. public LoginPom(IWebDriver driver) : base(driver)
  67. {
  68. }
  69.  
  70.  
  71. public LoginPom(IWebDriver driver, String username, String password) : base(driver)
  72. {
  73. setUsername(username).setPassword(password).submit();
  74. }
  75.  
  76. public LoginPom setUsername(String username)
  77. {
  78. this.UserNameTxt.Clear();
  79. this.UserNameTxt.SendKeys(username);
  80. return this;
  81. }
  82.  
  83. public LoginPom setPassword(String password)
  84. {
  85. this.PasswordTxt.Clear();
  86. this.PasswordTxt.SendKeys(password);
  87. return this;
  88. }
  89.  
  90. public void submit()
  91. {
  92. this.LoginBtn.Click();
  93. }
  94. }
  95.  
  96. [BeforeScenario("Firefox")]
  97. public void InitializeFirefoxWebDriver()
  98. {
  99. IngeniosSvcTrackerEntities entities = new IngeniosSvcTrackerEntities();
  100. DesiredCapabilities capability = DesiredCapabilities.Firefox();
  101. capability.Platform = new Platform(PlatformType.Any);
  102. launchWebDriver(capability);
  103. objectContainer.RegisterInstanceAs<IngeniosSvcTrackerEntities>(entities);
  104. }
  105.  
  106.  
  107. public void launchWebDriver(DesiredCapabilities capability)
  108. {
  109. string gridUrl = "http://127.0.0.1:4444/wd/hub/";
  110. ScenarioInfo si = ScenarioContext.Current.ScenarioInfo;
  111. if (si.Tags.Any(x => x.StartsWith("GridUrl=")))
  112. {
  113. gridUrl = ConvertToString(si.Tags.FirstOrDefault(x => x.StartsWith("GridUrl=")).Split('=')[1]);
  114. }
  115. var webDriver = new RemoteWebDriver(new Uri(gridUrl), capability);
  116. webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
  117. objectContainer.RegisterInstanceAs<IWebDriver>(webDriver);
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement