Advertisement
Guest User

Untitled

a guest
Oct 6th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. var AccountLoginPage = function (chromeless, options) {
  2. this.chromeless = chromeless
  3. this.options = options
  4.  
  5. this.usernameLocator = 'input[id="Username"]'
  6. this.passwordLocator = 'input[id="Password"]'
  7. this.submitButtonLocator = 'form input[type="submit"]'
  8. this.inputWithValidationErrorLocator = 'input.input-validation-error'
  9. this.usernameRequiredValidationLocator = '.field-validation-error[data-valmsg-for="Username"]'
  10. this.passwordRequiredValidationLocator = '.field-validation-error[data-valmsg-for="Password"]'
  11. this.page = '/account'
  12. };
  13.  
  14. AccountLoginPage.prototype.visit = async function () {
  15. await this.chromeless
  16. .goto(this.options.url + this.page)
  17. .setViewport({ width: 1200, height: 800, scale: 1 })
  18. }
  19.  
  20. AccountLoginPage.prototype.checkWeAreOnTheAccountPage = async function () {
  21. const href = await this.chromeless
  22. .evaluate(href => window.location.href)
  23.  
  24. return href.slice(-this.page.length) === this.page
  25. }
  26.  
  27. AccountLoginPage.prototype.fillInTheUsername = async function (username) {
  28. await this.chromeless
  29. .type(username, this.usernameLocator)
  30. }
  31.  
  32. AccountLoginPage.prototype.fillInThePassword = async function (password) {
  33. await this.chromeless
  34. .type(password, this.passwordLocator)
  35. }
  36.  
  37. AccountLoginPage.prototype.submitTheForm = async function () {
  38. await this.chromeless
  39. .click(this.submitButtonLocator)
  40. }
  41.  
  42. AccountLoginPage.prototype.checkUserNameValidationIsShown = async function () {
  43. return await this.chromeless
  44. .wait(this.inputWithValidationErrorLocator)
  45. .exists(this.usernameRequiredValidationLocator)
  46. }
  47.  
  48. AccountLoginPage.prototype.checkPasswordValidationIsShown = async function () {
  49. return await this.chromeless
  50. .wait(this.inputWithValidationErrorLocator)
  51. .exists(this.passwordRequiredValidationLocator)
  52. }
  53.  
  54. AccountLoginPage.prototype.checkUserNameNotFoundIsShown = async function () {
  55. return await this.chromeless
  56. .wait(this.inputWithValidationErrorLocator)
  57. .evaluate(() =>
  58. document.getElementsByClassName('field-validation-error')[0]
  59. .innerHTML === 'User could not be found'
  60. )
  61. }
  62.  
  63. AccountLoginPage.prototype.fullLogin = async function(username, password) {
  64. this.visit();
  65. this.fillInTheUsername(username)
  66. this.fillInThePassword(password)
  67. this.submitTheForm()
  68. }
  69.  
  70. module.exports = AccountLoginPage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement