简体   繁体   中英

Sharing test cases between specs in protractor

Right now I have a set of specs that are shared between two different specs in protractor.

What i have done is to write all the test cases inside a pageobject and then call that function from the suite.

Eg: PageObject

var testing_helper = function(){


this.functu = function(a,b){
//test case one . without using "it" functions.
//test case two
//testcase three.
...... 
}

the suite.js file looks like

var x = require('./testing_helper');
describe('description' function(){

  if(some condition){
   it('description', function(){
     x.functu(a,b);
   });
   }

});

This runs the test fine but there is no description or separate test cases in the generated report. The report file only shows one test instead of all three.

<testsuites disabled="0" errors="0" failures="0" tests="1" time="121.175">
 <testsuite name="This is rbac" timestamp="2018-07-09T14:59:41" hostname="localhost" time="121.175" errors="0" tests="1" skipped="0" disabled="0" failures="0">
  <testcase classname="This is rbac" name="runs the rbac off user" time="121.174" />
 </testsuite>
</testsuites>

I know this is not the right way to do this and it makes it impossible to give descriptions to each functions in the end report.

Is there a way to properly define the "it" specs for spec one, spec two and spec three and then use them in a suite and run them based on conditions?

I think it should be organized like -

var testing_helper = function(){       
add = function(a,b){
....
}    
subtract = function(a,b){
....
}    
}

Then, defining your test suites -

var x = require('./testing_helper');
describe('description' function(){  
   it('description', function(){
      if(some condition){
        x.add(a,b);
      }
   });

   it('description', function(){
      if(some condition){
        x.subtract(a,b);
      }
   });  

});

Does that make sense or any limitations if you find?

What I mean is, let's say you have login function which is to be used across many specs. You can have it there in helper and call it here in any number of specs you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM