Currently, I am in the process of developing test scripts for a non-angular JS website using Protractor. Below is a snippet of my code:
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
}));
});
Although adding sleep statements makes the test run as intended, I am looking to eliminate them from my code altogether. Despite consulting various Stack Overflow threads, I have yet to find a solution. :(
Initially, I tried
browser.manage().timeouts().implicitlyWait(5000);
, but there seemed to be no delay in loading my URL.
I also experimented with expected conditions, but unfortunately, that did not work either.
When I incorporated browser.wait(1000)
, my script failed. I would greatly appreciate any advice or guidance on this matter as I am feeling quite stuck.