how to re-use same IT blocks in multiple spec files

33 Views Asked by At

in protractor, i have 20 tests (IT block) in a spec file.

and we have few different spec files only the difference between each spec file is before block.

Spec A Spec B Spec C

so, 20 tests from Spec A are copied into Spec B & C also.

wanted to re-use instead of copy/paste.

tried below two types but page initialisation is not happening. please suggest, if there is a way.

spec A

export const testCasesRun = (
describe('2o tests cases', () => {

  before(async () => {


   }

   it(test case 1, async () => {}
   it(test case 2, async () => {}

} // describe
} // export 
```

Spec B:
```
describe('2o tests cases', () => {

  before(async () => {


   }
 testCasesRun(); // calling the tests from SPEC A
}

the problem with this approach is, the page initialisation is not happening when testCasesRun is being called.

any solution available? please suggest.

1

There are 1 best solutions below

0
L V Prasad On

by re initialising driver in both specs it started working.