由于模块导出,量角器代码失败

时间:2017-06-22 19:24:43

标签: javascript angular protractor e2e-testing

在我的Protractor框架中,我使用的是POM模型,所以很多代码都驻留在不同的.js文件中,然后在必要的交汇点调用它们进行e2e测试。

我有一个CompleteProfile.js文件(虚拟名称),我有条件,

if profile_flag ===100,
   then do nothing
else
   complete profile (includes a lot of forms)

对于else部分,我将代码放在不同的fillCustomerForms.js文件中,其代码是这样的

var completeprofile = function(){
    this.locator = element(by.css('some_css_locator'));
    this.locator.click();
    browser.sleep(2000);
}

module.exports={
    profileComplete1 = completeprofile
}

我在fillCustomerForms.js中使用CompleteProfile.js作为

 var Profile = require('./fillCustomerForms.js');
 var c_profile = new Profile.profileComplete1();

 var compl_profile = function(){

   this.someFunction= function(){
       profile_flag = "90"
       if profile_flag ==="100"{
           then do nothing;
       }else{
           c_profile.completeprofile();
      }
      }
      }

 module.exports={
      finalExp = compl_profile
     }

spec.js内,我将CompleteProfile.js称为

 var Profile = require('./CompleteProfile.js');
 var co_profile = new Profile.finalExp();

  describe("Modules",()=>{
    it('Modules that load other things',()=>{
         //do other things neccessary
      });
  });

  describe("Module",()=>{
        it("should do something,"()=>{
        co_profile.someFunction();    
  });
 });

第一个describe块是加载浏览器并检查URL和其他测试用例的块。我的问题是,如果我添加第二个describe块,那么在第一个describe块中发送的网址会呈现为空,即Chrome加载时没有任何网址,并且由于超时错误而导致错误消失。我检查了代码,看起来很好。我在这里做错了什么

我猜这可能与JS的一些基础知识有关,我可能忽略了,但是现在我无法解决这个问题。

1 个答案:

答案 0 :(得分:0)

您的第二个测试用例(it函数)中存在语法错误。 Mocha中每个测试用例的每个回调都需要解决或拒绝。例如:

it('should ...', done => { 
   /* assertion */ 
   done(/* passing a new instance of Error will reject the testcase*/); 
});`. 

被叫函数不会在提供的代码段中返回任何内容,我也不会真正看到您尝试测试的内容。