5
votes

I have a login function that I'm using for a Protractor test, it looks like this:

var config = require("../helpers/config.js");

var login = function() {
    browser.driver.get(config.dsp.url);
    browser.driver.findElement(by.name("userName")).sendKeys(config.dsp.user);
    browser.driver.findElement(by.name("password")).sendKeys(config.dsp.password);
    return browser.driver.findElement(by.name("submit")).click().then(function() {
        return browser.driver.wait(function() {
            return browser.driver.isElementPresent(browser.driver.findElement(by.className("sample-class-name")));
        }, 360000);
    });
}

module.exports = login;

I can't use any of the protractor specific hooks because Angular is not used on this page, so I have to use the underlying webdriver API. The problem is, I can't seem to figure out how to wait until an element is visible using this wrapped webdriver object. Any help would be appreciated.

1
The error I get when I run this test is TypeError: "Invalid Locator" for browser.driver.isElementPresent. - Larry Turtis
If Angular is not present, why don't you simply disable the sync with browser.ignoreSynchronization = true; ? - Florent B.
Good question. Angular is going to be present as soon as the login is complete. I just need to get the user past the non-angular login page. - Larry Turtis
You could disable the sync and then enable it once you're done with the page. Note that you'll have to schedule the assignment in the control flow. - Florent B.
That's the problem, I don't quite know when I'm done with the page because I can't figure out whether the element which tells me I am done is present. - Larry Turtis

1 Answers

6
votes

Try with the expected conditions from the underlying driver:

var config = require("../helpers/config.js");
var until = require('selenium-webdriver').until;

var login = function() {
    var driver = browser.driver;

    driver.get(config.dsp.url);
    driver.findElement(by.name("userName")).sendKeys(config.dsp.user);
    driver.findElement(by.name("password")).sendKeys(config.dsp.password);
    driver.findElement(by.name("submit")).click();

    return driver.wait(until.elementLocated(by.css(".sample-class-name")), 10000)
      .then(e => driver.wait(until.elementIsVisible(e)), 10000);
}

module.exports = login;