Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // spec.js
- describe('KPI Manager Protractor Proof of Concept', function() {
- var Username = element(by.name('username'));
- var Password = element(by.name('password'));
- var LoginButton = element(by.id('logInButton'));
- var hasClass = function (element, cls) {
- return element.getAttribute('class').then(function (classes) {
- return classes.split(' ').indexOf(cls) !== -1;
- });
- };
- function login(a, b) {
- var EC = protractor.ExpectedConditions;
- var isClickable = EC.elementToBeClickable(Username);
- browser.wait(isClickable, 5000); //wait for an element to become clickable
- browser.wait(Username.sendKeys(a),5000);
- browser.sleep(500);
- isClickable = EC.elementToBeClickable(Password);
- browser.wait(isClickable, 5000); //wait for an element to become clickable
- browser.wait(Password.sendKeys(b),5000);
- browser.sleep(500);
- if (a != "" && b != "") {
- var isClickable = EC.elementToBeClickable(LoginButton);
- browser.wait(isClickable, 5000); //wait for an element to become clickable
- browser.wait(LoginButton.click(),5000);
- }
- }
- function logout() {
- browser.sleep(1000);
- var EC = protractor.ExpectedConditions;
- element(by.css("button[aria-label*=account_circle]")).click();
- browser.sleep(500);
- element(by.css("button[aria-label*=exit_to_app]")).click();
- browser.sleep(500);
- }
- beforeEach(function() {
- browser.manage().timeouts().pageLoadTimeout(20000);
- browser.manage().timeouts().implicitlyWait(15000);
- browser.ignoreSynchronization = true;
- browser.get('http://localhost:8906');
- browser.sleep(2000);
- browser.driver.manage().window().maximize();
- });
- //browser.get('http://codemanila.dynamic.nsn-net.net:3932');
- console.log('Test Login Functionality');
- it('Should fail on wrong credentials', function() {
- login("test","test");
- var EC = protractor.ExpectedConditions;
- // Check for 'Authentication Failed'
- browser.wait(EC.presenceOf(element(by.css('.md-toast-content'))),5000);
- //enable next line to display text gotten in the console
- //element(by.css('.md-toast-content')).getText().then(console.log);
- expect(element(by.css('.md-toast-content')).getText()).toContain('Authentication failed');
- });
- it('Should display warnings on empty username field', function() {
- login("","test");
- //Check for the word 'required'
- expect(element.all(by.css('.md-input-message-animation.ng-scope')).first().getText()).toContain('required');
- });
- it('Should display warnings on empty password field', function() {
- login("test","")
- Username.sendKeys();
- //Check for the word 'required'
- expect(element.all(by.css('.md-input-message-animation.ng-scope')).first().getText()).toContain('required');
- });
- it('Should recognize Empty username/password fields', function() {
- //check if username and password fields have ng-invalid
- expect(hasClass(element(by.name('username')), 'ng-invalid')).toBe(true);
- expect(hasClass(element(by.name('password')), 'ng-invalid')).toBe(true);
- login("","");
- Username.sendKeys();
- //check if there are 2 field required messages are visible
- expect(element.all(by.css('.md-input-message-animation.ng-scope')).count()).toBe(2);
- });
- it('Should be able to login on correct credentials, check and close welcome message, and logout. ', function() {
- login(,);
- browser.sleep(7000);
- var got_it = element(by.css('.md-primary.md-button.md-ink-ripple'));
- expect(got_it.getText()).toContain('GOT IT');
- got_it.click();
- logout();
- expect(Username.isPresent()).toBe(true);
- expect(Password.isPresent()).toBe(true);
- expect(browser.getCurrentUrl()).toContain('login');
- });
- // XML reports
- var jasmineReporters = require('jasmine-reporters');
- jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
- consolidateAll: true,
- savePath: 'testresults',
- filePrefix: 'reportXMLoutput'
- }));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement