Advertisement
Guest User

Untitled

a guest
May 17th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /*
  4. * InputLabelPageObject.js
  5. *
  6. * This object will provide basic methods for an Input box with an attached label.
  7. * It is expected that the label will have an element called "label" and an element called "input"
  8. */
  9.  
  10. module.exports = InputLabelPageObject;
  11.  
  12. /**
  13. * Create an object that will provide methods for an input/label combination of elements.
  14. *
  15. * @param container The selector for the __container of the input/label combination of elements.
  16. */
  17. function InputLabelPageObject(container) {
  18. this.Container = container;
  19. }
  20.  
  21. InputLabelPageObject.prototype = {
  22. constructor: InputLabelPageObject,
  23. /**
  24. * Return the element for the label of the input/label combination of elements.
  25. *
  26. * @returns {protractor.element}
  27. */
  28. getLabel: function () {
  29. return this.Container.$('label');
  30. },
  31. /**
  32. * Return the element for the input of the input/label combination of elements.
  33. *
  34. * @returns {ElementFinder}
  35. */
  36. getInput: function () {
  37. return this.Container.$('input');
  38. },
  39. /**
  40. * Return the text shown in the input of the input/label combination of elements.
  41. *
  42. * @returns {Promise}
  43. */
  44. getValue: function () {
  45. return this.getInput().getAttribute('value');
  46. },
  47. /**
  48. * Get the placeholder text shown in the input of the input/label combination of elements.
  49. *
  50. * @returns {Promise}
  51. */
  52. getPlaceholder: function () {
  53. return this.getInput().getAttribute('placeholder');
  54. },
  55. /**
  56. * Clears the input element then puts the text from data into the input element.
  57. *
  58. * @param data The text to be entered into the input element.
  59. */
  60. sendKeys: function (data) {
  61. var el = this.getInput();
  62. el.clear().then(function () {
  63. return el.sendKeys(data);
  64. });
  65. }
  66. };
  67.  
  68. 'use strict';
  69.  
  70. /*
  71. * InputLabelVerification.js
  72. *
  73. * Provide verification methods associated with an Input and Label
  74. * combination of elements.
  75. */
  76.  
  77. module.exports = InputLabelVerifications;
  78.  
  79. var inputLabelPageObject;
  80.  
  81. function InputLabelVerifications(inputLabelPageObject) {
  82. this.__setPageObject(inputLabelPageObject);
  83. }
  84.  
  85. InputLabelVerifications.prototype = {
  86. constructor: InputLabelVerifications,
  87. __setPageObject: function (ilpo) {
  88. inputLabelPageObject = ilpo;
  89. },
  90. /**
  91. * Verify the text on the label of the input/label combination of elements.
  92. *
  93. * @param expected The expected text on the label.
  94. */
  95. verifyText: function (expected) {
  96. //console.log('Asserting text [' + expected + ']');
  97. expect(inputLabelPageObject.getLabel()).toEqual(expected);
  98. },
  99. /**
  100. * Verify the text shown in the input of the input/label combination of elements.
  101. *
  102. * @param expected The expected text in the input element.
  103. */
  104. verifyValue: function (expected) {
  105. //console.log('Asserting input value [' + expected + ']');
  106. expect(inputLabelPageObject.getValue()).toEqual(expected);
  107. },
  108. /**
  109. * Verify the placeholder text shown in the input of the input/label combination of elements.
  110. *
  111. * @param expected The expected text of the placeholder.
  112. */
  113. verifyPlaceholder: function (expected) {
  114. //console.log('Verifying placeholder text [' + expected + ']');
  115. expect(inputLabelPageObject.getPlaceholder()).toEqual(expected);
  116. }
  117. };
  118.  
  119. 'use strict';
  120.  
  121. /*
  122. * LoginPageObject.js
  123. *
  124. */
  125.  
  126. var InputLabelPageObject = require('./generics/InputLabelPageObject.js');
  127.  
  128. module.exports = LoginPageObject;
  129.  
  130. var __container = $('login-component');
  131. var username = new InputLabelPageObject(__container.$('form:nth-child(2) > div:nth-child(1)'));
  132. var password = new InputLabelPageObject(__container.$('form:nth-child(2) > div:nth-child(2)'));
  133.  
  134. /**
  135. * Create an object that contains the methods necessary to perform actions against the LoginPageObject page.
  136. *
  137. * @param url The base URL string. If not undefined, it will load the url+'/login' page.
  138. * @constructor new LoginPageObject('http://localhost:9000');
  139. */
  140. function LoginPageObject(url) {
  141. if (url) {
  142. this.loadPage(url)
  143. }
  144. }
  145.  
  146. LoginPageObject.prototype = {
  147. constructor: LoginPageObject,
  148. loadPage: function (url) {
  149. url = url + '/login';
  150. console.log('Loading page: '+ url);
  151. browser.get(url);
  152. },
  153. welcome: {
  154. /**
  155. * Return the element for the Welcome text
  156. *
  157. * @returns {ElementFinder}
  158. */
  159. get: function () {
  160. return __container.$('section:first-child h1:first-child');
  161. },
  162. },
  163. /**
  164. * Return an InputLabelPageObject object specific for the username input and label elements.
  165. */
  166. username: username,
  167. /**
  168. * Return an InputLabelPageObject object specific for the password input and label elements.
  169. */
  170. password: password,
  171. loginButton: {
  172. /**
  173. * Return the element for the login button.
  174. *
  175. * @returns {ElementFinder}
  176. */
  177. get: function () {
  178. return __container.$('form > button');
  179. },
  180. /**
  181. * Click the LoginPageObject button.
  182. * @returns {*|void|webdriver.promise.Promise<void>|ActionSequence|!webdriver.promise.Promise.<void>}
  183. */
  184. click: function () {
  185. return this.get().click();
  186. }
  187. }
  188. };
  189.  
  190. 'use strict';
  191.  
  192. /*
  193. * LoginPageVerifications.js
  194. */
  195.  
  196. var LoginPageObject = require('../pageObjects/LoginPageObject');
  197. var verifyText = require('./generics/VerifyText');
  198. var inputLabelVerifications = require('./generics/InputLabelVerifications');
  199.  
  200. module.exports = LoginPageVerifications;
  201.  
  202. var __loginPageObject = new LoginPageObject();
  203.  
  204. function LoginPageVerifications(url) {
  205. if (url) {
  206. __loginPageObject = new LoginPageObject(url);
  207. }
  208. }
  209.  
  210. LoginPageVerifications.prototype = {
  211. constructor: LoginPageVerifications,
  212. loginPageObject: new LoginPageObject(),
  213. welcome: {
  214. verifyText: function (expected) {
  215. verifyText(__loginPageObject.welcome.get(), expected);
  216. }
  217. },
  218. username: new inputLabelVerifications(__loginPageObject.username),
  219. password: new inputLabelVerifications(__loginPageObject.password),
  220. loginButton: {
  221. verifyText: function (expected) {
  222. verifyText(__loginPageObject.loginButton.get(), expected);
  223. }
  224. },
  225. /**
  226. * Performs the actions of logging in. That is, enter the username and password values,
  227. * then click the LoginPageObject button. This does *not* verify page load.
  228. *
  229. * @param username The username to login with.
  230. * @param password The password to login with.
  231. */
  232. doLogin: function (username, password) {
  233. var uPromise = __loginPageObject.username.sendKeys(username);
  234. var pPromise = __loginPageObject.password.sendKeys(password);
  235. protractor.promise.asap(this.username.verifyValue(username));
  236. protractor.promise.asap(this.password.verifyValue(password));
  237. protractor.promise.all([uPromise, pPromise]).then(this.loginButton.click());
  238. },
  239. /**
  240. * Verifies all page elements' text or other default attributes.
  241. *
  242. * @param welcomeText The expected Welcome text
  243. * @param userText The expected username label text.
  244. * @param userPlaceholder The expected username's input element's placeholder text.
  245. * @param passText The expected password label text.
  246. * @param passPlaceholder The expected password's input element's placeholder text.
  247. * @param loginText The expected login button text.
  248. */
  249. verifyPage: function (welcomeText, userText, userPlaceholder, passText, passPlaceholder, loginText) {
  250. this.welcome.verifyText(welcomeText);
  251. this.username.verifyText(userText);
  252. this.username.verifyPlaceholder(userPlaceholder);
  253. this.password.verifyText(passText);
  254. this.password.verifyPlaceholder(passPlaceholder);
  255. this.loginButton.verifyText(loginText);
  256. }
  257.  
  258. };
  259.  
  260. 'use strict';
  261.  
  262. /*
  263. * login-spec.js
  264. */
  265.  
  266. var LoginPageVerifications = require('../components/actions/LoginPageVerifications');
  267.  
  268. var myUrl = 'http://localhost:3000';
  269.  
  270. describe('My Login Page test', function() {
  271. var loginPage;
  272. beforeAll(function() {
  273. loginPage = new LoginPageVerifications(myUrl);
  274. });
  275.  
  276. it('should verify username input and label values', function() {
  277. var welcomeText = 'Thank you for visiting my login page';
  278. var userText = 'Username';
  279. var userPlaceholder = 'Enter your username';
  280. var passText = 'Password';
  281. var passPlaceholder = 'Enter your password';
  282. var loginText = 'Login';
  283.  
  284. loginPage.username.verifyText(userText);
  285. // loginPage.verifyPage(welcomeText, userText, userPlaceholder, passText, passPlaceholder, loginText);
  286. });
  287. });
  288.  
  289. A Jasmine spec timed out. Resetting the WebDriver Control Flow.
  290. F
  291.  
  292. Failures:
  293. 1) My Login Page test should verify username input and label values
  294. Expected ({ ptor_: ({ controlFlow: Function, schedule: Function,
  295. setFileDetector: Function, getSession: Function, getCapabilities: Function,
  296. quit: Function, actions: Function, touchActions: Function,
  297. executeScript: Function, executeAsyncScript: Function, call: Function,
  298. wait: Function, sleep: Function, getWindowHandle... }) }) to equal 'Username'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement