2

In protractor I search for a LinkText Login thats worked fine. I were redirect to the login site (non angular) and type in the username and pw. Clicking the submit button i came back to the first site. Now the Login Button is a Logout button. But protractor cannot see a angular site I only can find the button with selenium indicators.

The spec.js file:

it ('should have a login Button to click', function() {
    loginPage.clickLoginButton();
});

it('should be on idm to login', function() {
    var url = browser.driver.getCurrentUrl();
    expect( url ).toEqual('http://localhost/webapp/login');
});

it('should have access with the given user', function() {
    var idmPage = require('./idmPage.js');
    idmPage.setUsername('bla');
    idmPage.setPassword('secret');
    idmPage.clickSubmitButton();
});

The pageobject.js:

var IdmPage = function() {
var userField =  browser.driver.findElement(by.id('id_login'));
var passwordField = browser.driver.findElement(by.id('id_password'));
var submitButton = browser.driver.findElement(by.id('authentication-button'));

this.setUsername = function(username) {
    userField.sendKeys(username);
};
this.setPassword = function(password) {
    passwordField.sendKeys(password);
};

this.clickSubmitButton = function() {
    submitButton.click();
}; };  module.exports = new IdmPage();

The conf.js

'use strict';

var baseDir = 'test/e2e'; exports.config = {

// The adress of a runnung selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',

//Capabilities to be passed to the webdirver instance.
capabilities: {
    browserName: 'chrome'
},

//Spec patterns are relative to the current working directly when protractor is called

suites: {
    login: baseDir + '/login/**/*_spec.js',
    content: [baseDir + '/content/*_spec.js']
},

//Options to be passed to Jasmine-node
jasmineNodeOpts: {
    onComplete: null,
    isVerbose: true,
    showColors: true,
    includeStackTrace: false,
    defaultTimeoutInterval: 11000
}

};

tbere
  • 105
  • 1
  • 10

1 Answers1

1

You may want to make sure that protractor is actually waiting for your inputs to load when switching between non-angular and angular pages. So did you try using a browser.sleep() or browser.wait() after clicking the submit button? You should set browser.ignoreSynchronization = true; when testing non-angular pages. What is browser.ignoreSynchronization in protractor?

UPDATE:

browser.ignoreSynchronization = true;
this.clickLogoutButton = function(){
    browser.wait(function(){
        return loginButton.isPresent();
    }, 10000).then(function(){
        loginButton.click();
    });
}

this way your test will wait a maximum of 10 seconds before the test times out. You can update this depending on how long it should take at maximum before the button would appear clickable. This is how i deal with testing my non-angular web-pages. I hope this works for you

Community
  • 1
  • 1
Sir Neuman
  • 1,385
  • 1
  • 14
  • 23
  • no that dont work for me hopefully i have implement the wait function correctly 1) Webapp E2E-Tests should have login and redirect to titlepage Message: Error while waiting for Protractor to sync with the page: "angular could not be found on the window" `this.clickLogoutButton = function() { browser.wait(loginButton.isPresent()); loginButton.click(); };` – tbere Jun 10 '15 at 16:31
  • when i use browser.driver.findElement(by.xpath('/html/body/div[1]/div[1]/header/ul/li[1]/a')); it works – tbere Jun 10 '15 at 16:43
  • Well there it will ignore whether or not the element is actually visible or clickable, which you may not care about. Also does not seem like an at all ideal way of trying to click the button. Did you set `browser.ignoreSynchronization` to true before implementing the `browser.wait`? – Sir Neuman Jun 10 '15 at 17:07
  • ok i know thats not the ideal way but its only to know if the test see the angular page. I testet both ways one without the ignoreSynchronization and with ignorSynchonization, doesn't worked for me. Maybe i dont understand the wait function... – tbere Jun 10 '15 at 18:31
  • Actually after looking at your implementation of `browser.wait` i realized it's not quite correct. I updated my answer with how you should try it. – Sir Neuman Jun 10 '15 at 21:05
  • perfect thanks a lot now it works. Sorry but im not so familiar with the javascript promise syntax. – tbere Jun 11 '15 at 06:23