如何解决测试打字稿中的超时问题

时间:2017-10-11 10:06:01

标签: angularjs node.js typescript selenium-webdriver protractor

我调用计算器方法来调用email()方法,但元素不会补充页面,并且在相当长的等待时间之后抛出超时。有谁知道我怎么能解决这个问题?这非常麻烦。我尝试使用done()方法,但它没有出来,我仍然收到了这条消息。

app.e2e-spec.ts

import { Page } from './app.po';
import { Key, promise, browser, element, by } from 'protractor';

describe('App', () => {
  let page: Page;

  beforeEach(() => {
    page = new Page();
  });

  it('should show start page', () => {
    page.navigateTo();
    page.calculator();
  });

  it('address section', function(done){
    browser.sleep(8000);
    page.email(); 
  });
});

app.po.ts

calculator(){
    var amount = element(by.xpath(".//*[@id='amount-slider-value']"));
    amount.sendKeys(protractor.Key.chord(protractor.Key.CONTROL, "a"));
    var amountOfLoan =  Math.floor(Math.random() * 2500)+500;
    element(by.xpath(".//*[@id='amount-slider-value']")).sendKeys(amountOfLoan);
    browser.sleep(3000);
    var day = element(by.xpath(".//*[@id='period-slider-value']"));
    day.sendKeys(protractor.Key.chord(protractor.Key.CONTROL,"a"));
    var loanDays = Math.floor(Math.random() * 30) + 1;
    element(by.xpath(".//*[@id='period-slider-value']")).sendKeys(loanDays);
    browser.sleep(3000);
    element(by.xpath(".//*[@id='agreemenet-container']")).click();
    element(by.xpath('//div/div[2]/div[3]/div/div[2]/div[2]/button')).click();
    browser.sleep(3000);
  }

  email(){
    var email = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 8);
    var emailField = email + "@test.com";
    element(by.xpath('//section/form/div[1]/main/dynamic-form/form/div[1]/div[2]/div[1]/div/email-field/input')).clear();
    browser.sleep(2000);
    element(by.xpath('//section/form/div[1]/main/dynamic-form/form/div[1]/div[2]/div[1]/div/email-field/input')).sendKeys(emailField);
  }

我的日志:

A Jasmine spec timed out. Resetting the WebDriver Control Flow.
A Jasmine spec timed out. Resetting the WebDriver Control Flow.
    × address section
      - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
          at ontimeout (timers.js:386:11)
          at tryOnTimeout (timers.js:250:5)
      - Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
          at ontimeout (timers.js:386:11)
          at tryOnTimeout (timers.js:250:5)

1 个答案:

答案 0 :(得分:0)

必须要求

done才能完成测试。所以要么

it('address section', function(done){
    browser.sleep(8000);
    page.email(); 
    done();
});

或者,如果page.email()接受回调

it('address section', function(done){
   browser.sleep(8000);
   page.email(done); 
});