Nightwatch.js将无法获取服务器操作系统上的URL

时间:2015-12-18 16:26:21

标签: node.js selenium-webdriver nightwatch.js

我的测试在我的机器上工作正常,但是当我尝试将其移动到服务器操作系统(特别是Windows Server 2008)时,我遇到了问题。所有测试真正需要做的是从文件中加载每个URL。当我在服务器操作系统上运行它时,它只加载一个空白页面。但我知道它正在读取文件,因为我可以在console.log中输出URL列表,如果我的文件有5行,则会说5次测试失败。

我试过的一个不同的测试,它不是从文件中读取的,顺便给出了一些可以读取的URL的数组,顺便说一下

知道发生了什么事吗?这是我的代码:

var fs = require('fs');
var i = 0;
var errorlog = "";


module.exports = {

    'Person Page Test w/ txt file' : function (browser) {
        //iterates through excel sheet testing each URL
            fs.readFileSync('PersonPageUrls.txt').toString().split('\n').forEach(function (line) { 

                var url = line;
                i++;
                console.log(url);
                browser
                    .url(url)
                    .saveScreenshot('tests/PersonPage/screenshots/PersonPage' + i + '.png')
                    .waitForElementVisible('button[class=Person__readMoreButton___28toI]', 3000, false, function(result) {
                        if (!result.value) {
                            //if test fails, add to error log string
                            browser.url(function(currentUrl){
                                console.log();
                                errorlog = errorlog + "Test fail on: " + currentUrl.value + "\r\n";
                            }); 
                        }
                    });

            });
    browser.end()
    }       
};

和我的nightwatch.json

{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",



"selenium" : {
  "start_process" : true,
  "server_path" : "selenium-server-standalone-2.48.2.jar",
  "log_path" : "",
  "host" : "127.0.0.1",
  "port" : 4444,
  "cli_args" : {
    "webdriver.chrome.driver" : "",
    "webdriver.ie.driver" : ""
  }
},

"test_settings" : {
  "default" : {
    "launch_url" : "http://localhost",
    "selenium_port"  : 4444,
    "selenium_host"  : "localhost",
    "silent": true,
    "screenshots" : {
      "enabled" : true,
      "on_failure" : true,
      "on_error" : true,
      "on_success" : true,
      "path" : ""
    },
    "desiredCapabilities": {
      "browserName": "firefox",
      "javascriptEnabled": true,
      "acceptSslCerts": true
    }
  },

  "chrome" : {
    "desiredCapabilities": {
      "browserName": "firefox",
      "javascriptEnabled": true,
      "acceptSslCerts": true
    }
  }
}

}

继承我获得的输出(在2行文本文件上运行)(如果不是很明显,我用~~~~替换它打印的真实URL。但是它会打印网址):

D:\NightwatchProjects>nightwatch -t tests/PersonPage/personpagetxt.js
Starting selenium server... started - PID:  3004

[Person Page\personpagetxt] Test Suite
======================================

Running:  Person Page Test w/ txt file
~~my url 1 ~~
~~my url 2~~
 ? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds.  - expected "visible" but got: not fo
und
    at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
    at Array.forEach (native)
    at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
    at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
    at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
    at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
    at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
    at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)

 ? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds.  - expected "visible" but got: not fo
und
    at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
    at Array.forEach (native)
    at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
    at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
    at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
    at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
    at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
    at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)


FAILED:  2 assertions failed (11.389s)
Test fail on: about:blank
Test fail on: about:blank


----------------------------------------------------
TEST FAILURE: 2 assertions failed, 0 passed (11.53s)
 ? PersonPage\personpagetxt
   - Person Page Test w/ txt file
     Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"
     Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"


D:\NightwatchProjects>

0 个答案:

没有答案