0

I have a simple test that my Dev colleagues would like to run repeatedly - they have experienced issues where a page loads, then refuses to render correctly.

Here is the code of the test:

describe('DBM Tags', function() {
    it('clears prefill basket', function() {

var startTime;

        browser.get('https://gxptag.guestline.net/qa/');
       // browser.driver.manage().window().maximize();



       browser.ignoreSynchronization = true,

            browser.sleep(3000);

                    expect(browser.getTitle()).toEqual('DBM QA Tag Tester');
            browser.sleep(500);

//timer start

browser.controlFlow().execute(function() {
    startTime = new Date().getTime();
});

//Clicks on basket prefill to load Hotel1   
    element(by.xpath("/html/body/div[1]/div[1]/button[6]")).click();
    browser.switchTo().frame(element(by.tagName('iframe')).getWebElement()); 
    browser.sleep(500);
var EC = protractor.ExpectedConditions;
var e = element(by.xpath ('/html/body/div[1]/div[2]/div/div[2]/div/div[2]/div[2]/div/div[1]/div/span'));
browser.wait(EC.presenceOf(e),5000);

//timer stop
    browser.controlFlow().execute(function() {
var endTime = new Date().getTime();
var elapsedTime = endTime - startTime;
    console.log('Elapsed Time Basket Prefill modal = ' + elapsedTime + 'ms');

});

    browser.switchTo().defaultContent(); 

//verifies there is a value
            browser.switchTo().frame(element(by.tagName('iframe')).getWebElement());
var value1 = element(by.xpath('/html/body/div[1]/div[2]/div/div[2]/div/div[2]/div[2]/div/div[2]/div/div/div/div[2]/div/div[1]/span/span'));
    expect(value1.getText()).toEqual('£440.00');
        browser.sleep(1000);

//closes modal
            browser.switchTo().defaultContent(); 
    element(by.xpath('//*[@id="dbm-close-btn"]')).click();
        browser.sleep(500);


//clicks on Hotel1
    element(by.xpath('/html/body/div[1]/div[1]/button[3]')).click();
        browser.sleep(3000);

//clears room
            browser.switchTo().frame(element(by.tagName('iframe')).getWebElement());
        browser.sleep(3000);    
    element(by.deepCss('.removeBooking > svg:nth-child(1)')).click();
        browser.sleep(1000);
            browser.switchTo().defaultContent();        
    element (by.xpath('//*[@id="dbm-close-btn"]')).click();  
        browser.sleep(1000);    




        });
    });

What I want to do is loop this code x times...in the old VB parlance

for x = 1 to 100,

//code here

next x

I appreciate we need to consider promises but any other advice would be greatly appreciated.

Thanks

David Redmayne
  • 232
  • 1
  • 5
  • 13

2 Answers2

1

I didn't have time to test it, so there might be errors here and there but use it as an approach

make your spec like so

let j = Number(process.env.RERUN) || 1;
for (let i = 0; i < j; i++) {
    describe("Suite", () => {
        it('1', async () => {
            // your test case
        });
    });
}

and start the protractor with this command

RERUN=100 protractor protractor.conf.js

P.S.

this approach can be used as well https://moduscreate.com/blog/protractor_parameters_adding_flexibility_automation_tests/ this way, you'd need to change one line in the spec

let j = Number(browser.params.rerun) || 1;

and start your protractor so

protractor conf.js --parameters.rerun=100
Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
  • Thanks @Sergey Pleshakov. This is looking promising. However when I run the command `RERUN=100` etc I get an error message: `'RERUN' is not recognized as an internal or external command, operable program or batch file.` Is thre an NPM module I need to load or maybe the test command needs to be inserted into package.json? Thanks – David Redmayne Mar 16 '20 at 16:13
  • 1
    hm, you shouldn't need any package. 1. This is a command to start node process with env variable on Mac, https://medium.com/the-node-js-collection/making-your-node-js-work-everywhere-with-environment-variables-2da8cdf6e786 maybe it's different for your OS. 2. make sure you don't have spaces around `=` – Sergey Pleshakov Mar 16 '20 at 20:29
  • 1. I'm running Win10. 2. Yes checked no space. Still same error. Did you make any changes to your conf.js file? Thanks. – David Redmayne Mar 17 '20 at 11:42
  • 1
    no, this functionality is not a part of protractor. it's node feature. check the most upvoted comment under this answer, https://stackoverflow.com/a/22312793/9150146, maybe it will help. Meanwhile, I'll update the answer with another approach shortly – Sergey Pleshakov Mar 17 '20 at 14:46
  • Thanks Sergey...most kind. – David Redmayne Mar 17 '20 at 15:36
  • 1
    did that solve the problem? if so could you accept the answer – Sergey Pleshakov Mar 17 '20 at 15:43
  • Sadly not Sergey! `W/runner - Ignoring unknown extra flags: parameters. This will be an error in future versions, please use --disableChecks flag to disable the Protractor CLI flag checks.` I added the disableChecks entry but this just ignores the parameters entry! – David Redmayne Mar 18 '20 at 11:35
  • Got it!! Added a params value in in the config.js file called 'rerun' with a value and using Sergey's addition. Just run the test in the normal way. – David Redmayne Mar 18 '20 at 12:08
  • probably you'd need to run the command a bit defferent, somwthing like `export VARIABLE=value protractor protractor.config.js` – Sergey Pleshakov Mar 26 '20 at 14:15
0

So to sum up!

Add this to the spec:

let j = Number(browser.params.rerun) || 1;
for (let i = 0; i < j; i++) {
describe("Suite", () => {
    it('1', async () => {
   });
 });
}

THEN to the config.js file in the 'exports' section add:

  params: {
  rerun: 5
},     

..then start the test with

Protractor config.js

the test will run 5 times.

Thanks to @Sergey Pleshakov

David Redmayne
  • 232
  • 1
  • 5
  • 13