2014-01-11 25 views
2

我有以下測試,運行良好時,我運行它們在本地和醬(至少大部分時間)使用Firefox和鉻。使用醬和量角器來測試Internet Explorer和safari

ptor = protractor.getInstance(); 

baseUrl = protractor.getInstance().params.sBaseUrl; 
aRequiredTextFieldsKeys = [ 
'sFirstName', 
'sLastName', 
'sStreet', 
'sZip', 
'sCity' 
]; 


describe('form', function() 
{ 
var sFormUrl = baseUrl + '#/form'; 

beforeEach(function() 
{ 
    ptor.get(sFormUrl); 
}); 


describe('wholeForm', function() 
{ 

    it('fully filled form => required fields have correct class && submit leads to other route', function() 
    { 

     function checkRequiredClass(el) 
     { 
      expect(el.getAttribute('class')).toContain('ng-valid-required'); 
     } 

     // requried text-fields 
     for (var i = 0; i < aRequiredTextFieldsKeys.length; i++) { 
      var el = element(by.model('oFormData.' + aRequiredTextFieldsKeys[i])); 
      el.sendKeys('a'); 
      checkRequiredClass(el); 
     } 

     // email 
     var elEmail = element(by.model('oFormData.sEmail')); 
     elEmail.sendKeys('[email protected]'); 
     checkRequiredClass(el); 

     // birthday 
     var elBirthday = element(by.model('oFormData.oBirthday')); 
     elBirthday.sendKeys('1.1.1995'); 
     checkRequiredClass(el); 

     // checkboxes 
     var elCheck1 = element(by.model('oFormData.bAgb')); 
     elCheck1.click(); 
     checkRequiredClass(elCheck1); 

     var elCheck2 = element(by.model('oFormData.bPrivatePolicy')); 
     elCheck2.click(); 
     checkRequiredClass(elCheck2); 
     // hack upload bon 
     ptor.executeScript(function() 
     { 
      var scope = $('#application-form-id').scope(); 
      scope.oFormData.bBonUploaded = true; 
     }); 

     // submit form 
     element(by.className('btn-submit')).click(); 

     ptor.getCurrentUrl() 
      .then(function (url) 
      { 
       expect(url).toNotBe(sFormUrl); 
      }); 
    }); 
}); 

但是,當我啓動Internet Explorer或Safari瀏覽器時,出現各種錯誤,而頁面在手動測試時工作正常。對於IE我得到:

Message: UnknownError: JavaScript error (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 97 milliseconds Build info: version: '2.30.0', revision: 'dc1ef9c', time: '2013-02-19 00:15:27' System info: os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_35' Session ID: 42b30348-8598-4edb-923e-a7019ced6eb0 Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{platform=WINDOWS, elementScrollBehavior=0, javascriptEnabled=true, enablePersistentHover=true, ignoreZoomSetting=false, browserName=internet explorer, enableElementCacheCleanup=true, unexpectedAlertBehaviour=dismiss, version=10, cssSelectorsEnabled=true, ignoreProtectedModeSettings=false, requireWindowFocus=false, allowAsynchronousJavaScript=false, handlesAlerts=true, initialBrowserUrl=, nativeEvents=true, takesScreenshot=true}]

Error: Error while waiting for Protractor to sync with the page: {"stack":"TypeError: Unable to get property 'get' of undefined or null reference\n at Anonymous function (Unknown script code:25:5)\n at Anonymous function (Unknown script code:21:14)\n at Anonymous function (Unknown script code:21:2)","description":"Unable to get property 'get' of undefined or null reference","number":-2146823281}

而對於Safari瀏覽器:

UnknownError: Detected a page unload event; script execution does not work across page loads. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 384 milliseconds Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:38' System info: os.name: 'Windows Server 2008 R2', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_35' Session ID: null Driver info: org.openqa.selenium.safari.SafariDriver Capabilities [{platform=WINDOWS, javascriptEnabled=true, cssSelectorsEnabled=true, secureSsl=true, browserName=safari, takesScreenshot=true, version=5.1.7}]

我confsued有關的原因。我嘗試了更簡單的測試,結果相同,我嘗試了本地和遠程網址,並嘗試了各種延遲,如waitForAngularwaitptor ignoreAsynch = true。他們都沒有達到預期的結果。有什麼建議麼?

我量角器配置文件:

// A reference configuration file. 
    exports.config = { 

     seleniumServerJar: null, 
     seleniumPort: null, 
     chromeOnly: false, 
     // Additional command line options to pass to selenium. For example, 
     // if you need to change the browser timeout, use 
     // seleniumArgs: ['-browserTimeout=60'], 
     seleniumArgs: [], 
     sauceUser: 'saucesuer', 
     sauceKey: 'key', 
     allScriptsTimeout: 120000, 
     specs: [ 
      'test/e2e/**/*.js', 
     ], 

     // https://code.google.com/p/selenium/wiki/DesiredCapabilities 
     // https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js 
     capabilities: { 
      'browserName': 'phantomjs', 
      'phantomjs.binary.path':'node_modules/phantomjs/bin/phantomjs' 
     }, 


     // Selector for the element housing the angular app - this defaults to 
     // body, but is necessary if ng-app is on a descendant of <body> 
     rootElement: 'body', 

     onPrepare: function() 
     { 
    //  driver.manage().timeouts().setScriptTimeout(60000); 
     }, 

     params: { 
      sBaseUrl: 'https://dev.com/' 

     }, 
     baseUrl: 'http://localhost:8000', 

     framework: 'jasmine', 

     // ----- Options to be passed to minijasminenode ----- 
     // 
     // See the full list at https://github.com/juliemr/minijasminenode 
     jasmineNodeOpts: { 
      // onComplete will be called just before the driver quits. 
      onComplete: null, 
      // If true, display spec names. 
      isVerbose: true, 
      // If true, print colors to the terminal. 
      showColors: true, 
      // If true, include stack traces in failures. 
      includeStackTrace: true, 
      // Default time to wait in ms before a test fails. 
      defaultTimeoutInterval: 120000 
     } 
    }; 

雖然它似乎沒有關係,我用咕嚕,量角器選手按順序運行多個實例。

  chrome: { 
      options: { 
       args: { 
        browser: 'chrome', 
        "idle-timeout": 120 
       } 
      } 
     }, 
     firefox: { 
      options: { 
       args: { 
        browser: 'firefox' 
       } 
      } 
     }, 
     ie9: { 
      options: { 
       args: { 
        browser: 'internet explorer', 
        version: '9', 
        "idle-timeout": 120 
       } 
      } 
     }, 
     ie10: { 
      options: { 
       args: { 
        browser: 'internet explorer', 
        version: '10' 
       } 
      } 
     }, 
     safari7: { 
      options: { 
       args: { 
        browser: 'safari', 
        version: '7' 
       } 
      } 
     }, 
     safari6: { 
      options: { 
       args: { 
        browser: 'safari', 
        version: '6' 
       } 
      } 
     }, 
     safari5: { 
      options: { 
       args: { 
        browser: 'safari', 
        version: '5' 
       } 
      } 
     } 
    } 

grunt.registerTask('e2eall', [ 
    'protractor:ie9', 
    'protractor:ie10', 
    'protractor:safari5', 
    'protractor:safari6', 
    'protractor:safari7', 
    'protractor:firefox', 
    'protractor:chrome' 
]); 

回答

4
雨果

, 這與某些測試配置一個問題,即部分地在量角器0.17解決,在0.18更明確地得到解決。我會建議更新您的量角器到最新版本(0.18.1在這篇文章的時間),並看看是否可以解決您的問題。

相關的changelog條目:

v0.18

(10aec0f) fix(pageload): increase wait timeout

The 300 ms wait caused problems when testing IE on Sauce Labs. It seems way too short. "browser.get()" invariably timed out. Increasing it solved our problem.

v0.17

(a0bd84b) fix(pageload): add a wait during protractor.get() to solve unload issues

Some systems would not wait for the browser unload event to finish before beginning the asynchronous script execution.

Closes #406. Closes #85.

希望幫助!