如何等待网站使用量角器完全加载
问题描述:
我正在为使用量角器的非角度js网站创建测试脚本。我的代码如下:如何等待网站使用量角器完全加载
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
}));
});
如果我在我的代码中添加睡眠,测试按预期运行。但我想彻底删除我的代码中的睡眠声明。我提到了许多其他堆栈溢出问题,但它没有帮助。 :(
我第一次使用browser.manage().timeouts().implicitlyWait(5000);
但我认为是在载入我的网址没有延迟。
我用料的条件,但它也不能正常工作。
我加browser.wait(1000)
但我的脚本失败,请。咨询我,因为我觉得这个问题有点失落
答
我认为这个问题是这一行:
browser.ignoreSynchronization = true;
从this SO它
使得量角器不待角的承诺,如从$ http或$超时解决
量角器元函数都返回承诺,所以这可能是你的问题的原因?
而且这种结构看起来有点怪异:
var elmOK = browser.driver.findElement(by.css('a[href="#login"]'));
yield elmOK.click();
我会只是简化:
element(by.css('a[href="#login"]')).click();