如何使用量角器创建帮助程序以在测试运行之前登录



在我的测试中,我有

var LoginHelper = require('../helpers/functional/login.js')
describe('Passport Navigation', function() {
  beforeAll(function() {
    return LoginHelper()
  })
  it('should properly load the All Skills view', function() {
    browser.get('https://example.com/ng-app/profile')
    element(by.model('myModel')).sendKeys('test stuff')
    element(by.css('btn')).click()
    expect(myModel()).toEqual('more')
  })
})

我的帮手是:

module.exports = function() {
  browser.ignoreSynchronization = false
  browser.driver.get('https://example.com/ng-app')

  browser.driver.findElement(by.id('username')).sendKeys("myusername");
  browser.driver.findElement(by.id('password')).sendKeys("mypassword");
  return browser.driver.findElement(by.tagName('input')).click()
}

问题是我的网站登录不是一个有角度的网站,发生的事情是(据我所知(,它加载登录页面,输入用户名/密码,然后退出并显示错误

1) Passport Navigation should properly load the All Skills view
  Message:
    Failed: Angular could not be found on the page https://example.com/ng-app/profile.If this is not an Angular application, you may need to turn off waiting fo
r Angular.
                              Please see
                              https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load
  Stack:
    Error: Angular could not be found on the page https://example.com/ng-app/profile.If this is not an Angular application, you may need to turn off waiting for
 Angular.

browser.ignoreSync = false,告诉量角器等待 Angular。如果站点登录不是角度的,则应将其设置为 true。

browser.ignoreSynchronization = true;

量角器网站的示例

browser.ignoreSynchronization = true;
browser.get('/non-angular-login-page.html');
element(by.id('username')).sendKeys('Jane');
element(by.id('password')).sendKeys('1234');
element(by.id('clickme')).click();
browser.ignoreSynchronization = false;
browser.get('/page-containing-angular.html');

最新更新