2013-01-31 62 views
4

我正在使用phantomjs來測試許多頁面,並試圖使我的代碼更清潔。是否有可能做page.open並從其他函數或模塊調用page.evaluate。 現在:phantomjs:從一些其他功能或模塊調用page.evaluate

page.open(ADDRESS, function(status) { 
      if (status == 'success') { 
       page.evaluate(function() { 
       return document.querySelector('.error'); 
       ...... do some more checks 
       }): 
       .....Run some other code 
      } 

我想這樣做:

file check.js : exports.check = function() { 
       page.evaluate(function() { 
       return document.querySelector('.error'); 
       ...... do some more checks 
       }): 

而在main.js或其他文件,我只是叫check.js的這個功能做檢查。 這可能需要通過引用調用此函數,但不知道如何執行此操作。如果這可以完成,我所有的文件大小都會減小,代碼將更具可讀性。

+0

你試了一下,發生了什麼事......? – 2013-07-29 02:43:49

回答