简体   繁体   English

量角器不等待重定向

[英]Protractor doesn't wait for redirect

I've got protractor's code written with Jasmine that is supposed to log in the user. 我已经用Jasmine编写了量角器的代码,该代码应该可以登录用户。 Unfortunately there's a redirect going on after going to root url that takes quite some time (about 5 seconds) and I cannot make protractor wait for it. 不幸的是,在转到根url之后需要进行一段时间的重定向(大约5秒钟),我无法让量角器等待它。 I've already tried browser.wait , I've tried using promises, I've tried with this blogpost , but nothing did it. 我已经尝试过browser.wait ,我已经尝试过使用Promise,我已经尝试过此Blogpost ,但是没有做任何事情。 It still doesn't wait. 它仍然没有等待。 The login page is a page from Keycloak server, that's why I use driver.findElement instead of element . 登录页面是Keycloak服务器上的页面,这就是为什么我使用driver.findElement而不是element Here's my current code: 这是我当前的代码:

describe('my app', function() {
  it('login', function() {
    var driver = browser.driver;
    browser.get('/');
    console.log('get');
    driver.findElement(by.id('username')).isPresent().then(function() {
      console.log('waited');
      driver.findElement(by.id('username')).sendKeys("test");
      driver.findElement(by.id('password')).sendKeys("test");
      driver.findElement(by.id('kc-login')).click();
      driver.findElement(by.css('.page-header')).isPresent().then(function() {
        console.log('ok');
        expect(browser.getLocationAbsUrl()).toMatch("/test");
      });
    });
  });
});

Do you know what can I do to make it work? 你知道我该怎么做才能使它工作吗? I've started protractor project with this seed: https://github.com/angular/angular-seed 我已经使用此种子开始量角器项目: https : //github.com/angular/angular-seed

You need to turn the synchronization off : 您需要关闭同步

var EC = protractor.ExpectedConditions;

describe('my app', function() {

  beforeEach(function () {
      browser.ignoreSynchronization = true;
      browser.get('/');
  });

  it('login', function() {
    var username = element(by.id('username'));
    browser.wait(EC.visibilityOf(username), 10000);

    username.sendKeys("test");
    element(by.id('password')).sendKeys("test");
    element(by.id('kc-login')).click();

    var header = element(by.css('.page-header'));

    browser.wait(EC.visibilityOf(header), 10000).then(function () {
        console.log('logged in');
    });
  });
});

Note that I've also updated the test: switched back to element and browser , added browser.wait() with built-in Expected Conditions . 请注意,我还更新了测试:切换回elementbrowser ,添加了带有内置Expected Conditions的 browser.wait()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM