0
votes

I call the calculator method to call the email () method but the elements do not complement the page and after a fairly long wait time throw out the timeout. Does anyone know how I can get around this? This is quite a hassle. I tried with the done () method, but it did not come out and I still got this message.

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

My log:

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
What if you remove the done parameter? When you declare the done parameter you have to call it after the test is done. - Tamas Hegedus

1 Answers

0
votes

done has to be called for the test to finish. So either

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

or, if page.email() takes a callback

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