2017-02-08 36 views
0

我已經寫了一個文件,其中包含許多我希望用於各種E2E測試的函數。我一直在試圖測試,並找到了一些解決方案,但沒有爲我工作。在量角器中從一個文件讀到另一個文件JS

這是事情的立場。

在我TestingFunc.js文件我已經創建了以下內容:

var TestingFunc = function() { 

this.login = function(Url) { 
      browser.ignoreSynchronization = true; 
      browser.get(Url); 


      browser.wait(EC.elementToBeClickable(element(by.eeHook('login',null,null))), 300000); 
      element(by.eeHook('login', null, null)).click();  
      element(by.eeHook('authenticationEmailField',null,null)).sendKeys(logins.International); 

      element(by.name('password')).sendKeys(logins.password); 
      element(by.eeHook('authenticationLoginButton',null,null)).click(); 

      browser.wait(EC.elementToBeClickable(paymentFlow), 100000); 

      paymentFlow.click(); 
      browser.wait(EC.elementToBeClickable(depositAmount), 7000); 

     }; 
}; 

,我試圖在下面來閱讀:

var url = 'http://master.mrgreen.avengers.zone/en-US/casino'; 
var TestingFunc = require("C:/Users/davbor.3DB/MrGreen Google Drive/LetsTest/TestingFunc.js"); 

describe("The security application", function() { 


var test = new TestingFunc(); 

it("will login to the page", function() { 
    test.login(url); 
}); 

});

但每次我運行它的時候我不斷收到錯誤:

Failures: 
1) The security application encountered a declaration exception 
    Message: 
    TypeError: TestingFunc is not a constructor 
    Stack: 
    TypeError: TestingFunc is not a constructor 
     at Suite.<anonymous> (C:\Users\davbor.3DB\MrGreen Google Drive\LetsTest\Testing.js:6:17) 

不知道我很想念我甚至要求在房子開發商來看待它沒有成功。

+1

你導出了你的'TestingFunc'嗎? 'module.exports = TestingFunc' – casraf

+0

是啊,它已經寫出口,而不是出口,現在它看起來工作得很好,謝謝你的幫助:) –

回答

3

var TestingFunc = require("C:/Users/davbor.3DB/MrGreen Google Drive/LetsTest/TestingFunc.js");

1)您不應該使用完整路徑。使用該文件的相對路徑。

在你Testing.js要求應該是這樣的:

var TestingFunc = require("./TestingFunc.js"); 

2),你應該 '出口' 你的函數:

var TestingFunc = function() { 

this.login = function(Url) { 
     browser.ignoreSynchronization = true; 
     browser.get(Url); 


     browser.wait(EC.elementToBeClickable(element(by.eeHook('login',null,null))), 300000); 
     element(by.eeHook('login', null, null)).click();  
     element(by.eeHook('authenticationEmailField',null,null)).sendKeys(logins.International); 

     element(by.name('password')).sendKeys(logins.password); 
     element(by.eeHook('authenticationLoginButton',null,null)).click(); 

     browser.wait(EC.elementToBeClickable(paymentFlow), 100000); 

     paymentFlow.click(); 
     browser.wait(EC.elementToBeClickable(depositAmount), 7000); 

    }; 
}; 
module.exports = TestingFunc; 

檢查更多關於模塊的NodeJS這裏: https://nodejs.org/api/modules.html

+0

不幸的是,即使在出口,我仍然遇到同樣的錯誤。 –

+0

修復工作!我注意到,在閱讀建議的api時,出口不是出口。非常感謝你的幫助!你真的是我的一天! :) –

相關問題