protractor hangs after running a .sendKeys

Viewed 299

I am new to using protractor and am struggling with getting even a simple script running.

The symptom is "field1" is populated and then the script hangs. Removing the "await" on the .sendKeys causes the script to run but if I then move "if (await field2.isPresent()) {" down to below the "field1" sendKeys then once again only the "field1" is populated.

The issue seems to me to be around promises, but only a guess. What I need is to be able to have my .isPresent checks anywhere in my scripts. This is obviously a simplified example and is done for ease of explanation.

angular version 6

protractor.conf.js

allScriptsTimeout: 30000, ... SELENIUM_PROMISE_MANAGER: false,

package.json extract

"cucumber": "^5.0.2", "cucumber-html-reporter": "^4.0.4", "jasmine": "^3.3.0", "jasmine-core": "2.99.1", "jasmine-spec-reporter": "4.2.1", "protractor": "^5.4.1", "protractor-cucumber-framework": "^6.1.1", "protractor-html-screenshot-reporter": "0.0.21",

Given ('peek capture is running', {timeout: 30000},  async function ()  {
    await browser.get('#/login');
    let field1: ElementFinder = element(by.id('login-email'));
    let field2: ElementFinder = element(by.id('login-password'));
    let field3: ElementFinder = element(by.css('#theButton'));
    if (await field1.isPresent()) {
        if (await field2.isPresent()) {
            await field1.sendKeys('theuser@the.org');
            await field2.sendKeys('the password');
            await field3.click();

            await browser.sleep(1500);
        }
    }
    return(null);
});
1 Answers

You can make use of ExpectedConditions in protractor

https://www.protractortest.org/#/api?view=ProtractorExpectedConditions

Given ('peek capture is running', {timeout: 30000},  async function ()  {

var EC = protractor.ExpectedConditions;
var input1 = element(by.id('login-email'));
var input2 = element(by.id('login-password'));
var btn = element(by.css('#theButton'));
browser.wait(EC.visibilityOf(input1), 10000);
input1.sendKeys('****');
browser.wait(EC.visibilityOf(input2), 10000);
input2.sendKeys('****');
browser.wait(EC.isClickable(btn), 10000);
btn.click();

})
Related