0

I am working on creating a test scripts for a non angular js website using protractor. My code is as follows :

var co = require('co');
var path = require('path');

describe("TEST", function () {

    it("test", co.wrap(function* () {
        browser.ignoreSynchronization = true;

        yield browser.get(URL, 60000);
        browser.sleep(5000);// I want to remove the sleep statements
        var elmOK = browser.driver.findElement(by.css('a[href="#login"]'));
        yield elmOK.click();
        expect(browser.getCurrentUrl()).toContain("login");
        yield browser.switchTo().frame('here-account-sdk').then(function () {
            browser.driver.findElement(by.id('sign-in-email')).sendKeys("uid");
            browser.driver.findElement(by.id('sign-in-password-encrypted')).sendKeys("password");
            browser.driver.findElement(by.xpath(' //*[@id="sign-in-form"]/div[2]/div[6]/form/fieldset[3]/button')).click();

        });
        browser.sleep(5000);// I want to remove the sleep statements
        var elmOK = browser.driver.findElement(by.xpath('//*[@id="lnav"]/li[3]/a'));
        yield elmOK.click();
        browser.sleep(1500);// I want to remove the sleep statements
        browser.driver.findElement(by.xpath('//*[@id="administration"]/div/div[1]/select/option[2]')).click();
        browser.sleep(5000);// I want to remove the sleep statements

        browser.driver.findElement(by.xpath('//*[@id="administration"]/div/div[2]/table/tbody/tr[1]/td[10]/span')).click();
        browser.sleep(5000);// I want to remove the sleep statements

        browser.driver.findElement(by.xpath('//*[@id="content"]/div/div[2]/div/div/div/div[3]/button[1]')).click();//Delete the file
        browser.sleep(5000);// I want to remove the sleep statements
    }));




});

If I add sleep in my code the test runs as expected. But I want to remove sleep statements from my code completely. I referred to many other stack overflow questions but it didn't help. :(

I first used browser.manage().timeouts().implicitlyWait(5000); but I think there was no delay in loading my url.

I used expected condition but it was also not working.

I added browser.wait(1000) but my script fails. Please advice me as I feel bit lost in this problem.

JeffC
  • 22,180
  • 5
  • 32
  • 55
Jatin
  • 660
  • 3
  • 8
  • 28

1 Answers1

0

I think the problem is with this line:

browser.ignoreSynchronization = true;

From this SO it

makes protractor not wait for Angular promises, such as those from $http or $timeout to resolve

Protractor element functions all return promises so this might be the cause of your problem?

Also this structure looks a bit weird:

var elmOK = browser.driver.findElement(by.css('a[href="#login"]'));
yield elmOK.click();

I would simplify with just:

element(by.css('a[href="#login"]')).click();
Community
  • 1
  • 1
bwobbones
  • 2,398
  • 3
  • 23
  • 32