2017-06-15 3 views
0

Ich habe nightwatch.js verwendet, um e2e Testfälle für mein Produkt zu automatisieren. Es funktionierte sehr gut auf Chrome, Firefox und anderen UI-basierten Browsern. Allerdings muss ich es auf phantom.js ausführen, um es Teil von Jenkins als Headless-Browser für die Automatisierung zu betreiben.nightwatch.js funktioniert nicht für phantom.js

Ich habe versucht, aber Testskript funktioniert nicht mit phantom.js.

Testskript:

describe('TEST PHANTOMJS#',function() { 

    afterEach((client,done) => { 
    client.end(() => done()); 
    }); 

    it('successful test google.com',(client)=> { 

    // Launch google.com 
    client.url('https://www.google.com').resizeWindow(1000,800); 
    console.log('Launched Google') 
    client.expect.element('body1').to.be.present.before(1000); // test error 
    console.log('Completed testing') 
    }); 
}); 

Meine nightwatch.json Konfiguration:

{ 
    "src_folders": [ 
    "tests" 
    ], 
    "output_folder": "reports", 
    "custom_commands_path": "", 
    "custom_assertions_path": "", 
    "page_objects_path": "", 
    "selenium": { 
    "start_process": true, 
    "server_path": "./bin/selenium/selenium-server-standalone-3.0.1.jar", 
    "log_path": "", 
    "port": 4444, 
    "cli_args": { 
     "webdriver.chrome.driver": "./bin/chrome/chromedriver", 
     "webdriver.gecko.driver": "./bin/firefox/geckodriver", 
     "webdriver.edge.driver": "./bin/ie/IEDriverServer.exe" 
    } 
    }, 
    "test_settings": { 
    "default": { 
     "selenium_port": 4444, 
     "selenium_host": "localhost", 
     "default_path_prefix": "/wd/hub", 
     "silent": true, 
     "screenshots": { 
     "enabled": true, 
     "on_failure": true, 
     "path": "./screen-shots" 
     }, 
     "desiredCapabilities": { 
     "browserName": "phantomjs", 
     "javascriptEnabled": true, 
     "acceptSslCerts": true, 
     "phantomjs.binary.path": "./node_modules/phantomjs-prebuilt/bin/phantomjs", 
     "phantomjs.page.settings.userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36", 
     "phantomjs.cli.args": [] 
     }, 
     "test_runner": { 
     "type": "mocha", 
     "options": { 
      "ui": "bdd", 
      "reporter": "list" 
     } 
     } 
    } 
    } 
} 

Nach ./node_modules/.bin/nightwatch --env qa --verbose läuft Ich sehe folgende Protokoll

> nightwatch --env qa --verbose 

Starting selenium server... started - PID: 11037 

    TEST PHANTOMJS# successful test google.com: Launched Google 
Completed testing 
INFO Request: POST /wd/hub/session 
- data: {"desiredCapabilities":{"browserName":"phantomjs","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","phantomjs.binary.path":"./node_modules/phantomjs-prebuilt/bin/phantomjs","phantomjs.page.settings.userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36","phantomjs.cli.args":[]}} 
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":372} 
INFO Response 200 POST /wd/hub/session (1409ms) { state: null, 
    sessionId: 'd16c7439-18ec-4b67-85eb-e3dda6fe0075', 
    hCode: 1253002783, 
    value: 
    { applicationCacheEnabled: false, 
    rotatable: false, 
    handlesAlerts: false, 
    databaseEnabled: false, 
    version: '2.1.1', 
    platform: 'MAC', 
    browserConnectionEnabled: false, 
    proxy: { proxyType: 'direct' }, 
    nativeEvents: true, 
    acceptSslCerts: false, 
    driverVersion: '1.2.0', 
    'webdriver.remote.sessionid': 'd16c7439-18ec-4b67-85eb-e3dda6fe0075', 
    'phantomjs.page.settings.userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36', 
    locationContextEnabled: false, 
    webStorageEnabled: false, 
    browserName: 'phantomjs', 
    takesScreenshot: true, 
    driverName: 'ghostdriver', 
    javascriptEnabled: true, 
    cssSelectorsEnabled: true }, 
    class: 'org.openqa.selenium.remote.Response', 
    status: 0 } 
INFO Got sessionId from selenium d16c7439-18ec-4b67-85eb-e3dda6fe0075 
INFO Request: POST /wd/hub/session/d16c7439-18ec-4b67-85eb-e3dda6fe0075/url 
- data: {"url":"https://www.google.com"} 
- headers: {"Content-Type":"application/json; charset=utf-8","Content-Length":32} 

Idealerweise sollte es die Prüfung mit der Berichterstattung vervollständigen ein Fehler. Es blieb jedoch stecken und bewegt sich nicht weiter.

Jede Hilfe wäre willkommen.

+0

So seltsam, es nicht wegen Proxy-Ausgabe arbeitet :-(Nun, um herauszufinden, wie Proxy für Phantom js setzen – joy

Antwort

0

Wenn Sie PhantomJS auf einer Website mit HTTPS, Sie haben in der Regel das Skript mit der ignore-ssl-errors Option ausführen. Andernfalls geraten Sie oft in Schwierigkeiten ... Wenn Ihr Skript mit allen grafischen Browsern funktioniert, aber nicht mit PhantomJS, ist Ihr Problem wahrscheinlich auf SSL/TLS zurückzuführen.

In nightwatch.json, wo Sie PhantomJS konfigurieren, stellen Sie sicher, dass die CLI-Option hinzuzufügen:

"phantomjs.cli.args": ["--ignore-ssl-errors=true"] 

Das folgende Skript funktioniert nicht ohne die Option (es ist nicht der Titel der Seite nicht gedruckt werden), aber es funktioniert, wenn Sie es hinzufügen.

module.exports = { 
    'PhantomJS': function(browser) { 
    browser 
     .url('https://www.google.com') 
     .waitForElementVisible('body', 1000) 
     .getTitle(function (title) { 
     console.log(title); 
     }) 
     .end(); 
    } 
}; 
+0

wie ich vermuten, dies ist ein Proxy-Problem war, habe ich "proxy": { "proxyType": "manuell", "httpProxy": "http://proxy.mycompany.com:8080/" }. Es funktioniert. Aber jetzt habe ich ein anderes Problem. Meine URL wird auf eine andere URL umgeleitet, wie unterstützt man die Umleitung mit phantomjs? – joy

Verwandte Themen