angular protractor loop over it('some test') tests

Viewed 111

I have racked my brain and scoured the internet for a way to make a protractor e2e test code synchronous to no avail! What I wish to achieve is to repeat the same protractor test indefinitely until I close the browser or end the tests or to end it via ^(control)c on the command line. Here is an example of what I am trying to do:

import { AppPage } from './app.po';
import { browser } from 'protractor';
import { interval } from 'rxjs';
import { takeWhile, switchMap } from 'rxjs/operators';
describe('workspace-project App', () => {
    let page: AppPage;
    let testComplete = false;

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

    while (true) { // Doesn't work 
        it('should display welcome message', () => {
            page.navigateTo();
            expect(page.getParagraphText()).toEqual('Welcome to testAngular6!');
            console.log('Executing tests');
            browser.wait(function () { return true; }, 5000);
        });
    }

});

but the while loop around the 'it' test does not work and keeps looping around. I realise that I cannot use any of the protractor/ web-driver wait commands or even the rjx interval APIs to achieve this because this is purely a JavaScript problem. Since JavaScript is single threaded. How could I possibly achieve this please? There are a lot of questions on the internet about this but some have no answers and others are at best similar but not quite the same! Thanks very much in advance for your help.

1 Answers

I found an interesting article

What you need to do is wrap your it block inside a function, which you can then call from inside a loop

Example:

describe('this is my looping test!', function() {
  var input = [1,2,3];
  var output = [10, 20, 30];

  function test_my_times_ten(input, output) {
    it('should multiply ' + input + ' by 10 to give ' + output, function() {
      expect(input * 10).toEqual(output)
    });
  }

  for(var x = 0; x < input.size; x++) {
    test_my_times_ten(input[x], output[x]);
  }
});

I hope this helps

Related