Advertisement
Guest User

xx

a guest
Apr 15th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. // spec.js
  2.  
  3. describe('KPI Manager Protractor Proof of Concept', function() {
  4. var Username = element(by.name('username'));
  5. var Password = element(by.name('password'));
  6. var LoginButton = element(by.id('logInButton'));
  7. var hasClass = function (element, cls) {
  8. return element.getAttribute('class').then(function (classes) {
  9. return classes.split(' ').indexOf(cls) !== -1;
  10. });
  11. };
  12. function login(a, b) {
  13. var EC = protractor.ExpectedConditions;
  14. var isClickable = EC.elementToBeClickable(Username);
  15. browser.wait(isClickable, 5000); //wait for an element to become clickable
  16. browser.wait(Username.sendKeys(a),5000);
  17. browser.sleep(500);
  18. isClickable = EC.elementToBeClickable(Password);
  19. browser.wait(isClickable, 5000); //wait for an element to become clickable
  20. browser.wait(Password.sendKeys(b),5000);
  21. browser.sleep(500);
  22. if (a != "" && b != "") {
  23. var isClickable = EC.elementToBeClickable(LoginButton);
  24. browser.wait(isClickable, 5000); //wait for an element to become clickable
  25. browser.wait(LoginButton.click(),5000);
  26. }
  27. }
  28. function logout() {
  29. browser.sleep(1000);
  30. var EC = protractor.ExpectedConditions;
  31. element(by.css("button[aria-label*=account_circle]")).click();
  32. browser.sleep(500);
  33. element(by.css("button[aria-label*=exit_to_app]")).click();
  34. browser.sleep(500);
  35. }
  36. beforeEach(function() {
  37. browser.manage().timeouts().pageLoadTimeout(20000);
  38. browser.manage().timeouts().implicitlyWait(15000);
  39. browser.ignoreSynchronization = true;
  40. browser.get('http://localhost:8906');
  41. browser.sleep(2000);
  42. browser.driver.manage().window().maximize();
  43. });
  44.  
  45. //browser.get('http://codemanila.dynamic.nsn-net.net:3932');
  46.  
  47.  
  48. console.log('Test Login Functionality');
  49.  
  50. it('Should fail on wrong credentials', function() {
  51. login("test","test");
  52. var EC = protractor.ExpectedConditions;
  53. // Check for 'Authentication Failed'
  54. browser.wait(EC.presenceOf(element(by.css('.md-toast-content'))),5000);
  55. //enable next line to display text gotten in the console
  56. //element(by.css('.md-toast-content')).getText().then(console.log);
  57. expect(element(by.css('.md-toast-content')).getText()).toContain('Authentication failed');
  58. });
  59.  
  60. it('Should display warnings on empty username field', function() {
  61. login("","test");
  62. //Check for the word 'required'
  63. expect(element.all(by.css('.md-input-message-animation.ng-scope')).first().getText()).toContain('required');
  64. });
  65.  
  66. it('Should display warnings on empty password field', function() {
  67. login("test","")
  68. Username.sendKeys();
  69. //Check for the word 'required'
  70. expect(element.all(by.css('.md-input-message-animation.ng-scope')).first().getText()).toContain('required');
  71. });
  72.  
  73. it('Should recognize Empty username/password fields', function() {
  74. //check if username and password fields have ng-invalid
  75. expect(hasClass(element(by.name('username')), 'ng-invalid')).toBe(true);
  76. expect(hasClass(element(by.name('password')), 'ng-invalid')).toBe(true);
  77. login("","");
  78. Username.sendKeys();
  79. //check if there are 2 field required messages are visible
  80. expect(element.all(by.css('.md-input-message-animation.ng-scope')).count()).toBe(2);
  81. });
  82.  
  83. it('Should be able to login on correct credentials, check and close welcome message, and logout. ', function() {
  84. login(,);
  85. browser.sleep(7000);
  86. var got_it = element(by.css('.md-primary.md-button.md-ink-ripple'));
  87. expect(got_it.getText()).toContain('GOT IT');
  88. got_it.click();
  89. logout();
  90. expect(Username.isPresent()).toBe(true);
  91. expect(Password.isPresent()).toBe(true);
  92. expect(browser.getCurrentUrl()).toContain('login');
  93. });
  94.  
  95.  
  96.  
  97. // XML reports
  98. var jasmineReporters = require('jasmine-reporters');
  99. jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
  100. consolidateAll: true,
  101. savePath: 'testresults',
  102. filePrefix: 'reportXMLoutput'
  103. }));
  104.  
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement