2013-04-09 11 views
8

Sto provando a eseguire i casi di test qunit con PhantomJS. Uno dei miei test è sospeso quando phantomJS tenta di accedere alla funzione navigator.geolocation del DOM. lo stesso test funziona bene nel browser, si blocca nella console con phantomJS.PhantomJS supporta geolocalizzazioni?

doe phantomJS geolocalizzazioni di supporto? qualche suggerimento?

rotture nella seguente condizione if

if(navigator.geolocation) { 
      window.navigator.geolocation.watchPosition(updateLocation, null, { frequency: 3000 }); 
     } 

risposta

10

No.

sufficiente selezionare l'esempio features.js.

>phantomjs.exe features.js 
Detected features (using Modernizr 2.0.6): 

Supported: 
    touch 
    generatedcontent 
    fontface 
    flexbox 
    canvas 
    canvastext 
    postmessage 
    websqldatabase 
    hashchange 
    history 
    draganddrop 
    websockets 
    rgba 
    hsla 
    multiplebgs 
    backgroundsize 
    borderimage 
    borderradius 
    boxshadow 
    textshadow 
    opacity 
    cssanimations 
    csscolumns 
    cssgradients 
    cssreflections 
    csstransforms 
    csstransitions 
    localstorage 
    sessionstorage 
    webworkers 
    applicationcache 
    svg 
    inlinesvg 
    smil 
    svgclippaths 

Not supported: 
    csstransforms3d 
    webgl 
    geolocation 
    indexeddb 
    video 
    audio 
+0

Thank you very much. È stato davvero utile Riuscito a saltare la geolocalizzazione –

4

È possibile aggiungere "geolocalizzazione-finto-support" per l'esecuzione di test o di fare altre cose iniettando le funzioni necessarie nel DOM su inizializzazione. L'esempio seguente simula navigator.geolocation.getCurrentPosition, quindi quando il sito Web nel browser chiama questo endpoint API, PhantomJS restituirà sempre la posizione configurata.

webpage.onInitialized = function() { 
    webpage.injectJs('geolocation.js') 
}; 

geolocation.js:

window.navigator.geolocation = { 
    getCurrentPosition: function (success, failure) { 
     success({ 
      coords: { 
       // Will always return Germany, Rostock 
       latitude: 54.0834, 
       longitude: 12.1004 

      }, timestamp: Date.now() 
     }); 
    } 
};