2017-10-11 31 views
0

我打電話給計算器方法來調用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) 
+0

如果刪除什麼做參數?當你聲明done參數時,你必須在測試完成後調用它。 –

回答

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); 
}); 
+0

我試過這種方式,但它不起作用 – danio900409

+0

我看到'email()'不需要回調。你必須修改'email'才能進行回調,並在'email'結尾處調用它。 – user835611

+0

你能指導我如何做到這一點? – danio900409