如何确保元素不可见并继续量角器中的下一个条件

How to make sure that the element is not visible and proceed with the next conditions in protractor

我正在测试一个元素,当用户选择一个单选按钮时,加载图像将出现在中间,几秒钟后将不可见。当加载图像消失时,它应该显示登录屏幕并执行所有其他条件。下面是我的量角器代码:

it('Displays the small login screen', function () {
    var loadpanel = element(by.id("loadingimage"));
    var el = loadpanel;
    browser.driver.wait(protractor.until.elementIsNotVisible(el));
    smallLogin = element(by.id('loginScreen'));
    browser.wait(EC.presenceOf(smallLogin), 30000);
    expect(smallLogin.isPresent()).toBe(true);
    element(by.id('dropdown')).click();

这行不通,但它通过了。我希望隐藏加载图像,直到它可见为止,不应执行小登录条件。发生的事情是它执行了小登录条件和下拉单击,同时图像仍然可见。谢谢

您要使用的预期条件是 invisibilityOf:

var EC = protractor.ExpectedConditions;

// select a radiobutton 

var loadpanel = element(by.id("loadingimage"));
browser.wait(EC.invisibilityOf(loadpanel), 5000);

var smallLogin = element(by.id('loginScreen'));
expect(browser.isElementPresent(smallLogin)).toBe(true);

element(by.id('dropdown')).click();

此外,在类似的情况下,在测试内部 Angular 应用程序时,我记得还必须在测试前将 ignoreSynchronization 设置为 true 并将其设置为 false 之后为了捕捉应用程序的 "loading" 状态。