本文介绍了在Mac OS上使用Nightwatchjs在Chrome中启动测试:“连接被拒绝!硒服务器启动了吗?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下命令在Firefox上运行测试:

I am able to run my tests with Firefox using the following command:

 nightwatch -t tests/test4.js   

我的nightwatchjs.json配置文件:

My nightwatchjs.json config file:

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

  "selenium" : {
    "start_process" : true,
    "server_path" : "selenium-server-standalone-2.44.0.jar",
    "log_path" : "",
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "drivers/chromedriver"
    }  
  },

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

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

但是我无法使用Chrome运行测试.这是命令:

However I can't run the tests with Chrome. Here is the command:

nightwatch -t tests/test4.js -e chrome --verbose

输出:

INFO Request: POST /wd/hub/session 
 - data:  {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","name":"Test4"}} 
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":127}
ERROR Response 500 POST /wd/hub/session{ sessionId: null,
  status: 13,
  state: 'unhandled error',
  value: 
   { message: null,
     localizedMessage: null,
     cause: null,
     class: 'java.util.concurrent.TimeoutException',
     hCode: 1023736867,
     screen: null },
  class: 'org.openqa.selenium.remote.Response',
  hCode: 31447144 }

由于某些原因,相同的主要配置选项适用于Firefox,但不适用于Chrome.有人有同样的问题吗?

For some reasons, the same main configuration options work for Firefox but do not work for Chrome. Does anybody have the same issue?

谢谢,保罗

推荐答案

Paul!)尝试在chrome"desiredCapabilities"块中使用Selenium CLI参数.并指定chromedriver二进制文件的路径.或者您可以将其添加到硒块中

Paul!) Try use selenium CLI arguments in chrome "desiredCapabilities" block. And specify path to your chromedriver binary file.or you can make it if add it in selenium block

"cli_args" : {
      "webdriver.chrome.driver" : "<path to chromedriver>"
    }   

http://nightwatchjs.org/guide#settings-file 了解更多信息.

但是我更喜欢使用bash脚本运行selenium服务器

But I prefer run selenium server using bash script something like that

#!/bin/bash
all="false"
chrome="false"
firefox="false"
phantom="false"
for var in "$@"
do
    if [ "$var" == "firefox" ];
    then
        firefox="true"
    fi
    if [ "$var" == "chrome" ];
    then
        chrome="true"
    fi
    if [ "$var" == "phantomjs" ];
    then
        phantom="true"
    fi
    if [ "$var" == "all" ];
    then
        all="true"
        firefox="true"
        chrome="true"
        phantom="true"
    fi
done

if [ "$firefox" == "true" ] && [ "$phantom" == "true" ] && [ "$chrome" == "true" ];
then
    all="true"
fi

if [ "$#" -eq 0 ];
then
    firefox="true"
fi

echo Selenium will started for chrome: "$chrome"
echo Selenium will started for firefox: "$firefox"
echo Selenium will started for phantomjs: "$phantom"
echo Selenium will started for all browsers: "$all"

if [ "$chrome" == "true" ];
then
    nohup java -jar lib/selenium-server-standalone-2.44.0.jar -Dwebdriver.chrome.driver="lib/chromedriver"&
    echo $! > sel_pid_head
    echo "Selenium server for Chrome and FireFox started"
    chrome="false"
    firefox="false"
fi

if [ "$firefox" == "true" ];
then
    nohup java -jar lib/selenium-server-standalone-2.44.0.jar&
    echo $! > sel_pid_head
    echo "Selenium server for FireFox started"
    firefox="false"
fi

if [ "$all" == "true" ];
then
    nohup java -jar lib/selenium-server-standalone-2.44.0.jar -role hub -port 4455&
    echo $! > sel_pid_headless
    echo "Selenium server for PhantomJS started"
    echo "Waiting 3 sec to register ghost driver into Selenium hub"
    sleep 3
    nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&
    echo "PhantomJS registred in Selenium Server"
    echo $! > ghost_pid
    phantom="false"
    all="false"
fi

if [ "$phantom" == "true" ]
then
    nohup java -jar lib/selenium-server-standalone-2.44.0.jar -role hub -port 4455&
    echo $! > sel_pid_headless
    echo "Selenium server for PhantomJS started"
    echo "Waiting 3 sec to register ghost driver into Selenium hub"
    sleep 3
    nohup phantomjs --webdriver=8080 --webdriver-selenium-grid-hub=http://127.0.0.1:4455&
    echo "PhantomJS registred in Selenium Server"
    echo $! > ghost_pid
    phantom="false"
fi

这篇关于在Mac OS上使用Nightwatchjs在Chrome中启动测试:“连接被拒绝!硒服务器启动了吗?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 11:18